colours in console

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
St8ic

colours in console

Post by St8ic »

How would I go about getting different coloured text in the console? I know it is a pretty basic procedure, but I can't get it to work correctly.

Thanks!
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

RE:colours in console

Post by gaf »

Hello St8ic
The characters consist of 2 bytes, the first byte is the ANSI-Character itself and the second is the attribute-byte. So if you want to change the color of a character, you simply have to overwrite it's attribute-byte.

The attribute-byte:
-------------------
b 0 Foreground - BLUE
b 1 Foreground - GREEN
b 2 Foreground - RED
b 3 Foreground - INTENSITY
b 4 Background - BLUE
b 5 Background - GREEN
b 6 Background - RED
b 7 BLINKING

The foreground-colortable:
--------------------------
0000 Black1000 Grey
0001 Blue 1001 Light Blue
0010 Green 1010 Light Green
0011 Cyan 1011 Light Cyan
0100 Red 1100 Light Red
0101 Magenta 1101 Light Magenta
0110 Brown 1110 Yellow
0111 White 1111 "Bright" White
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

RE:colours in console

Post by gaf »

Hello St8ic
The characters consist of 2 bytes, the first byte is the ANSI-Character itself and the second is the attribute-byte. So if you want to change the color of a character, you simply have to overwrite it's attribute-byte.

The attribute-byte:
-------------------
b 0 Foreground - BLUE
b 1 Foreground - GREEN
b 2 Foreground - RED
b 3 Foreground - INTENSITY
b 4 Background - BLUE
b 5 Background - GREEN
b 6 Background - RED
b 7 BLINKING

The foreground-colortable:
--------------------------
0000  Black         1000  Grey
0001  Blue         1001  Light Blue
0010  Green         1010  Light Green
0011  Cyan         1011  Light Cyan
0100  Red         1100  Light Red
0101  Magenta       1101  Light Magenta
0110  Brown         1110  Yellow
0111  White         1111  "Bright" White

The background-colortable is basically the same, but there's no intensity-bit, so you can only use the 3bit colors (on the left site)

regards,
gaf
Post Reply