mirror of
https://github.com/nvbn/thefuck.git
synced 2025-09-18 11:12:30 +01:00
#334: Wait only for first matched rule; regression: always show arrows
This commit is contained in:
@@ -96,15 +96,6 @@ class TestSelectCommand(object):
|
|||||||
require_confirmation=True)) == commands[0]
|
require_confirmation=True)) == commands[0]
|
||||||
assert capsys.readouterr() == ('', u'\x1b[1K\rls [enter/↑/↓/ctrl+c]\n')
|
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):
|
def test_with_confirmation_abort(self, capsys, patch_getch, commands):
|
||||||
patch_getch([KeyboardInterrupt])
|
patch_getch([KeyboardInterrupt])
|
||||||
assert ui.select_command(commands,
|
assert ui.select_command(commands,
|
||||||
|
@@ -45,15 +45,11 @@ def show_corrected_command(corrected_command, settings):
|
|||||||
reset=color(colorama.Style.RESET_ALL, settings)))
|
reset=color(colorama.Style.RESET_ALL, settings)))
|
||||||
|
|
||||||
|
|
||||||
def confirm_text(corrected_command, multiple_cmds, settings):
|
def confirm_text(corrected_command, settings):
|
||||||
if multiple_cmds:
|
|
||||||
arrows = '{blue}↑{reset}/{blue}↓{reset}/'
|
|
||||||
else:
|
|
||||||
arrows = ''
|
|
||||||
|
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
('{clear}{bold}{script}{reset}{side_effect} '
|
('{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,
|
script=corrected_command.script,
|
||||||
side_effect=' (+side effect)' if corrected_command.side_effect else '',
|
side_effect=' (+side effect)' if corrected_command.side_effect else '',
|
||||||
clear='\033[1K\r',
|
clear='\033[1K\r',
|
||||||
|
@@ -62,21 +62,15 @@ class SortedCorrectedCommandsSequence(object):
|
|||||||
def __init__(self, commands, settings):
|
def __init__(self, commands, settings):
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._commands = commands
|
self._commands = commands
|
||||||
self._cached = self._get_first_two_unique()
|
self._cached = self._realise_first()
|
||||||
self._realised = False
|
self._realised = False
|
||||||
|
|
||||||
def _get_first_two_unique(self):
|
def _realise_first(self):
|
||||||
"""Returns first two unique commands."""
|
|
||||||
try:
|
try:
|
||||||
first = next(self._commands)
|
return [next(self._commands)]
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
for command in self._commands:
|
|
||||||
if command != first:
|
|
||||||
return [first, command]
|
|
||||||
return [first]
|
|
||||||
|
|
||||||
def _remove_duplicates(self, corrected_commands):
|
def _remove_duplicates(self, corrected_commands):
|
||||||
"""Removes low-priority duplicates."""
|
"""Removes low-priority duplicates."""
|
||||||
commands = {command
|
commands = {command
|
||||||
@@ -87,8 +81,7 @@ class SortedCorrectedCommandsSequence(object):
|
|||||||
|
|
||||||
def _realise(self):
|
def _realise(self):
|
||||||
"""Realises generator, removes duplicates and sorts commands."""
|
"""Realises generator, removes duplicates and sorts commands."""
|
||||||
commands = self._cached[1:] + list(self._commands)
|
commands = self._remove_duplicates(self._commands)
|
||||||
commands = self._remove_duplicates(commands)
|
|
||||||
self._cached = [self._cached[0]] + sorted(
|
self._cached = [self._cached[0]] + sorted(
|
||||||
commands, key=lambda corrected_command: corrected_command.priority)
|
commands, key=lambda corrected_command: corrected_command.priority)
|
||||||
self._realised = True
|
self._realised = True
|
||||||
@@ -112,7 +105,3 @@ class SortedCorrectedCommandsSequence(object):
|
|||||||
if not self._realised:
|
if not self._realised:
|
||||||
self._realise()
|
self._realise()
|
||||||
return iter(self._cached)
|
return iter(self._cached)
|
||||||
|
|
||||||
@property
|
|
||||||
def is_multiple(self):
|
|
||||||
return len(self._cached) > 1
|
|
||||||
|
@@ -88,9 +88,7 @@ def select_command(corrected_commands, settings):
|
|||||||
logs.show_corrected_command(selector.value, settings)
|
logs.show_corrected_command(selector.value, settings)
|
||||||
return selector.value
|
return selector.value
|
||||||
|
|
||||||
selector.on_change(
|
selector.on_change(lambda val: logs.confirm_text(val, settings))
|
||||||
lambda val: logs.confirm_text(val, corrected_commands.is_multiple,
|
|
||||||
settings))
|
|
||||||
for action in read_actions():
|
for action in read_actions():
|
||||||
if action == SELECT:
|
if action == SELECT:
|
||||||
sys.stderr.write('\n')
|
sys.stderr.write('\n')
|
||||||
|
Reference in New Issue
Block a user