-1

I was wondering if you could have certain words be certain color in cmd contrary to making the whole instance having the same color them with color with built-in command prompt commands rather than using c or other external methods. Answers in powershell script will also be accepted.

  • 2
    depending on the console you are using, you may be able to use ansi escape sequences. the "new" windows terminal app supports that, for instance – Lee_Dailey Apr 28 '20 at 22:23
  • I see, I do use the new Windows Terminal, but I was wondering of a was to implement it in batch files so this wouldn't be the best answer for me since so far I don't think it is possible to run a batch file through the new windows terminal. Your answer does work but is not the right one for my case. –  Apr 28 '20 at 22:31
  • the old `Command.Com` console supported ansi, but `Cmd.exe` does not do so. there are modules for powershell that allow mixed color text. if that would work for you, take a look at a search for `powershell write color` for a bunch of such items. several are on the PSGallery site. – Lee_Dailey Apr 28 '20 at 22:37
  • It's not specific to Windows Terminal. cmd in general can support ANSI escape sequences as of Windows 10.0.1511. – SomethingDark Apr 28 '20 at 22:37
  • I see, oppose to the ANSI I found the solution in the `powershell write-host "blah" -foregroundcolor color` command –  Apr 28 '20 at 22:47
  • @SomethingDark Yes that works to but I feel `powershel write-host "words" -foregroundcolor color is a better solution for the purpose I had in mind –  Apr 28 '20 at 22:54
  • That's fair; it's way less to write. Just keep in mind that if you use it too much at once in a batch script, you'll notice a performance decrease. – SomethingDark Apr 28 '20 at 22:55
  • https://winsourcecode.blogspot.com/2019/12/colourtext-changes-colour-of-text-to-be.html –  Apr 28 '20 at 22:55
  • @SomethingDark yes this indeed I had been using long convoluted scripts like the answer you linked but now I fond this though it may have performance issues would also be easier for me. – Nico Nekoru Apr 28 '20 at 22:59
  • If you find yourself wanting more control with less effort, [a script that makes use of ANSI codes as macro arguments](https://stackoverflow.com/a/61174175/12343998) can save a lot of typing. To execute, `%Param|% Your messsage goes here %Pos.Color% Line#;Column# color` Performance is much better than powershell and provides more flexibility. – T3RR0R Apr 29 '20 at 04:23
  • Except it won't work on many computers. –  Apr 29 '20 at 06:50
  • You may use the method described at [Read arrow keys and show color text in an efficient way](https://www.dostips.com/forum/viewtopic.php?f=3&t=6936) to show color text via a _resident_ Powershell module. This method is fast enough to program some animated games in Batch, like [Tetris](https://www.dostips.com/forum/viewtopic.php?f=3&t=6936&p=46206#p46206) or [Snake with several players](https://www.dostips.com/forum/viewtopic.php?f=3&t=8606&hilit=Antonio) – Aacini Apr 29 '20 at 23:10

1 Answers1

0

The answer I was looking for was in the powershell command write-host "words" -foregroundcolor color where color is a specific color like red and words is text you want to print. To implement this in batch files you can use powershell write-host "words" -foregroundcolor color and it works! Write-Host must be used as opposed to write or echo.