Python curses.KEY_BACKSPACE Examples
The following are 22
code examples of curses.KEY_BACKSPACE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
curses
, or try the search function
.
Example #1
Source File: screen.py From wpm with GNU Affero General Public License v3.0 | 6 votes |
def _get_key_py33(self): """Python 3.3+ implementation of get_key.""" # pylint: disable=too-many-return-statements try: # Curses in Python 3.3 handles unicode via get_wch key = self.window.get_wch() if isinstance(key, int): if key == curses.KEY_BACKSPACE: return "KEY_BACKSPACE" if key == curses.KEY_LEFT: return "KEY_LEFT" if key == curses.KEY_RIGHT: return "KEY_RIGHT" if key == curses.KEY_RESIZE: return "KEY_RESIZE" return None return key except curses.error: return None except KeyboardInterrupt: raise
Example #2
Source File: wgtextbox.py From TelegramTUI with MIT License | 6 votes |
def set_up_handlers(self): super(Textfield, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, # mac os x curses reports DEL as escape oddly # no solution yet "^K": self.h_erase_right, "^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #3
Source File: wgtextbox.py From EDCOP with Apache License 2.0 | 6 votes |
def set_up_handlers(self): super(Textfield, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, # mac os x curses reports DEL as escape oddly # no solution yet "^K": self.h_erase_right, "^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #4
Source File: wgtextbox.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def set_up_handlers(self): super(Textfield, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, # mac os x curses reports DEL as escape oddly # no solution yet "^K": self.h_erase_right, "^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #5
Source File: pytrader.py From pytrader with MIT License | 6 votes |
def validator(self, char): """here we tweak the behavior slightly, especially we want to end modal editing mode immediately on arrow up/down and on enter and we also want to catch ESC and F10, to abort the entire dialog""" if curses.ascii.isprint(char): return char if char == curses.ascii.TAB: char = curses.KEY_DOWN if char in [curses.KEY_DOWN, curses.KEY_UP]: self.result = char return curses.ascii.BEL if char in [10, 13, curses.KEY_ENTER, curses.ascii.BEL]: self.result = 10 return curses.ascii.BEL if char == 127: char = curses.KEY_BACKSPACE if char in [27, curses.KEY_F10]: self.result = -1 return curses.ascii.BEL return char
Example #6
Source File: tui.py From awesome-finder with MIT License | 6 votes |
def input_stream(self): """Waiting an input and run a proper method according to type of input""" while True: self.search(self.query) self.display() ch = self.search_window.getch() if curses.ascii.isprint(ch): self.write(ch) self.reset_top() elif ch in (curses.ascii.BS, curses.ascii.DEL, curses.KEY_BACKSPACE): self.delete() self.reset_top() elif ch == curses.KEY_UP: self.scroll(self.UP) elif ch == curses.KEY_DOWN: self.scroll(self.DOWN) elif ch == curses.KEY_LEFT: self.paging(self.UP) elif ch == curses.KEY_RIGHT: self.paging(self.DOWN) elif ch in (curses.ascii.LF, curses.ascii.NL): self.open_link() elif ch == curses.ascii.ESC: break
Example #7
Source File: wgeditmultiline.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): super(MultiLineEdit, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({ curses.ascii.NL: self.h_add_nl, curses.ascii.CR: self.h_add_nl, curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_UP: self.h_line_up, curses.KEY_DOWN: self.h_line_down, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, "^R": self.full_reformat, # mac os x curses reports DEL as escape oddly # no solution yet #"^K": self.h_erase_right, #"^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #8
Source File: wgtextbox.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): super(Textfield, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, # mac os x curses reports DEL as escape oddly # no solution yet "^K": self.h_erase_right, "^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #9
Source File: wgmultilineeditable.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): super(MultiLineEditable, self).set_up_handlers() self.handlers.update ( { ord('i'): self.h_insert_value, ord('o'): self.h_insert_next_line, curses.ascii.CR: self.h_edit_cursor_line_value, curses.ascii.NL: self.h_edit_cursor_line_value, curses.ascii.SP: self.h_edit_cursor_line_value, curses.ascii.DEL: self.h_delete_line_value, curses.ascii.BS: self.h_delete_line_value, curses.KEY_BACKSPACE: self.h_delete_line_value, } )
Example #10
Source File: wgmultilineeditable.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): super(MultiLineEditable, self).set_up_handlers() self.handlers.update ( { ord('i'): self.h_insert_value, ord('o'): self.h_insert_next_line, curses.ascii.CR: self.h_edit_cursor_line_value, curses.ascii.NL: self.h_edit_cursor_line_value, curses.ascii.SP: self.h_edit_cursor_line_value, curses.ascii.DEL: self.h_delete_line_value, curses.ascii.BS: self.h_delete_line_value, curses.KEY_BACKSPACE: self.h_delete_line_value, } )
Example #11
Source File: getstr.py From bitcoind-ncurses with MIT License | 5 votes |
def getstr(w, y, x): window = curses.newwin(1, w, y, x) result = "" window.addstr("> ", curses.A_BOLD + curses.A_BLINK) window.refresh() window.keypad(True) while True: try: character = -1 while (character < 0): character = window.getch() except: break if character == curses.KEY_ENTER or character == ord('\n'): break elif character == curses.KEY_BACKSPACE or character == 127: if len(result): window.move(0, len(result)+1) window.delch() result = result[:-1] continue elif (137 > character > 31 and len(result) < w-3): # ascii range TODO: unicode result += chr(character) window.addstr(chr(character)) window.addstr(0, 0, "> ", curses.A_BOLD + curses.color_pair(3)) window.refresh() window.keypad(False) return result
Example #12
Source File: wgeditmultiline.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def set_up_handlers(self): super(MultiLineEdit, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({ curses.ascii.NL: self.h_add_nl, curses.ascii.CR: self.h_add_nl, curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_UP: self.h_line_up, curses.KEY_DOWN: self.h_line_down, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, "^R": self.full_reformat, # mac os x curses reports DEL as escape oddly # no solution yet #"^K": self.h_erase_right, #"^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #13
Source File: wgmultilineeditable.py From EDCOP with Apache License 2.0 | 5 votes |
def set_up_handlers(self): super(MultiLineEditable, self).set_up_handlers() self.handlers.update ( { ord('i'): self.h_insert_value, ord('o'): self.h_insert_next_line, curses.ascii.CR: self.h_edit_cursor_line_value, curses.ascii.NL: self.h_edit_cursor_line_value, curses.ascii.SP: self.h_edit_cursor_line_value, curses.ascii.DEL: self.h_delete_line_value, curses.ascii.BS: self.h_delete_line_value, curses.KEY_BACKSPACE: self.h_delete_line_value, } )
Example #14
Source File: screen.py From wpm with GNU Affero General Public License v3.0 | 5 votes |
def _get_key_py27(self): """Python 2.7 implementation of get_key.""" # pylint: disable=too-many-return-statements try: key = self.window.getkey() # Start of UTF-8 multi-byte character? if self.encoding == "utf-8" and ord(key[0]) & 0x80: multibyte = key[0] cont_bytes = ord(key[0]) << 1 while cont_bytes & 0x80: cont_bytes <<= 1 multibyte += self.window.getkey()[0] return multibyte.decode(self.encoding) if isinstance(key, int): if key == curses.KEY_BACKSPACE: return "KEY_BACKSPACE" if key == curses.KEY_LEFT: return "KEY_LEFT" if key == curses.KEY_RIGHT: return "KEY_RIGHT" if key == curses.KEY_RESIZE: return "KEY_RESIZE" return None return key.decode("ascii") except KeyboardInterrupt: raise except curses.error: return None
Example #15
Source File: wgeditmultiline.py From EDCOP with Apache License 2.0 | 5 votes |
def set_up_handlers(self): super(MultiLineEdit, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({ curses.ascii.NL: self.h_add_nl, curses.ascii.CR: self.h_add_nl, curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_UP: self.h_line_up, curses.KEY_DOWN: self.h_line_down, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, "^R": self.full_reformat, # mac os x curses reports DEL as escape oddly # no solution yet #"^K": self.h_erase_right, #"^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #16
Source File: wgmultilineeditable.py From TelegramTUI with MIT License | 5 votes |
def set_up_handlers(self): super(MultiLineEditable, self).set_up_handlers() self.handlers.update ( { ord('i'): self.h_insert_value, ord('o'): self.h_insert_next_line, curses.ascii.CR: self.h_edit_cursor_line_value, curses.ascii.NL: self.h_edit_cursor_line_value, curses.ascii.SP: self.h_edit_cursor_line_value, curses.ascii.DEL: self.h_delete_line_value, curses.ascii.BS: self.h_delete_line_value, curses.KEY_BACKSPACE: self.h_delete_line_value, } )
Example #17
Source File: screen.py From wpm with GNU Affero General Public License v3.0 | 5 votes |
def is_backspace(key): """Checks for backspace key.""" if len(key) > 1: return key == "KEY_BACKSPACE" if ord(key) in (curses.ascii.BS, curses.ascii.DEL): return True return False
Example #18
Source File: wgeditmultiline.py From TelegramTUI with MIT License | 5 votes |
def set_up_handlers(self): super(MultiLineEdit, self).set_up_handlers() # For OS X del_key = curses.ascii.alt('~') self.handlers.update({ curses.ascii.NL: self.h_add_nl, curses.ascii.CR: self.h_add_nl, curses.KEY_LEFT: self.h_cursor_left, curses.KEY_RIGHT: self.h_cursor_right, curses.KEY_UP: self.h_line_up, curses.KEY_DOWN: self.h_line_down, curses.KEY_DC: self.h_delete_right, curses.ascii.DEL: self.h_delete_left, curses.ascii.BS: self.h_delete_left, curses.KEY_BACKSPACE: self.h_delete_left, "^R": self.full_reformat, # mac os x curses reports DEL as escape oddly # no solution yet #"^K": self.h_erase_right, #"^U": self.h_erase_left, }) self.complex_handlers.extend(( (self.t_input_isprint, self.h_addch), # (self.t_is_ck, self.h_erase_right), # (self.t_is_cu, self.h_erase_left), ))
Example #19
Source File: terminal_10.py From Modern-Python-Standard-Library-Cookbook with MIT License | 5 votes |
def _edit(self, box): while True: ch = box.win.getch() if not ch: continue if ch == 127: ch = curses.KEY_BACKSPACE if not box.do_command(ch): break box.win.refresh() return box.gather()
Example #20
Source File: terminal.py From ttrv with MIT License | 4 votes |
def text_input(self, window, allow_resize=False): """ Transform a window into a text box that will accept user input and loop until an escape sequence is entered. If the escape key (27) is pressed, cancel the textbox and return None. Otherwise, the textbox will wait until it is full (^j, or a new line is entered on the bottom line) or the BEL key (^g) is pressed. """ window.clear() # Set cursor mode to 1 because 2 doesn't display on some terminals self.curs_set(1) # Keep insert_mode off to avoid the recursion error described here # http://bugs.python.org/issue13051 textbox = textpad.Textbox(window) textbox.stripspaces = 0 def validate(ch): "Filters characters for special key sequences" if ch == self.ESCAPE: raise exceptions.EscapeInterrupt() if (not allow_resize) and (ch == curses.KEY_RESIZE): raise exceptions.EscapeInterrupt() # Fix backspace for iterm if ch == curses.ascii.DEL: ch = curses.KEY_BACKSPACE return ch # Wrapping in an exception block so that we can distinguish when the # user hits the return character from when the user tries to back out # of the input. try: out = textbox.edit(validate=validate) if isinstance(out, six.binary_type): out = out.decode('utf-8') except exceptions.EscapeInterrupt: out = None self.curs_set(0) return self.strip_textpad(out)
Example #21
Source File: app.py From toot with GNU General Public License v3.0 | 4 votes |
def do_command(self, ch): if curses.ascii.isprint(ch) or ch == curses.ascii.LF: text_window_height, text_window_width = self.text_window.getmaxyx() y, x = size_as_drawn((self.get_content() + chr(ch)).split('\n'), text_window_width) if y < text_window_height - 1 and x < text_window_width: self.content.insert(self.cursor_pos, chr(ch)) self.cursor_pos += 1 else: curses.beep() elif ch == curses.KEY_BACKSPACE: if self.cursor_pos > 0: del self.content[self.cursor_pos - 1] self.cursor_pos -= 1 else: curses.beep() elif ch == curses.KEY_DC: if self.cursor_pos >= 0 and self.cursor_pos < len(self.content): del self.content[self.cursor_pos] else: curses.beep() elif ch == curses.KEY_LEFT: if self.cursor_pos > 0: self.cursor_pos -= 1 else: curses.beep() elif ch == curses.KEY_RIGHT: if self.cursor_pos + 1 <= len(self.content): self.cursor_pos += 1 else: curses.beep() elif ch in (curses.ascii.EOT, curses.ascii.RS): # ^D or (for some terminals) Ctrl+Enter return False, False elif ch == curses.ascii.ESC: self.clear() return False, True elif ch == curses.KEY_RESIZE: self.on_resize() return True, False self.refresh_text() return True, False
Example #22
Source File: terminal.py From rtv with MIT License | 4 votes |
def text_input(self, window, allow_resize=False): """ Transform a window into a text box that will accept user input and loop until an escape sequence is entered. If the escape key (27) is pressed, cancel the textbox and return None. Otherwise, the textbox will wait until it is full (^j, or a new line is entered on the bottom line) or the BEL key (^g) is pressed. """ window.clear() # Set cursor mode to 1 because 2 doesn't display on some terminals self.curs_set(1) # Keep insert_mode off to avoid the recursion error described here # http://bugs.python.org/issue13051 textbox = textpad.Textbox(window) textbox.stripspaces = 0 def validate(ch): "Filters characters for special key sequences" if ch == self.ESCAPE: raise exceptions.EscapeInterrupt() if (not allow_resize) and (ch == curses.KEY_RESIZE): raise exceptions.EscapeInterrupt() # Fix backspace for iterm if ch == curses.ascii.DEL: ch = curses.KEY_BACKSPACE return ch # Wrapping in an exception block so that we can distinguish when the # user hits the return character from when the user tries to back out # of the input. try: out = textbox.edit(validate=validate) if isinstance(out, six.binary_type): out = out.decode('utf-8') except exceptions.EscapeInterrupt: out = None self.curs_set(0) return self.strip_textpad(out)