Skip to content
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

Reset colors after abnormal exit #474

Closed
chucker opened this issue Nov 2, 2015 · 15 comments
Closed

Reset colors after abnormal exit #474

chucker opened this issue Nov 2, 2015 · 15 comments

Comments

@chucker
Copy link

chucker commented Nov 2, 2015

If chocolatey exits abnormally, this message appears:

Exiting chocolatey abnormally. Please manually clean up anything that
 was not finished.

Afterwards, the prompt color needs to be reset. (In my case, it was red.)

@ferventcoder
Copy link
Member

Ruh roh shaggy. What executable are you using? powershell.exe? cmd.exe? Something else like conemu?

@chucker
Copy link
Author

chucker commented Nov 2, 2015

cmd.exe on Windows 10.0.10565

@ferventcoder
Copy link
Member

Weird that this is going on. I haven't seen the behavior yet.

@moreandres
Copy link

I can reproduce when you interrupt using ctrl-C in the right moment (while choco install showing an error message in red for instance). I am running cmd.exe as admin.

@ferventcoder
Copy link
Member

I can reproduce this as well (my last comment was 2015) and I hadn't reproduced it by then. By now I've done it many a time and the problem is once it is exited, there is nothing to reset. Maybe catch and reset before it fully exits. The problem is the code that handles this is in log4net - no idea why it gets stuck.

Currently the only thing to do is close and reopen your shell.

@AdmiringWorm
Copy link
Member

@ferventcoder another option could perhaps be to hook into the CancelKeyPressed event, and cancel the currently running task, doing cleanup and then reset the console colors?

Never used it myself though, so I don't know how well that works for that event.

@ferventcoder
Copy link
Member

We already have code set for handling the cancel - https://github.com/chocolatey/choco/blob/0c11effebeadbd6bec1d1a16206942aef4204446/src/chocolatey/infrastructure/commandline/ExitScenarioHandler.cs. We went much more low level on that - maybe we didn't have to! All we'd need in there is to ensure we reset colors.

@AdmiringWorm
Copy link
Member

I see, in that case.
Shouldn't it be enough to just call Console.ResetColor() in the handler to restore the original colors of the console?

@ferventcoder
Copy link
Member

@AdmiringWorm Definitely worth a shot to add. It won't apply if you don't see the warning message though. Sometimes when you call control+c it just exits without a warning. That seems to be when the colors get messed up. So there is probably more to do to ensure that it is capturing those events.

If you want to create a PR for this, we'd accept it!

@AdmiringWorm
Copy link
Member

sure thing, I can do that.
But not able to do it until sunday at its earliest, I'll try to have a look around for alternative functionality for this though.

@AdmiringWorm
Copy link
Member

It won't apply if you don't see the warning message though. Sometimes when you call control+c it just exits without a warning.

I'm just guessing, but it could be that a different signal is sent instead (especially in cases where the user have done CTRL+C twice in a row).
It's probably the CTRL_SHUTDOWN_EVENT that is sent, which in my understanding is the equivalent of a SIGKILL signal.

@ferventcoder
Copy link
Member

That's a one line change in the code I shared above to remove that break; - we are handling that event currently by doing nothing but letting it exit.

There are more graceful ways we could clean up, which I believe is captured in another open ticket here.

@ferventcoder
Copy link
Member

This will be in 0.10.9

@ferventcoder ferventcoder changed the title Reset color after abnormal exit console - Reset colors after abnormal exit Mar 25, 2018
@ferventcoder ferventcoder changed the title console - Reset colors after abnormal exit Reset colors after abnormal exit Mar 25, 2018
ferventcoder pushed a commit that referenced this issue Mar 25, 2018
With this commit the console is always reset when an abnormal exit
has occurred. Without this change, all customizations of the console
may still be present when choco have exited.
ferventcoder added a commit that referenced this issue Mar 25, 2018
* stable:
  (version) 0.10.9
  (doc) update release notes
  (GH-474) Adding reset of console on abnormal exit
  (doc) update release notes
  (GH-1526) Provide friendly messages on exit codes
  (maint) update tab expansion
  (GH-1365) Do not warn on missing folders
  (doc) update release notes
  (GH-1524) Capture password when only user is provided
@john-aws
Copy link

Still an issue with chocolatey v1.2.1 on Windows 10. Run choco list, wait a few seconds, then press ctrl+c. The command prompt is now red.

@corbob
Copy link
Member

corbob commented Dec 14, 2022

Hi @john-aws,

Thanks for your comment. As this particular issue was closed over 4 years ago, would you mind opening a new issue and filling out the template? Of particular help would probably be a video of the issue happening, as well as consistent reproduction steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants