Python curses.keyname() Examples
The following are 18
code examples of curses.keyname().
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: wgtexttokens.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + [ch_adding,] \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding)
Example #2
Source File: wgtexttokens.py From TelegramTUI with MIT License | 6 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + [ch_adding,] \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding)
Example #3
Source File: unit_test_curses_util.py From ci_edit with Apache License 2.0 | 6 votes |
def test_curses_key_name(self): # These actually test the fake curses. def test1(): curses.keyname(-3) self.assertRaises(ValueError, test1) def test2(): curses.keyname([]) self.assertRaises(TypeError, test2) def test3(): curses.keyname(9**999) self.assertRaises(OverflowError, test3)
Example #4
Source File: wgtexttokens.py From EDCOP with Apache License 2.0 | 6 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + [ch_adding,] \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding)
Example #5
Source File: wgtexttokens.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + [ch_adding,] \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding)
Example #6
Source File: screen.py From babi with MIT License | 6 votes |
def _get_char(self) -> Key: if self._buffered_input is not None: wch, self._buffered_input = self._buffered_input, None else: try: wch = self.stdscr.get_wch() except curses.error: # pragma: no cover (macos bug?) wch = self.stdscr.get_wch() if isinstance(wch, str) and wch == '\x1b': wch = self._get_sequence(wch) if len(wch) == 2: return Key(wch, f'M-{wch[1]}'.encode()) elif len(wch) > 1: keyname = SEQUENCE_KEYNAME.get(wch, b'unknown') return Key(wch, keyname) elif isinstance(wch, str) and wch.isprintable(): wch = self._get_string(wch) return Key(wch, b'STRING') key = wch if isinstance(wch, int) else ord(wch) keyname = curses.keyname(key) keyname = KEYNAME_REWRITE.get(keyname, keyname) return Key(wch, keyname)
Example #7
Source File: ui.py From suplemon with MIT License | 5 votes |
def _curses_key_name(self, key): """Return the curses key name for keys received from get_wch (and getch).""" # Handle multibyte get_wch input in Python 3.3 if isinstance(key, str): return str(curses.keyname(ord(key)).decode("utf-8")) # Fallback to try and handle Python < 3.3 # Special keys can also be ints on Python > 3.3 if isinstance(key, int): # getch fallback try: # Try to convert to a curses key name name = str(curses.keyname(key).decode("utf-8")) return name except: # Otherwise try to convert to a character return False return False
Example #8
Source File: wgtextbox.py From TelegramTUI with MIT License | 5 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + ch_adding \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding) # or avoid it entirely: #self.value = self.value[:self.cursor_position] + curses.ascii.unctrl(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.ascii.unctrl(input))
Example #9
Source File: wgmultiline.py From TelegramTUI with MIT License | 5 votes |
def h_find_char(self, input): # The following ought to work, but there is a curses keyname bug # searchingfor = curses.keyname(input).upper() # do this instead: searchingfor = chr(input).upper() for counter in range(len(self.values)): try: if self.values[counter].find(searchingfor) is not -1: self.cursor_line = counter break except AttributeError: break
Example #10
Source File: curses_util.py From ci_edit with Apache License 2.0 | 5 votes |
def cursesKeyName(keyCode): try: return curses.keyname(keyCode) except Exception: pass return None
Example #11
Source File: screen.py From babi with MIT License | 5 votes |
def get_char(self) -> Key: self.perf.end() ret = self._get_char() self.perf.start(ret.keyname.decode()) return ret
Example #12
Source File: wgtextbox.py From EDCOP with Apache License 2.0 | 5 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + ch_adding \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding) # or avoid it entirely: #self.value = self.value[:self.cursor_position] + curses.ascii.unctrl(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.ascii.unctrl(input))
Example #13
Source File: wgmultiline.py From EDCOP with Apache License 2.0 | 5 votes |
def h_find_char(self, input): # The following ought to work, but there is a curses keyname bug # searchingfor = curses.keyname(input).upper() # do this instead: searchingfor = chr(input).upper() for counter in range(len(self.values)): try: if self.values[counter].find(searchingfor) is not -1: self.cursor_line = counter break except AttributeError: break
Example #14
Source File: wgtextbox.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + ch_adding \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding) # or avoid it entirely: #self.value = self.value[:self.cursor_position] + curses.ascii.unctrl(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.ascii.unctrl(input))
Example #15
Source File: wgmultiline.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def h_find_char(self, input): # The following ought to work, but there is a curses keyname bug # searchingfor = curses.keyname(input).upper() # do this instead: searchingfor = chr(input).upper() for counter in range(len(self.values)): try: if self.values[counter].find(searchingfor) is not -1: self.cursor_line = counter break except AttributeError: break
Example #16
Source File: wgtextbox.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def h_addch(self, inp): if self.editable: #self.value = self.value[:self.cursor_position] + curses.keyname(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.keyname(input)) # workaround for the metamode bug: if self._last_get_ch_was_unicode == True and isinstance(self.value, bytes): # probably dealing with python2. ch_adding = inp self.value = self.value.decode() elif self._last_get_ch_was_unicode == True: ch_adding = inp else: try: ch_adding = chr(inp) except TypeError: ch_adding = input self.value = self.value[:self.cursor_position] + ch_adding \ + self.value[self.cursor_position:] self.cursor_position += len(ch_adding) # or avoid it entirely: #self.value = self.value[:self.cursor_position] + curses.ascii.unctrl(input) \ # + self.value[self.cursor_position:] #self.cursor_position += len(curses.ascii.unctrl(input))
Example #17
Source File: wgmultiline.py From apple_bleee with GNU General Public License v3.0 | 5 votes |
def h_find_char(self, input): # The following ought to work, but there is a curses keyname bug # searchingfor = curses.keyname(input).upper() # do this instead: searchingfor = chr(input).upper() for counter in range(len(self.values)): try: if self.values[counter].find(searchingfor) is not -1: self.cursor_line = counter break except AttributeError: break
Example #18
Source File: screen.py From babi with MIT License | 4 votes |
def quick_prompt( self, prompt: str, opt_strs: Tuple[str, ...], ) -> Union[str, PromptResult]: opts = [opt[0] for opt in opt_strs] while True: x = 0 prompt_line = self.margin.lines - 1 def _write(s: str, *, attr: int = curses.A_REVERSE) -> None: nonlocal x if x >= self.margin.cols: return self.stdscr.insstr(prompt_line, x, s, attr) x += len(s) _write(prompt) _write(' [') for i, opt_str in enumerate(opt_strs): _write(opt_str[0], attr=curses.A_REVERSE | curses.A_BOLD) _write(opt_str[1:]) if i != len(opt_strs) - 1: _write(', ') _write(']?') if x < self.margin.cols - 1: s = ' ' * (self.margin.cols - x) self.stdscr.insstr(prompt_line, x, s, curses.A_REVERSE) x += 1 else: x = self.margin.cols - 1 self.stdscr.insstr(prompt_line, x, '…', curses.A_REVERSE) self.stdscr.move(prompt_line, x) key = self.get_char() if key.keyname == b'KEY_RESIZE': self.resize() elif key.keyname == b'^C': return self.status.cancelled() elif isinstance(key.wch, str) and key.wch in opts: return key.wch