-
-
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
Use child process worker to gracefully kill it on Crtl-C. Closes #281 #435
Conversation
src/main.rs
Outdated
|
||
let result = child.wait(); | ||
|
||
let _ = stdout.reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this reset will stop the control characters being printed which are causing your tests to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of commit is to add this reset to gracefully clean-up colors if necessary. There is no point in this commit otherwise.
I was waiting for @BurntSushi to discuss how to approach tests
src/main.rs
Outdated
|
||
let exe = env::current_exe().expect("Could not retrieve own exe's path"); | ||
let child = process::Command::new(exe).env(CHILD_ENV_VAR, "1") | ||
.args(env::args().skip(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure you will want to use env::args_os
here instead of env::args
so that invalid unicode is still passed properly as an argument. Else, this will fail the regression_210
test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for pointing it out.
@DoumanAsh Unfortunately, I think there are problems with this PR as-is, and I'm not sure that they are easy to solve. First and foremost, if ripgrep exits successfully, then there the term colors should never be reset. Namely, if ripgrep runs successfully to completion, then it will have reset the colors on its own already. Secondly, we shouldn't be resetting the colors if we didn't actually use them. This probably requires parsing |
Agree and corrected.
Yes, at first i thought about it but then it leads us to parse CLI arguments twice...
I'm not sure whether there is any special exit code for such cases? UPD: We can though set flag in our handler of |
That's not quite sufficient. Even if it accepted a |
@BurntSushi So how would you like to see solution to this problem? Is there something else you would like to point out? |
@DoumanAsh I would like to experiment with @jethrogb's ideas in #281. I will get around to it eventually, but until then, I'd request we just hit pause on this PR unfortunately. |
No, that's false. If a terminal doesn't support escape codes, then I imagine the escape code might show up as visible to the end user. We shouldn't be printing color codes if the end user requested that we shouldn't. |
Just wondering do you need this PR? |
I think it's probably fine to close this. I almost certainly want to move in a different direction. |
This PR should provide a graceful way to clean-up after sudden interruption by user.
It relies on libary
clonablechild
to provide way to wait and kill child in parallelI looked briefly at code but haven't found anything bad with it.
Decided to go with setting particular environment variable instead if hidden variable.
I believe we can choose careful variable that could ensure more or less almost 100% that there will be no collision.
This way we do not need to bother correcting clap parsing and just have modification in main function.
I would appreciate help in testing on linux though
cc @BurntSushi @seabadger
UPD: For now it seems to bring some issues to tests as it is always reseting terminal color and therefore the extra character at the end that breaks tests