1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

Change the message when expecting side effect

The previous behavior is really surprising:
```
    some_command* [enter/ctrl+c]
   |<~~~~~~~~~~~>|<~~~~~~~~~~~~>|
   |  bold text  | normal weight|
```
as if the '*' is part of the command to be executed.
The new behavior is:
```
    some_command (+side effect) [enter/ctrl+c]
   |<~~~~~~~~~~>|<~~~~~~~~~~~~~~~~~~~~~~~~~~~>|
   |  bold text |        normal weight        |
```
This commit is contained in:
mcarton 2015-07-25 23:10:21 +02:00
parent 1c5fef3a34
commit 3173ef10c6
2 changed files with 6 additions and 6 deletions

View File

@ -153,7 +153,7 @@ class TestConfirm(object):
def test_with_side_effect_and_without_confirmation(self, capsys): def test_with_side_effect_and_without_confirmation(self, capsys):
assert main.confirm('command', Mock(), Mock(require_confirmation=False)) assert main.confirm('command', Mock(), Mock(require_confirmation=False))
assert capsys.readouterr() == ('', 'command*\n') assert capsys.readouterr() == ('', 'command (+side effect)\n')
# `stdin` fixture should be applied after `capsys` # `stdin` fixture should be applied after `capsys`
def test_when_confirmation_required_and_confirmed(self, capsys, stdin): def test_when_confirmation_required_and_confirmed(self, capsys, stdin):
@ -165,7 +165,7 @@ class TestConfirm(object):
def test_when_confirmation_required_and_confirmed_with_side_effect(self, capsys, stdin): def test_when_confirmation_required_and_confirmed_with_side_effect(self, capsys, stdin):
assert main.confirm('command', Mock(), Mock(require_confirmation=True, assert main.confirm('command', Mock(), Mock(require_confirmation=True,
no_colors=True)) no_colors=True))
assert capsys.readouterr() == ('', 'command* [enter/ctrl+c]') assert capsys.readouterr() == ('', 'command (+side effect) [enter/ctrl+c]')
def test_when_confirmation_required_and_aborted(self, capsys, stdin): def test_when_confirmation_required_and_aborted(self, capsys, stdin):
stdin.side_effect = KeyboardInterrupt stdin.side_effect = KeyboardInterrupt

View File

@ -29,19 +29,19 @@ def rule_failed(rule, exc_info, settings):
def show_command(new_command, side_effect, settings): def show_command(new_command, side_effect, settings):
sys.stderr.write('{bold}{command}{side_effect}{reset}\n'.format( sys.stderr.write('{bold}{command}{reset}{side_effect}\n'.format(
command=new_command, command=new_command,
side_effect='*' if side_effect else '', side_effect=' (+side effect)' if side_effect else '',
bold=color(colorama.Style.BRIGHT, settings), bold=color(colorama.Style.BRIGHT, settings),
reset=color(colorama.Style.RESET_ALL, settings))) reset=color(colorama.Style.RESET_ALL, settings)))
def confirm_command(new_command, side_effect, settings): def confirm_command(new_command, side_effect, settings):
sys.stderr.write( sys.stderr.write(
'{bold}{command}{side_effect}{reset} ' '{bold}{command}{reset}{side_effect} '
'[{green}enter{reset}/{red}ctrl+c{reset}]'.format( '[{green}enter{reset}/{red}ctrl+c{reset}]'.format(
command=new_command, command=new_command,
side_effect='*' if side_effect else '', side_effect=' (+side effect)' if side_effect else '',
bold=color(colorama.Style.BRIGHT, settings), bold=color(colorama.Style.BRIGHT, settings),
green=color(colorama.Fore.GREEN, settings), green=color(colorama.Fore.GREEN, settings),
red=color(colorama.Fore.RED, settings), red=color(colorama.Fore.RED, settings),