mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
#324 Remove arrows in case there is only one match
This commit is contained in:
parent
8be353941f
commit
4d467cce95
@ -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,
|
||||
|
@ -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),
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user