chase / awrit

A full graphical web browser for Kitty terminal with mouse and keyboard support
Other
431 stars 14 forks source link

Reset terminal attributes after exit #20

Open aarondill opened 1 year ago

aarondill commented 1 year ago

Issue: After exiting awrit (using pkill awrit bc ctrl+c doesn't work for me :disappointed:), moving the mouse results in escape codes being written to the terminal. This is fixed by a tput reset.

Expected behavior: awrit sets the terminal attributes to their previous values, or if impossible, then resets them to default (essentially tput reset)

Environment: wezterm 20230712-072601-f4abf8fd on Ubuntu 22.04.2 LTS

AnonymouX47 commented 1 year ago

Not sure if there's a particular key binding to exit "properly" but pkill -2 awrit should send SIGINT (as ctrl + c does) instead of SIGTERM sent by pkill awrit.

EDIT: Default is SIGTERM, not SIGKILL.

chase commented 1 year ago

Hm, strange that Ctrl+C stopped working. If you want to play around with it, the intercept code is here: https://github.com/chase/awrit/blob/main/awrit/input_event_handler.cc#L23-L30

Realistically, awrit should have a signal handler to handle any terminating event and exit cleanly.

I'm rather busy for a while so I can't put time into this right now, but if you figure out a fix for this I'll gladly accept a PR

aarondill commented 1 year ago

Not sure if there's a particular key binding to exit "properly" but pkill -2 awrit should send SIGINT (as ctrl + c does) instead of SIGKILL sent by pkill awrit.

According to man pkill:

       pkill will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout.

While SIGTERM is not the same as SIGINT, they should both be handled (nearly) identically by every program, and unlike SIGKILL can and should be caught before cleanup.

Infact, it seems to be caught and handled the same as SIGINT here, which means any signal that is passed will be treated identically. It seems that it just doesn't reset terminal attributes?

AnonymouX47 commented 1 year ago

According to man pkill:

       pkill will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout.

Sorry, that was an error on my part. Corrected it.

Infact, it seems to be caught and handled the same as SIGINT here, which means any signal that is passed will be treated identically. It seems that it just doesn't reset terminal attributes?

Oh, I see... thanks.

chase commented 1 year ago

I just made a fresh build and I can't reproduce this issue in Kitty. It correctly resets the terminal attributes.

I believe this might be a wezterm-specific issue. While wezterm should mostly work, there are bound to be issues like this that arise since I primarily use and test things in Kitty.


Detecting if things are running in wezterm and apply additional fixes is probably the best we can do in this case. I'm still busy unfortunately, so I'd appreciate any PRs, hacky or not 🙂

metamaterialsuit commented 6 months ago

I also was having problems with ctrl+c -- turns out, doing ctrl+c + c (ctrl+c followed by another c while holding ctrl) works. I don't know why that's happening.