mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 06:15:54 +08:00
fff8e8163b
Commit 5f849d0
changed control-C to print an inverted ^C and then a newline.
The original motivation was
> In bash if you type something and press ctrl-c then the content of the line
> is preserved and the cursor is moved to a new line. In fish the ctrl-c just
> clears the line. For me the behaviour of bash is a bit better, because it
> allows me to type something then press ctrl-c and I have the typed string
> in the log for further reference.
This sounds like a valid use case in some scenarios but I think that most
abandoned commands are noise. After all, the user erased them. Also, now that
we have undo that can be used to get back a limited set of canceled commands.
I believe the original motivation for existing behavior (in other shells) was
that TERM=dumb does not support erasing characters. Similarly, other shells
like to leave behind other artifacts, for example when using tab-completion
or in their interactive menus but we generally don't.
Control-C is the obvious way to quickly clear a multi-line commandline.
IPython does the same. For the other behavior we have Alt-# although that's
probably not very well-known.
Restore the old Control-C behavior of simply clearing the command line.
Our unused __fish_cancel_commandline still prints the ^C. For folks who
have explicitly bound ^C to that, it's probably better to keep the existing
behavior, so let's leave this one.
Previous attempt at #4713 fizzled.
Closes #10213
43 lines
953 B
Python
43 lines
953 B
Python
#!/usr/bin/env python3
|
|
import os
|
|
from pexpect_helper import SpawnedProc
|
|
import signal
|
|
|
|
sp = SpawnedProc()
|
|
send, sendline, sleep, expect_str, expect_prompt = (
|
|
sp.send,
|
|
sp.sendline,
|
|
sp.sleep,
|
|
sp.expect_str,
|
|
sp.expect_prompt,
|
|
)
|
|
expect_prompt()
|
|
|
|
timeout = 0.15
|
|
|
|
if "CI" in os.environ:
|
|
# This doesn't work under TSan, because TSan prevents select() being
|
|
# interrupted by a signal.
|
|
import sys
|
|
|
|
print("SKIPPING cancel_event.py")
|
|
sys.exit(0)
|
|
|
|
# Verify that cancel-commandline does what we expect - see #7384.
|
|
send("not executed")
|
|
sleep(timeout)
|
|
os.kill(sp.spawn.pid, signal.SIGINT)
|
|
sendline("echo marker")
|
|
sp.expect_str("marker")
|
|
expect_prompt()
|
|
|
|
sendline("function cancelhandler --on-event fish_cancel ; echo yay cancelled ; end")
|
|
expect_prompt()
|
|
send("still not executed")
|
|
sleep(timeout)
|
|
os.kill(sp.spawn.pid, signal.SIGINT)
|
|
expect_str("yay cancelled")
|
|
sendline("echo marker")
|
|
sp.expect_str("marker")
|
|
expect_prompt()
|