simplify platform differences with KEYNAME_REWRITE

This commit is contained in:
Anthony Sottile
2020-04-02 10:15:34 -07:00
parent 2a9eccefb2
commit 2d0f3a3077
4 changed files with 10 additions and 12 deletions

View File

@@ -670,7 +670,6 @@ class File:
b'kEND5': ctrl_end,
# editing
b'KEY_BACKSPACE': backspace,
b'^H': backspace, # ^Backspace
b'KEY_DC': delete,
b'^M': enter,
b'^I': tab,

View File

@@ -127,7 +127,7 @@ class Prompt:
key = self._screen.get_char()
if key.keyname == b'KEY_RESIZE':
self._screen.resize()
elif key.keyname == b'KEY_BACKSPACE' or key.keyname == b'^H':
elif key.keyname == b'KEY_BACKSPACE':
reverse_s = reverse_s[:-1]
elif key.keyname == b'^R':
idx = max(0, idx - 1)
@@ -164,7 +164,6 @@ class Prompt:
b'kLFT5': _ctrl_left,
# editing
b'KEY_BACKSPACE': _backspace,
b'^H': _backspace, # ^Backspace
b'KEY_DC': _delete,
b'^K': _cut_to_end,
# misc

View File

@@ -61,27 +61,30 @@ SEQUENCE_KEYNAME = {
'\x1b[1;6H': b'kHOM6', # Shift + ^Home
'\x1b[1;6F': b'kEND6', # Shift + ^End
}
# windows-curses has different keynames for some keys
KEYNAME_REWRITE = {
# numeric pad arrow keys
# windows-curses: numeric pad arrow keys
# - some overlay keyboards pick these as well
# - in xterm it seems these are mapped automatically
b'KEY_A2': b'KEY_UP',
b'KEY_C2': b'KEY_DOWN',
b'KEY_B3': b'KEY_RIGHT',
b'KEY_B1': b'KEY_LEFT',
# map to our M- names
# windows-curses: map to our M- names
b'ALT_U': b'M-u',
# arguably these names are better than the xterm names
# windows-curses: arguably these names are better than the xterm names
b'CTL_UP': b'kUP5',
b'CTL_DOWN': b'kDN5',
b'CTL_RIGHT': b'kRIT5',
b'CTL_LEFT': b'kLFT5',
b'ALT_RIGHT': b'kRIT3',
b'ALT_LEFT': b'kLFT3',
# idk why these are different
# windows-curses: idk why these are different
b'KEY_SUP': b'KEY_SR',
b'KEY_SDOWN': b'KEY_SF',
# macos: (sends this for backspace key, others interpret this as well)
b'^?': b'KEY_BACKSPACE',
# linux, perhaps others
b'^H': b'KEY_BACKSPACE', # ^Backspace on my keyboard
}
@@ -224,9 +227,6 @@ class Screen:
elif isinstance(wch, str) and wch.isprintable():
wch = self._get_string(wch)
return Key(wch, b'STRING')
elif wch == '\x7f': # pragma: no cover (macos)
keyname = curses.keyname(curses.KEY_BACKSPACE)
return Key(wch, keyname)
key = wch if isinstance(wch, int) else ord(wch)
keyname = curses.keyname(key)

View File

@@ -237,7 +237,7 @@ def test_vim_save_on_exit(run, tmpdir):
h.press_and_enter(':q')
h.await_text('file is modified - save [yes, no]?')
h.press('y')
h.await_text(f'enter filename: {f}')
h.await_text(f'enter filename: ')
h.press('Enter')
h.await_exit()