Paul Nathan
Paul Nathan

Reputation: 40299

Windows API colored output to stdout in Powershell/cmd.exe

Anyone know where to find a reference that describes how to output color on the Windows CLI interfaces using API and/or stdout?

Upvotes: 4

Views: 3426

Answers (4)

Leon
Leon

Reputation: 91

Not exactly a reference but it should help you find what you're looking for on MSDN, check out:

http://www.gamedev.net/community/forums/topic.asp?topic_id=457528.

You probably want to look up "WriteConsoleOutput".

Upvotes: 1

ChrisN
ChrisN

Reputation: 16933

The Win32 console API has a function, SetConsoleTextAttribute, that can be used to set the text foreground and background colours. Sample code is here.

Upvotes: 3

Jimmy
Jimmy

Reputation: 91432

in powershell write-host takes -backgroundcolor and -foregroundcolor parameters

Upvotes: 0

Toon Krijthe
Toon Krijthe

Reputation: 53366

At least there is the color command:

color bg fg

where:

0: Black
1: Blue
2: Green
3: Cyan
4: Red
5: Purple
6: Yellow
7: Gray
8: Silver
9: Light blue
A: Lime
B: Light cyan
C: Light red
D: Light purple
E: Light yellow
F: White

Example:

color 80

Gives a silver background with black text.

Upvotes: 1

Related Questions