-
-
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
Stop all threads and write ANSI-Reset on Ctrl-C #2727
base: master
Are you sure you want to change the base?
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. |
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
rg
with a-j
of 7, 11, 22, 33.. etc. will disable this handler.