ignore case for quick prompt answers

This commit is contained in:
Anthony Sottile
2020-11-20 12:22:55 -08:00
parent 0b5e187be5
commit 4ca3b0d1e5
2 changed files with 6 additions and 5 deletions

View File

@@ -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,

View File

@@ -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(' *')