Ticket #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 | 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.
