rabite0 / hunter

The fastest file manager in the galaxy!
Do What The F*ck You Want To Public License
1.31k stars 64 forks source link

Terminal left in bad state after running hunter #13

Closed wezm closed 5 years ago

wezm commented 5 years ago

OS: Arch Linux Terminal: Alacritty 0.2.9 Hunter Version: 1.0.1 (evil branch) (also happens in master branch)

Steps to Reproduce

  1. Run hunter
  2. Quit hunter q

Expected Results

After exiting the terminal is restored to its previous state.

Actual Results

After exiting it's no longer possible to scroll or click in the Alacritty window. Doing so outputs what appears to be raw escape sequences that look like this:

65;52;47M65;52;46M65;52;46M65;52;46M65;52;46M64;52;46M64;52;46M64;52;46M0;52;46M0;52;46m0;52;46m0;52;46m0;33;64M32;34;64M32;34;65M32;35;65M0;35;65m
rabite0 commented 5 years ago

I'm aware that it can happen sometimes, but I'm not actually sure how and why. The termion library is supposed to reset the terminal to the previous state when the RawTerminal is dropped, but it doesn't actually seem to happen. Maybe I'm using it wrong but I don't know.

As a workaround I implemented the drop_screen method in term.rs, which runs "reset -I" on quitting. It also does that when running a subshell. Does it also consistently happen when running a subshell? Type z to enter a subshell.

Maybe some other flags for reset are needed, but it would be better if termion actually reset the terminal like it's supposed to. Maybe I should report a bug on termion... Definitely need to check this out.

rabite0 commented 5 years ago

Just had this happen to me as well on kitty+tmux. Not sure what's causing it, most of the time that "reset -L" is enough to get the terminal into a sane state. I have to play around with termion and see if I can get the resetting it's supposed to do working. In the mean-time I might go for a full "reset", but this clears the screen, which is unfortunate.

While I'm at it I should add a panic handler that fixes the terminal in case of a crash.

rabite0 commented 5 years ago

OK, so I poked around a bit and it seems fixed now. I even added a panic-handler, so that the terminal gets reset on a crash.

Can you still get it to mangle the terminal? I tried a few things and couldn't, but there might be something I overlooked.

Thanks for testing/reporting.

cpdean commented 5 years ago

I had experienced this symptom before, but after pulling master a couple hours ago it seems to restore my terminal correctly now on macos.

rabite0 commented 5 years ago

Great, thanks. If it still happens, feel free to reopen.

therealklanni commented 5 years ago

Just ran into this exact issue on latest build with nightly rust (does not compile on stable). Please reopen.

macOS 10.14.4 (18E226) rustc 1.36.0-nightly (3991285f5 2019-04-25)

rabite0 commented 5 years ago

Can you give a bit more detail? What did you do? Ran any commands, entered a subshell, or something like that? Is it reproducible?

therealklanni commented 5 years ago

Happens no matter what I do (or don't do). If you need any specific detail, I'm happy to oblige.

cpdean commented 5 years ago

@therealklanni

Just ran into this exact issue on latest build with nightly rust (does not compile on stable).

When it does not build, does the compiler give you an error?

rabite0 commented 5 years ago

Hunter only compiles on nightly because it relies on try_trait to turn None Options into Results to simplify error handling. I should probably turn these into custom error types so it's clear what exactly was None, but that would be a bit of work.

rabite0 commented 5 years ago

Weird, it works fine here on alacritty, kitty, urxvt and xterm, with or without tmux, etc..., when I quit the terminal resets to the main screen. I've seen it bug out during development when it crashes in weird ways sometimes, but otherwise it's become pretty solid in my experience. But apparently not...

@therealklanni What terminal emulator are you using? What does echo $TERM say?

Does the terminal get fixed when you call "reset"? What about "reset -I"?

I actually had hunter call "reset" at some point, but I fixed how I use termion and it seemed fine on its own. The downside is that reset has to be loaded before hunter can really quit, which could be slow, depending on the environment. It also clears the screen, which is not nice. With "-I" it doesn't clear the screen, but it's not as thorough in resetting, so it might not be enough. But if it is, great.

If that works I could add an option so hunter calls reset when it quits. I'm thinking about ways that might fix this, but if I can't even reproduce it, it's hard. Especially since I don't have access to macOS, so I can't even test things that don't work on it.

EDIT: Actually, this could be a generic "on-quit"-hook kind of thing. It might be useful for other things, too.

therealklanni commented 5 years ago

@rabite0 I'm using zsh (zsh 5.7.1 (x86_64-apple-darwin18.2.0)) in iTerm (Build 3.2.7).

The "bad state" I experienced is all input keys are echoed to the terminal instead of being recognized by the terminal as inputs. The only thing that was working as a fix was to completely restart the terminal (restarting zsh wasn't enough).

Interestingly I'm not seeing this behavior today, but it was consistent when I reported it. I haven't updated my terminal or shell, nor have I recompiled hunter since then.

Will let you know if the issue returns.

rabite0 commented 5 years ago

That could have been a half-crashed hunter. I recently fixed a bug where it crashed halfway without really exiting completely. I think it was #26.

If that's it, you can kill hunter and your terminal should work again.

I recommend updating though :)

rabite0 commented 5 years ago

Ok, so I did take another look at this and it turns out that termion has special methods to get in and out of RAW-mode. After a bit of fiddling I got it working without issues on all terminals I tested now.

I tried opening subshells and running things like htop, directly opening files in a (terminal) editor from the file list in hunter, etc, etc and it always resets the terminal nicely when it quits.

There rare still some drawing issues with urxvt, but even there resetting seems to work fine.

This should be fixed now. Or so I hope :').