1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

#334: Wait only for first matched rule; regression: always show arrows

This commit is contained in:
nvbn 2015-09-01 14:34:41 +03:00
parent 5d74344994
commit 61937e9e8f
4 changed files with 8 additions and 34 deletions

View File

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

View File

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

View File

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

View File

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