-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset terminal at prompt to clean up after bad termination of certain scripts #4873
Comments
The example you cite (arrow keys not working) is usually because the app enabled alternate keypad mode (sometimes known as application keypad mode). The |
Hmmm, The problem is that sometimes (esp. when breaking |
@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 Is this on a UNIX like platform? That is, not Cygwin or WSL? If so execute 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. |
Does |
Note that if the problem is such that |
@zanchey I'll have to work up a minimal reproduction case so I can test the @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 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 . |
I'm able to reproduce this now on kernel vtty (not x11 or ssh). #include <SDL.h>
int main(int argc, char * argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(500, 500, 32, SDL_DOUBLEBUF | SDL_OPENGL); // should fail
return 1; //without calling SDL_Quit();
} 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. |
@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. |
No, fish gets back control and I can interact with fish, it's just input is scrambled. |
How is it scrambled? Does pressing ctrl-j or ctrl-m execute stufff? As in, did you try 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? |
@mqudsi: Does this still happen for you? I've not actually ever seen this with fish. |
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 |
We restore the modes. So if we're missing any, |
Nobody has experienced this in a couple of months, let's close it for now! |
Ok, I ran into this using the Elementary OS terminal application (it's its own thing) with whatever version of fish is in the Ubuntu repository used by Elementary OS Hera, but wasn't able to come up with a repro. But this is important because it means that the repro I was able to come up with isn't a bug in the specific terminal I'm using. Read on. I do, however, have a very convoluted and specific repro that demonstrates the problem every single time. I run neovim under wsl in conhost with termguicolors and a colored theme then send I was leaning heavily towards this being a bug in conhost, but then I discovered that merely starting I believe that in addition to resetting the terminal state we also need to reset something in ncurses: all of fish, nvim, and fzf use ncurses and when I send neovim SIGBART, I rob it of the opportunity to call |
@faho can you please dial back on closing issues? It makes it hard to keep track of things that haven't been tested and confirmed fixed/wontfix. (and this particular issue still replicates; #7133 mentions that it's a separate bug from this one, and d5a239e has nothing to do with this, it was only termsize) |
This is quite possibly a separate issue but with the same underlying cause (ncurses modifies something in the terminal state that fish does not restore): After
While starting and cleanly exiting an ncurses app (nvim) does not fix the terminal (hypothesis: ncurses correctly restores the previous - albeit broken - terminal state on exit), importantly |
So, comparing your
of which the only output related one is onlcr - "translate newline to carriage return-newline". And when I do turn that off I indeed get weird staircase output. So it seems we just need to restore that one? Note that we used to disable it because of #4505. It seems we may need to force it to on instead. |
I think so? (I re-opened because the issue described with neovim is different) |
Okay, if I understand correctly your issue is:
? 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 |
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. |
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. |
Fish was previously oblivious to the existence of mouse-tracking ANSI escapes; this was mostly OK because they're disabled by default and we don't enable them, but if a TUI application that turned on mouse reporting crashed or exited without turning mouse reporting off, fish would be left in an unusable state as all mouse reporting CSI sequences would be posted to the prompt. This can be tested by executing `printf '\x1b[?1003h'` at the prompt, then clicking with any mouse button anywhere within the terminal window. Previously, this would have resulted in seeming garbage being spewed to the prompt; now, fish detects the mouse tracking CSIs posted to stdin by the terminal emulator and a) ignores them to prevent invalid input, as well as b) posts the CSI needed to disable future mouse tracking events from being emitted on subsequent mouse interactions (until re-enabled). Note that since we respond to a mouse tracking CSI rather than pre-emptively disable mouse reporting, we do not need to do any sort of feature detection to determine whether or not the terminal supports mouse reporting (otherwise, if it didn't support it and we posted the CSI anyway, we'd end up with exactly the kind of cruft posted to the prompt that we're trying to avoid). Fixes fish-shell#4873
Fish was previously oblivious to the existence of mouse-tracking ANSI escapes; this was mostly OK because they're disabled by default and we don't enable them, but if a TUI application that turned on mouse reporting crashed or exited without turning mouse reporting off, fish would be left in an unusable state as all mouse reporting CSI sequences would be posted to the prompt. This can be tested by executing `printf '\x1b[?1003h'` at the prompt, then clicking with any mouse button anywhere within the terminal window. Previously, this would have resulted in seeming garbage being spewed to the prompt; now, fish detects the mouse tracking CSIs posted to stdin by the terminal emulator and a) ignores them to prevent invalid input, as well as b) posts the CSI needed to disable future mouse tracking events from being emitted on subsequent mouse interactions (until re-enabled). Note that since we respond to a mouse tracking CSI rather than pre-emptively disable mouse reporting, we do not need to do any sort of feature detection to determine whether or not the terminal supports mouse reporting (otherwise, if it didn't support it and we posted the CSI anyway, we'd end up with exactly the kind of cruft posted to the prompt that we're trying to avoid). Fixes fish-shell#4873
Fish was previously oblivious to the existence of mouse-tracking ANSI escapes; this was mostly OK because they're disabled by default and we don't enable them, but if a TUI application that turned on mouse reporting crashed or exited without turning mouse reporting off, fish would be left in an unusable state as all mouse reporting CSI sequences would be posted to the prompt. This can be tested by executing `printf '\x1b[?1003h'` at the prompt, then clicking with any mouse button anywhere within the terminal window. Previously, this would have resulted in seeming garbage being spewed to the prompt; now, fish detects the mouse tracking CSIs posted to stdin by the terminal emulator and a) ignores them to prevent invalid input, as well as b) posts the CSI needed to disable future mouse tracking events from being emitted on subsequent mouse interactions (until re-enabled). Note that since we respond to a mouse tracking CSI rather than pre-emptively disable mouse reporting, we do not need to do any sort of feature detection to determine whether or not the terminal supports mouse reporting (otherwise, if it didn't support it and we posted the CSI anyway, we'd end up with exactly the kind of cruft posted to the prompt that we're trying to avoid). Fixes fish-shell#4873
All issues in this thread have now been resolved, with the mouse-related issues being addressed in mqudsi@eecc223 and subsequent commits. |
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.)tput init
does not help.The text was updated successfully, but these errors were encountered: