Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you reset the colors for Windows PowerShell if they become corrupted after running a program?

I am starting to use PowerShell for a Windows project using node.js. When running many programs (including node, supervisor and npm) from the Powershell commmand line, my PowerShell background and foreground colors start to change from the default Powershell colors. How can I maintain a consistent look within PowerShell so I can easily read the results of running commands?

like image 534
SnapShot Avatar asked Dec 10 '12 17:12

SnapShot


2 Answers

As a one-time operation just run this:

> [Console]::ResetColor() 

From the docs: (emphasis added)

The foreground and background colors are restored to the colors that existed when the current process began.

like image 165
Shaun Luttin Avatar answered Oct 12 '22 23:10

Shaun Luttin


I have this problem with MSBuild especially when I ctrl+C a build. This is what I put in my profile.ps1 file:

$OrigBgColor = $host.ui.rawui.BackgroundColor $OrigFgColor = $host.ui.rawui.ForegroundColor  # MSBUILD has a nasty habit of leaving the foreground color red # if you Ctrl+C while it is outputting errors. function Reset-Colors {     $host.ui.rawui.BackgroundColor = $OrigBgColor     $host.ui.rawui.ForegroundColor = $OrigFgColor } 

Then I just invoke Reset-Colors when MSBuild has messed them up.

like image 41
Keith Hill Avatar answered Oct 13 '22 00:10

Keith Hill