Add secret --key-debug to debug keypresses

This commit is contained in:
Anthony Sottile
2020-03-21 15:57:23 -07:00
parent 01bb6d91b9
commit 175fd61119
3 changed files with 50 additions and 3 deletions

View File

@@ -267,7 +267,7 @@ KEYS = [
Key('^\\', b'^\\', '\x1c'),
Key('!resize', b'KEY_RESIZE', curses.KEY_RESIZE),
]
KEYS_TMUX = {k.tmux: k.value for k in KEYS}
KEYS_TMUX = {k.tmux: k.wch for k in KEYS}
KEYS_CURSES = {k.value: k.curses for k in KEYS}
@@ -298,7 +298,7 @@ class DeferredRunner:
print(f'KEY: {keypress_event.wch!r}')
return keypress_event.wch
def await_text(self, text):
def await_text(self, text, timeout=1):
self._ops.append(AwaitText(text))
def await_text_missing(self, text):

View File

@@ -0,0 +1,22 @@
import curses
from babi.screen import VERSION_STR
def test_key_debug(run):
with run('--key-debug') as h:
h.await_text(VERSION_STR, timeout=2)
h.await_text('press q to quit')
h.press('a')
h.await_text("'a' 'STRING'")
h.press('^X')
h.await_text(r"'\x18' '^X'")
with h.resize(width=20, height=20):
h.await_text(f"{curses.KEY_RESIZE} 'KEY_RESIZE'")
h.press('q')
h.await_exit()