diff --git a/tests/test_ui.py b/tests/test_ui.py index 578abce..7843dea 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -92,6 +92,13 @@ class TestSelectCommand(object): require_confirmation=True)) == commands[0] assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\n') + def test_with_confirmation_one_match(self, capsys, patch_getch, commands): + patch_getch(['\n']) + assert ui.select_command((commands[0],), + Mock(debug=False, no_color=True, + require_confirmation=True)) == commands[0] + assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/ctrl+c]\n') + def test_with_confirmation_abort(self, capsys, patch_getch, commands): patch_getch([KeyboardInterrupt]) assert ui.select_command(commands, diff --git a/thefuck/logs.py b/thefuck/logs.py index 0878102..18154f1 100644 --- a/thefuck/logs.py +++ b/thefuck/logs.py @@ -45,12 +45,18 @@ def show_corrected_command(corrected_command, settings): reset=color(colorama.Style.RESET_ALL, settings))) -def confirm_text(corrected_command, settings): +def confirm_text(corrected_command, multiple_cmds, settings): + if multiple_cmds: + arrows = '{blue}↑{reset}/{blue}↓{reset}/' + else: + arrows = '' + sys.stderr.write( - '\033[1K\r{bold}{script}{reset}{side_effect} ' - '[{green}enter{reset}/{blue}↑{reset}/{blue}↓{reset}/{red}ctrl+c{reset}]'.format( + ('{clear}{bold}{script}{reset}{side_effect} ' + '[{green}enter{reset}/' + arrows + '{red}ctrl+c{reset}]').format( script=corrected_command.script, side_effect=' (+side effect)' if corrected_command.side_effect else '', + clear='\033[1K\r', bold=color(colorama.Style.BRIGHT, settings), green=color(colorama.Fore.GREEN, settings), red=color(colorama.Fore.RED, settings), diff --git a/thefuck/ui.py b/thefuck/ui.py index f0b4979..18684b4 100644 --- a/thefuck/ui.py +++ b/thefuck/ui.py @@ -44,8 +44,7 @@ def read_actions(): if buffer == ['\x1b', '[', 'A']: # ↑ yield PREVIOUS - - if buffer == ['\x1b', '[', 'B']: # ↓ + elif buffer == ['\x1b', '[', 'B']: # ↓ yield NEXT @@ -89,7 +88,9 @@ def select_command(corrected_commands, settings): logs.show_corrected_command(selector.value, settings) return selector.value - selector.on_change(lambda val: logs.confirm_text(val, settings)) + multiple_cmds = len(corrected_commands) > 1 + + selector.on_change(lambda val: logs.confirm_text(val, multiple_cmds, settings)) for action in read_actions(): if action == SELECT: sys.stderr.write('\n')