You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reset terminal at prompt to clean up after bad termination of certain scripts #4873
Not sure what exactly is the cause, but many cli apps that use escape codes to present a console ui (not sure if curses only or in general) can crash/exit at a point that will break input, for example, forcing fish_config and descendents to quit while w3m is running results in breakage of the up/down/right/left arrow keys (pressing up results in [A posted to the console, down in [B, etc.)
The example you cite (arrow keys not working) is usually because the app enabled alternate keypad mode (sometimes known as application keypad mode). The tput init command typically includes the sequence \e> to enable numeric keypad mode. See https://vt100.net/docs/vt100-ug/chapter3.html. Whether fish should send the terminfo is or init sequence (which is what tput init emits) before every prompt is debatable. Neither bash or zsh do so. Of course you can argue that fish should do so because ensuring the terminal is in a known state is friendlier but the concern I would have involves possible unwanted side-effects and the cost of including that string with every prompt.
Hmmm, tput init didn't help for me in that case (and in the past) with xterm-256color as my TERM with the termcap from ncurses 5.9 (2014-07-26).
The problem is that sometimes (esp. when breaking fish_prompt while testing) ctrl+c, del, and ctrl+h/bkspc becomes uninterpretable so that after a typo there is no option but to kill the process out-of-band (since I can no longer type in exit). Obviously that particular case (fish dev) is an edge case, but other such escaping issues exist.
@mqudsi, I missed the "does not help" part of your original comment. Nonetheless, what you're describing in your second comment implies that fish is not setting the tty driver mode to a sane value after running an external command. Something that should be impossible (at least as of 2017-09-08 when I stopped tracking the master branch). Also, whatever escape sequences the application has sent to the terminal (e.g., to enable alternate keypad mode) can't possibly affect how fish handles things like [ctrl-C] or [backspace]. What the app does to the tty driver mode can if fish is no longer setting the tty driver mode to a sane value after an external command.
Is this on a UNIX like platform? That is, not Cygwin or WSL? If so execute tty before recreating the problem to capture the tty name. Capture the tty mode by running stty -a < $tty where $tty is the tty name you captured. Then recreate the problem and run, in a different terminal on the same system, stty -a < $tty. Are they the same? They should be identical.
Also, when you say
... so that after a typo there is no option but to kill the process...
it seems to me the need to kill the fish process is irrelevant. The fact it no longer responds to something as basic as the interrupt character (normally [ctrl-c]) is all we need to know. So I'm wondering if I've misunderstood what you're saying.
Note that if the problem is such that stty sane fixes it then you'll probably need to press [ctrl-j] rather than [enter] to run the command. And if that does fix the problem it means fish is no longer ensuring the tty modes are sane after an external command is run.
@zanchey I'll have to work up a minimal reproduction case so I can test the stty sane approach, but essentially yes, fish is (no longer?) ensuring a sane tty after external commands.
@krader1961 The reason I didn't feel that the lack of response to ctrl+c was enough is because it isn't so much fish ignoring sigint (which I should test via an external kill -SIGINT next time) as it was that ctrl+c was no longer mapped to sigint.
Depending on the repro, sometimes enter still works and sometimes it doesn't (it did this last time, but when I broke fish_prompt it wouldn't any more). I'll try ctrl+j next time that happens, too, thanks for the tip, @krader1961 .
Executing the resulting binary causes the console to act up (input is no longer process correctly) under FreeBSD 12 from the login terminal. Cannot switch sessions, exit fish, or do anything useful.
ssh into the machine and kill the fish login session and everything goes back to normal.
I haven't experienced it in the past couple of months, but I haven't been working on anything that manipulates the terminal too much. Note that I already posted test code above which reproduces it 100% of the time, I could try that again if need be.
I don't think it's a race condition because running a subsequent command should trigger the code again and make it work, and that wasn't the case for me.
I imagine there's some state that we aren't saving/restoring? Or maybe it's an issue with the terminal (or terminal emulator) itself?
@krader1961 I'm thinking now that there's no way stty sane could actually ever work because we deliberately break stty, don't we? #2315
(I re-opened because the issue described with neovim is different)
Okay, if I understand correctly your issue is:
any mouse clicks put garbage to the screen
Garbage like
?
If so, neovim turned mouse reporting on and didn't turn it off. Fish does not do any mouse handling by itself, and won't currently turn mouse reporting on or off.
The solution is echo -e "\e[?1000l" (echo -e "\e[?1000h" turns it on), but I don't know when that's accepted, I'm not particularly in the mood to do yet more terminal feature detection (can we get a better replacement for terminfo already), and this doesn't seem to be a common problem so I don't feel like handling it is worth it. If neovim crashed, just start neovim again and exit it cleanly, or start a new tab.
I don't think this needs any terminal feature detection? If fish doesn't use mouse detection, fish can (should?) just keep it off and any application that needs application-level mouse detection will be turn it back on as needed. I can't think of any apps that act differently (intentionally) based on whether or not the invoking shell has enabled mouse support. It would just have to be one of those states that is saved alongside a background process' state so that it is restored along with it but otherwise disabled.
f fish doesn't use mouse detection, fish can (should?) just keep it off and any application that needs application-level mouse detection will be turn it back on as needed
You misunderstand. Fish doesn't need it, but neovim turned it on, and because it crashed did not turn it off!
And because turning it off involves sending an escape sequence, it needs feature detection.
Okay, the original issue was fixed, so I am closing this. As for the secondary issue with the mouse reporting, I'll refer to #4918. Turning mouse reporting off requires detecting if mouse reporting is supported in the first place, which is only really something that makes sense in the context of adding support for mouse reporting.
Any other ways to break the terminal (e.g. iTerm might be confused about which host the user is currently operating on) also require fish to know about these escapes. They should also be handled in separate issues.
Activity
krader1961 commentedon Apr 2, 2018
The example you cite (arrow keys not working) is usually because the app enabled alternate keypad mode (sometimes known as application keypad mode). The
tput initcommand typically includes the sequence\e>to enable numeric keypad mode. See https://vt100.net/docs/vt100-ug/chapter3.html. Whether fish should send the terminfoisorinitsequence (which is whattput initemits) before every prompt is debatable. Neither bash or zsh do so. Of course you can argue that fish should do so because ensuring the terminal is in a known state is friendlier but the concern I would have involves possible unwanted side-effects and the cost of including that string with every prompt.mqudsi commentedon Apr 3, 2018
Hmmm,
tput initdidn't help for me in that case (and in the past) withxterm-256coloras myTERMwith the termcap from ncurses 5.9 (2014-07-26).The problem is that sometimes (esp. when breaking
fish_promptwhile testing) ctrl+c, del, and ctrl+h/bkspc becomes uninterpretable so that after a typo there is no option but to kill the process out-of-band (since I can no longer type inexit). Obviously that particular case (fish dev) is an edge case, but other such escaping issues exist.krader1961 commentedon Apr 3, 2018
@mqudsi, I missed the "does not help" part of your original comment. Nonetheless, what you're describing in your second comment implies that fish is not setting the tty driver mode to a sane value after running an external command. Something that should be impossible (at least as of 2017-09-08 when I stopped tracking the
masterbranch). Also, whatever escape sequences the application has sent to the terminal (e.g., to enable alternate keypad mode) can't possibly affect how fish handles things like [ctrl-C] or [backspace]. What the app does to the tty driver mode can if fish is no longer setting the tty driver mode to a sane value after an external command.Is this on a UNIX like platform? That is, not Cygwin or WSL? If so execute
ttybefore recreating the problem to capture the tty name. Capture the tty mode by runningstty -a < $ttywhere$ttyis the tty name you captured. Then recreate the problem and run, in a different terminal on the same system,stty -a < $tty. Are they the same? They should be identical.Also, when you say
it seems to me the need to kill the fish process is irrelevant. The fact it no longer responds to something as basic as the interrupt character (normally [ctrl-c]) is all we need to know. So I'm wondering if I've misunderstood what you're saying.
zanchey commentedon Apr 3, 2018
Does
stty sanehelp?krader1961 commentedon Apr 3, 2018
Note that if the problem is such that
stty sanefixes it then you'll probably need to press [ctrl-j] rather than [enter] to run the command. And if that does fix the problem it means fish is no longer ensuring the tty modes are sane after an external command is run.mqudsi commentedon Apr 4, 2018
@zanchey I'll have to work up a minimal reproduction case so I can test the
stty saneapproach, but essentially yes, fish is (no longer?) ensuring a sane tty after external commands.@krader1961 The reason I didn't feel that the lack of response to ctrl+c was enough is because it isn't so much fish ignoring sigint (which I should test via an external
kill -SIGINTnext time) as it was that ctrl+c was no longer mapped to sigint.Depending on the repro, sometimes enter still works and sometimes it doesn't (it did this last time, but when I broke fish_prompt it wouldn't any more). I'll try ctrl+j next time that happens, too, thanks for the tip, @krader1961 .
mqudsi commentedon Jun 1, 2018
I'm able to reproduce this now on kernel vtty (not x11 or ssh).
Executing the resulting binary causes the console to act up (input is no longer process correctly) under FreeBSD 12 from the login terminal. Cannot switch sessions, exit fish, or do anything useful.
ssh into the machine and kill the fish login session and everything goes back to normal.
faho commentedon Jun 3, 2018
@mqudsi: Are you sure that's about terminal modes getting screwed up?
There's a couple more things that could have happened there - did fish actually gain back control? Or did the display get frozen?
I actually think this being a problem with tty modes is fairly unlikely because fish is already resetting them.
mqudsi commentedon Jun 4, 2018
No, fish gets back control and I can interact with fish, it's just input is scrambled.
faho commentedon Jun 4, 2018
How is it scrambled? Does pressing ctrl-j or ctrl-m execute stufff? As in, did you try
stty sane<ctrl-j>, as was mentioned earlier in this issue?The weird part here is that fish is already supposed to restore the modes (https://github.com/fish-shell/fish-shell/blob/master/src/reader.cpp#L349-L363)!
Is that not happening? Is there something missing? Is there a race?
faho commentedon Nov 30, 2018
@mqudsi: Does this still happen for you?
I've not actually ever seen this with fish.
mqudsi commentedon Dec 1, 2018
I haven't experienced it in the past couple of months, but I haven't been working on anything that manipulates the terminal too much. Note that I already posted test code above which reproduces it 100% of the time, I could try that again if need be.
I don't think it's a race condition because running a subsequent command should trigger the code again and make it work, and that wasn't the case for me.
I imagine there's some state that we aren't saving/restoring? Or maybe it's an issue with the terminal (or terminal emulator) itself?
@krader1961 I'm thinking now that there's no way
stty sanecould actually ever work because we deliberately breakstty, don't we? #2315faho commentedon Dec 1, 2018
stty -abefore and after should show that.We restore the modes. So if we're missing any,
stty saneshould still affect those.faho commentedon Jan 26, 2019
Nobody has experienced this in a couple of months, let's close it for now!
14 remaining items
mqudsi commentedon Jan 18, 2021
I think so?
(I re-opened because the issue described with neovim is different)
faho commentedon Jan 18, 2021
Okay, if I understand correctly your issue is:
Garbage like

?
If so, neovim turned mouse reporting on and didn't turn it off. Fish does not do any mouse handling by itself, and won't currently turn mouse reporting on or off.
The solution is
echo -e "\e[?1000l"(echo -e "\e[?1000h"turns it on), but I don't know when that's accepted, I'm not particularly in the mood to do yet more terminal feature detection (can we get a better replacement for terminfo already), and this doesn't seem to be a common problem so I don't feel like handling it is worth it. If neovim crashed, just start neovim again and exit it cleanly, or start a new tab.mqudsi commentedon Jan 18, 2021
I don't think this needs any terminal feature detection? If fish doesn't use mouse detection, fish can (should?) just keep it off and any application that needs application-level mouse detection will be turn it back on as needed. I can't think of any apps that act differently (intentionally) based on whether or not the invoking shell has enabled mouse support. It would just have to be one of those states that is saved alongside a background process' state so that it is restored along with it but otherwise disabled.
faho commentedon Jan 18, 2021
You misunderstand. Fish doesn't need it, but neovim turned it on, and because it crashed did not turn it off!
And because turning it off involves sending an escape sequence, it needs feature detection.
faho commentedon Jan 19, 2021
Okay, the original issue was fixed, so I am closing this. As for the secondary issue with the mouse reporting, I'll refer to #4918. Turning mouse reporting off requires detecting if mouse reporting is supported in the first place, which is only really something that makes sense in the context of adding support for mouse reporting.
Any other ways to break the terminal (e.g. iTerm might be confused about which host the user is currently operating on) also require fish to know about these escapes. They should also be handled in separate issues.
Recognize and disable mouse-tracking CSI events
Recognize and disable mouse-tracking CSI events
Recognize and disable mouse-tracking CSI events
mqudsi commentedon Feb 23, 2021
All issues in this thread have now been resolved, with the mouse-related issues being addressed in mqudsi@eecc223 and subsequent commits.