From 2d0f3a30779256bc5935f7d5cc5ababfd3b88a22 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 2 Apr 2020 10:15:34 -0700 Subject: [PATCH] simplify platform differences with KEYNAME_REWRITE --- babi/file.py | 1 - babi/prompt.py | 3 +-- babi/screen.py | 16 ++++++++-------- tests/features/save_test.py | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/babi/file.py b/babi/file.py index 100c029..fe5f580 100644 --- a/babi/file.py +++ b/babi/file.py @@ -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, diff --git a/babi/prompt.py b/babi/prompt.py index c2a76eb..23856a8 100644 --- a/babi/prompt.py +++ b/babi/prompt.py @@ -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 diff --git a/babi/screen.py b/babi/screen.py index 42aac86..b902156 100644 --- a/babi/screen.py +++ b/babi/screen.py @@ -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) diff --git a/tests/features/save_test.py b/tests/features/save_test.py index 7d48726..72f3214 100644 --- a/tests/features/save_test.py +++ b/tests/features/save_test.py @@ -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()