From 4ca3b0d1e54afba1ea6518a05ec0ac2800f5bace Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 20 Nov 2020 12:22:55 -0800 Subject: [PATCH] ignore case for quick prompt answers --- babi/screen.py | 6 +++--- tests/features/replace_test.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/babi/screen.py b/babi/screen.py index 4ca74f5..cb58161 100644 --- a/babi/screen.py +++ b/babi/screen.py @@ -273,7 +273,7 @@ class Screen: prompt: str, opt_strs: Tuple[str, ...], ) -> Union[str, PromptResult]: - opts = [opt[0] for opt in opt_strs] + opts = {opt[0] for opt in opt_strs} while True: x = 0 prompt_line = self.margin.lines - 1 @@ -310,8 +310,8 @@ class Screen: self.resize() elif key.keyname == b'^C': return self.status.cancelled() - elif isinstance(key.wch, str) and key.wch in opts: - return key.wch + elif isinstance(key.wch, str) and key.wch.lower() in opts: + return key.wch.lower() def prompt( self, diff --git a/tests/features/replace_test.py b/tests/features/replace_test.py index 6120bba..b4953e4 100644 --- a/tests/features/replace_test.py +++ b/tests/features/replace_test.py @@ -30,7 +30,8 @@ def test_replace_cancel_at_replace_string(run): h.await_text('cancelled') -def test_replace_actual_contents(run, ten_lines): +@pytest.mark.parametrize('key', ('y', 'Y')) +def test_replace_actual_contents(run, ten_lines, key): with run(str(ten_lines)) as h, and_exit(h): h.press('^\\') h.await_text('search (to replace):') @@ -38,7 +39,7 @@ def test_replace_actual_contents(run, ten_lines): h.await_text('replace with:') h.press_and_enter('ohai') h.await_text('replace [yes, no, all]?') - h.press('y') + h.press(key) h.await_text_missing('line_0') h.await_text('ohai') h.await_text(' *')