-
Notifications
You must be signed in to change notification settings - Fork 0
/
back_example.c
67 lines (60 loc) · 1.66 KB
/
back_example.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "colr.h"
int main(void) {
// Basic colors:
char* s = colr_cat(
fore(BLACK),
back(RED), "This is a test",
back(BLUE), " and only a test."
);
if (!s) return 1;
printf("%s\n", s);
free(s);
// Color names:
char* n = colr_cat(
back("blue"),
fore("white"),
"This is blue."
);
if (!n) return 1;
printf("%s\nThis is not.\n", n);
free(n);
// Extended (256) colors:
char* e = colr_cat(fore(ext(0)), back(ext(35)), "Extended colors.\n");
if (!e) return 1;
printf("%s", e);
free(e);
// RGB (True Color) colors:
char* r = colr_cat(back(rgb(35, 0, 155)), "RGB");
if (!r) return 1;
printf("%s\n", r);
free(r);
// Hex (RGB style) colors:
char* h = colr_cat(
back("#ff0000"), "Hex RGB\n",
back(hex("fff")), fore(hex("000000")), "Hex macro RGB\n",
back(hex_or("NOTHEX", rgb(255, 255, 255))), "Using default for bad hex str"
);
if (!h) return 1;
printf("%s\n", h);
free(h);
// Hex (Closest ExtendedValue) colors:
char* he = colr_cat(
back(ext_hex("ff0000")), "Closest ExtendedValue Hex\n",
back(ext_hex_or("NOTAHEX", ext(255))), "Using default for bad hex str"
);
if (!he) return 1;
printf("%s\n", he);
free(he);
/*
Colr() accepts a back() as one of it's arguments.
The order does not matter.
*/
char* colorized = colr_cat(
Colr("This is red.\n", back(RED)),
Colr("This is also red.\n", fore("white"), back("red")),
"This is not."
);
if (!colorized) return 1;
printf("%s\n", colorized);
free(colorized);
}