Ticket #1140: unicode_input.diff

File unicode_input.diff, 2.2 KB (added by nullie, 14 years ago)

Add unicode input support

  • trunk/deluge/ui/console/screen.py

     
    385385                self.display_lines_offset = 0 
    386386            self.refresh() 
    387387 
     388        # We remove the tab count if the key wasn't a tab 
     389        if c != 9: 
     390            self.tab_count = 0 
     391 
    388392        # Delete a character in the input string based on cursor position 
    389393        if c == curses.KEY_BACKSPACE or c == 127: 
    390394            if self.input and self.input_cursor > 0: 
     
    397401 
    398402        # A key to add to the input string 
    399403        else: 
    400             if c > 31 and c < 127: 
    401                 if self.input_cursor == len(self.input): 
    402                     self.input += chr(c) 
    403                 else: 
    404                     # Insert into string 
    405                     self.input = self.input[:self.input_cursor] + chr(c) + self.input[self.input_cursor:] 
    406                 # Move the cursor forward 
    407                 self.input_cursor += 1 
     404            if c > 31 and c < 256: 
     405                # Emulate getwch 
     406                stroke = chr(c) 
    408407 
    409         # We remove the tab count if the key wasn't a tab 
    410         if c != 9: 
    411             self.tab_count = 0 
     408                uchar = None 
    412409 
     410                while 1: 
     411                    try: 
     412                        uchar = stroke.decode(self.encoding) 
     413                    except UnicodeDecodeError: 
     414                        pass 
     415                     
     416                    c = self.stdscr.getch() 
     417 
     418                    if c == -1: 
     419                        break 
     420 
     421                    stroke += chr(c)  
     422 
     423                if uchar: 
     424                    if self.input_cursor == len(self.input): 
     425                        self.input += uchar 
     426                    else: 
     427                        # Insert into string 
     428                        self.input = self.input[:self.input_cursor] + uchar + self.input[self.input_cursor:] 
     429                         
     430                    # Move the cursor forward 
     431                    self.input_cursor += 1 
     432 
    413433        # Update the input string on the screen 
    414434        self.add_string(self.rows - 1, self.input) 
    415435        self.stdscr.move(self.rows - 1, self.input_cursor)