none
Changing color of CMD prompt only RRS feed

  • General discussion

  • Hello all,

    First thanks for any help. I found a article that showed me how to set my command prompt to a specific color and then back to white as I type for my self. (ex 'C:\>' is the only part that is changed).

    So the command that I used is:

    prompt $e[0;32;40m$p$g$s$e[0;37;40m

    My question is what do these numbers mean: 0;32;40m...

    It changes the color of the prompt only to green, then back to white. I played around with it a bit and when I put a 4 for the first position where the 0 is, it gave made the prompt underlined. I have no clue what the numbers mean, except the middle number is the font color and that's about it.

    Just wondering if anyone has a reference to this and/or can explain exactly what these numbers mean.

    Thanks again for any help!!!

    Friday, April 22, 2016 9:02 PM

All replies

  • So playing with the second and third numbers some more, I'm not entirely sure that the second number is the foreground/font color because I can change the third number and the font color changes...
    Friday, April 22, 2016 9:06 PM
  • Those are known as "ANSI escape sequences". (Now you know what to search for)


    -- Bill Stewart [Bill_Stewart]

    Friday, April 22, 2016 9:10 PM
    Moderator
  • I have never used the prompt command in PowerShell, I don't believe it is supported.

    I like the emerald green on a black background myself, so I typically start an administrative DOS prompt [Start | Run | cmd], then type:  Color a  Then type:  Powershell so my powershell session inherits the colors from the DOS box.

    I have also used color conditions sometimes in Powershell to highlight certain output data on the screen. with the -foreground parameter.  

    (eg:  

    $var1 = "Magenta!"

    Write-Host $var1 -foreground "Magenta"

    If you run:  Color /? in DOS, it will show you which numbers and letters are associate with which colors. You can get creative with the foreground and background colors.

    Thursday, April 28, 2016 6:04 PM
  • Actually prompt is a function in PowerShell, which makes it pretty easy to dictate colors.

    Here's an example prompt that shows the day of week, date, and time in red.


    function prompt {
      Write-Host -NoNewline -ForegroundColor Red ("{0:ddd MM/dd HH:mm} >" -f (Get-Date))
      return " "
    }
    


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 28, 2016 7:14 PM
    Moderator