Stop all threads and write ANSI-Reset on Ctrl-C#2727
Conversation
|
When suggesting to someone to use A lot of users have shells or prompts which handle this automatically. But now that |
|
I've only skimmed this PR so far, but there is a ton of code here. And it also introduces a new dependency on Separate from that, ripgrep used to have handling like this, but it ended up offering a worse user experience. Namely,
I just use a simple little script to fix coloring if and when it happens (which is rare): https://github.com/BurntSushi/dotfiles/blob/eb14900839a210f31b826f0ab070506528ea6a99/bin/reset-term
This is not a recent development. This has been true for years. |
On Ctrl-C stop all threads currently writing to the terminal, ignoring whatever they have locked, and write the ANSI-Reset code directly to the terminal, then exit. This uses `pthread_kill()` or `SuspendThread()`, then `libc::write()` or `WriteConsoleA()` on Unix or Windows, respectively.
b0323c7 to
a671258
Compare
Both crates work fine, I added a commit which uses
I've seen the previous behavior, this is fixed in this PR. It does this by (safely) ignoring any held locks which could slow down a fast exit, so a few syscalls have to be issued directly.
I must be thinking in Debian releases, there it has only been included for one or two releases I think :) |
|
ripgrep has been in Debian for years. I'm not sure if I'm going to take this. It is so much code to solve an issue that I don't think is a big deal. |
|
I'm going to close this. I don't think my opinion has changed since the above. I've tried this in the past, and it just lead to worse problems. 500 lines of code to deal with this just isn't worth it IMO. |
On Ctrt-C stop all threads currently writing to the terminal, ignoring whatever they have locked, and write the ANSI-Reset code directly to the terminal, then exit.
This uses
pthread_kill()orSuspendThread(), thenlibc::write()orWriteConsoleA()on Unix or Windows, respectively.So far only tested and enabled on Linux, macOS and Windows (cmd.exe, Powershell, Mingw64), but I am sure this will
work on the BSDs and several others which have
pthread_kill()- but I'd rather have someone confirm this first.And to compare the before/after, running
rgwith a-jof 7, 11, 22, 33.. etc. will disable this handler.