Multiple ASCI

Pages: 12
As the form of the "Set Graphics Mode" ascii sequence is

Esc[Value;...;Valuem

where value is either
a. 3x for a foreground color
b. 4x for a background color
(where x = 0..7, for black, red, green, yellow, blue, magenta, cyan, white)
c. or a text attribute
(0 for all off, 1 for bold on, etc.)

You could do something like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>

#define BLACK   0
#define RED     1
#define GREEN   2
#define YELLOW  3
#define BLUE    4
#define MAGENTA 5
#define CYAN    6
#define WHITE   7

#define NORMAL  0
#define BOLD    1
#define UNDERSCORE 4
#define BLINK   5
#define REVERSE 7

void text_out(int attr, int fcol, int bcol, const char* msg)
{
    printf("\033[%i;3%i;4%im%s\033[0m\n", attr, fcol, bcol, msg);
}

int main()
{
    text_out(NORMAL, YELLOW, BLUE, "Hello world!");
    text_out(BOLD, RED, YELLOW, "Bonjour le monde !");
    text_out(BLINK, WHITE, RED, "Hej varlden!");
    text_out(REVERSE, GREEN, MAGENTA, "Wapendwa ulimwengu!");
    text_out(UNDERSCORE, BLACK, GREEN, "Hallo Welt !");

    return 0;
}


Andy

ANSI Escape sequences
http://ascii-table.com/ansi-escape-sequences.php
Last edited on
Thank you...
Before I had a define.h that was like 60 lines now it'll be like 15
Hey problem when I append the same thing happens...
I added an append space after each switch and the background works text doesn't...
Topic archived. No new replies allowed.
Pages: 12