Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#1117 closed bug (Fixed)

[PATCH] can't press '3' key in deluge-console

Reported by: cdep_illabout Owned by:
Priority: minor Milestone: 1.2.0
Component: Console UI Version: 1.2.0_dev
Keywords: cannot type 3 three in console Cc:

Description

deluge-console will not print a '3' when the '3' key is pressed.

It is due to this code block in trunk/deluge/ui/console/screen.py:

# Delete a character in the input string based on cursor position
if c == curses.KEY_BACKSPACE or c == 127:
    if self.input and self.input_cursor > 0:
        self.input = self.input[:self.input_cursor - 1] + self.input[self.input_cursor:]
        self.input_cursor -= 1

elif c == curses.KEY_DC or c == 51:
    if self.input and self.input_cursor < len(self.input):
        self.input = self.input[:self.input_cursor] + self.input[self.input_cursor + 1:]

The line 'elif c == curses.KEY_DC or c == 51:' should probably be just 'elif c == curses.KEY_DC:'

I'm not sure why the check for 'c == 51' was initially added, because 51 is the decimal ascii code for the number three, not the ascii code for Delete (which is 127, according to http://www.asciitable.com/).

The var c is originally obtained in a called to stdscr.getch(). I did some testing with getch() to see what values were returned for the Delete key, the Backspace key, and Ctrl-H.

On my box, the Delete key returns the value 330. The Backspace key returns the value 127. Ctrl-H returns the value 263. Maybe these values vary by terminal type?

I checked python's documentation for these different values (http://docs.python.org/library/curses.html#constants), and it looks like KEY_DC is pretty safe to use. KEY_BACKSPACE has a warning that it is unreliable, but KEY_DC has no such warning. So KEY_DC is probably safe to use and relatively portable? Hopefully.

Change History (2)

comment:1 Changed 14 years ago by andar

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [6077]

Thanks

comment:2 Changed 14 years ago by andar

  • Milestone set to 1.2.0
Note: See TracTickets for help on using tickets.