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

Colors don't reset properly in Powershell.exe #22

Closed
floyd-may opened this issue Jun 5, 2015 · 6 comments
Closed

Colors don't reset properly in Powershell.exe #22

floyd-may opened this issue Jun 5, 2015 · 6 comments

Comments

@floyd-may
Copy link

This code has some interesting behavior on powershell:

var ansi = require('ansi');

var ansiLogger = ansi(process.stderr);

ansiLogger.fg.red();
ansiLogger.bg.grey();

ansiLogger.write('colored output\n').reset();

Now, in ConEmu (my terminal of choice on Windows), this works fine:

image

However, if I use powershell.exe by itself, the colors don't reset properly:
image

See how the BG of all the text emitted afterwards is black? I discovered this originally from a bug logged to npm.

@stereokai
Copy link

@floyd-may Thanks you very much for putting in the work to discover this.

@TooTallNate - can we do something about this?

@mvas
Copy link

mvas commented Oct 23, 2015

that seems to be powershell issue.
The ansi itself has only one way to try to restore colors after changing them - and that is sending reset ANSI escape code (https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes)
Reading currently used background and foreground is impossible in general case and node.js does not provide API for doing that, so reseting is the only way.
Unfortunately, powershell treats that code as going back to black_and_white palette.

What I've found as a workaround is to update powershell profile and add [Console]::ResetColor(); to the Prompt function:
image
That makes powershell to reset colors when printing prompt.

Ping me if you need more details

@floyd-may
Copy link
Author

@mvas 👍

@YotaXP
Copy link

YotaXP commented Oct 23, 2015

Is the reset escape code really the proper solution? This happens in cmd as well if you customize the colors, so it is not specific to Powershell.

Though interestingly, this doesn't happen in MinGW.

@mvas
Copy link

mvas commented Oct 28, 2015

This is not a solution, that's a workaround. And for the PowerShell only.

By the way, I've updated my nodejs to 4.1.2 (it happened I used 0.12 before) and issue has gone.

@floyd-may
Copy link
Author

I confirm what @mvas says:

image

Looks like this is an issue with running an out-of-date version of nodejs.

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

No branches or pull requests

4 participants