From 61937e9e8f2a35ab9588b4973ec29f11da54a9bd Mon Sep 17 00:00:00 2001 From: nvbn Date: Tue, 1 Sep 2015 14:34:41 +0300 Subject: [PATCH] #334: Wait only for first matched rule; regression: always show arrows --- tests/test_ui.py | 9 --------- thefuck/logs.py | 10 +++------- thefuck/types.py | 19 ++++--------------- thefuck/ui.py | 4 +--- 4 files changed, 8 insertions(+), 34 deletions(-) diff --git a/tests/test_ui.py b/tests/test_ui.py index f919963e..f997374c 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -96,15 +96,6 @@ 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, - settings): - patch_getch(['\n']) - seq = SortedCorrectedCommandsSequence(iter([commands[0]]), settings) - assert ui.select_command(seq, - 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 8c7b3a7d..ae5f1ad2 100644 --- a/thefuck/logs.py +++ b/thefuck/logs.py @@ -45,15 +45,11 @@ def show_corrected_command(corrected_command, settings): reset=color(colorama.Style.RESET_ALL, settings))) -def confirm_text(corrected_command, multiple_cmds, settings): - if multiple_cmds: - arrows = '{blue}↑{reset}/{blue}↓{reset}/' - else: - arrows = '' - +def confirm_text(corrected_command, settings): sys.stderr.write( ('{clear}{bold}{script}{reset}{side_effect} ' - '[{green}enter{reset}/' + arrows + '{red}ctrl+c{reset}]').format( + '[{green}enter{reset}/{blue}↑{reset}/{blue}↓{reset}' + '/{red}ctrl+c{reset}]').format( script=corrected_command.script, side_effect=' (+side effect)' if corrected_command.side_effect else '', clear='\033[1K\r', diff --git a/thefuck/types.py b/thefuck/types.py index 3f2155b6..69b174ea 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -62,21 +62,15 @@ class SortedCorrectedCommandsSequence(object): def __init__(self, commands, settings): self._settings = settings self._commands = commands - self._cached = self._get_first_two_unique() + self._cached = self._realise_first() self._realised = False - def _get_first_two_unique(self): - """Returns first two unique commands.""" + def _realise_first(self): try: - first = next(self._commands) + return [next(self._commands)] except StopIteration: return [] - for command in self._commands: - if command != first: - return [first, command] - return [first] - def _remove_duplicates(self, corrected_commands): """Removes low-priority duplicates.""" commands = {command @@ -87,8 +81,7 @@ class SortedCorrectedCommandsSequence(object): def _realise(self): """Realises generator, removes duplicates and sorts commands.""" - commands = self._cached[1:] + list(self._commands) - commands = self._remove_duplicates(commands) + commands = self._remove_duplicates(self._commands) self._cached = [self._cached[0]] + sorted( commands, key=lambda corrected_command: corrected_command.priority) self._realised = True @@ -112,7 +105,3 @@ class SortedCorrectedCommandsSequence(object): if not self._realised: self._realise() return iter(self._cached) - - @property - def is_multiple(self): - return len(self._cached) > 1 diff --git a/thefuck/ui.py b/thefuck/ui.py index 31f0316f..36dced97 100644 --- a/thefuck/ui.py +++ b/thefuck/ui.py @@ -88,9 +88,7 @@ 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, corrected_commands.is_multiple, - settings)) + selector.on_change(lambda val: logs.confirm_text(val, settings)) for action in read_actions(): if action == SELECT: sys.stderr.write('\n')