-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colr_example.c
51 lines (47 loc) · 1.42 KB
/
Colr_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
#include "colr.h"
int main(void) {
/*
Colr() is for styling one piece of text.
When combined with the colr_cat() macro it allows you to seperate colors/styles.
*/
char* colorized = colr_cat(
Colr("America ", fore(RED)),
Colr("the ", fore(WHITE)),
Colr("beautiful", fore(BLUE)),
".\n"
);
/*
All of the Colr, fore, back, and style resources were free'd by `colr`.
You are responsible for the text and the resulting colorized string.
*/
if (!colorized) return 1;
printf("%s", colorized);
free(colorized);
/*
There are three justification macros that make it easy to create
ColorText's with center, left, or right-justified text.
*/
char* just = colr_cat(
Colr_center("This is centered.", 80, fore("lightblue")),
"\n",
Colr_ljust("This is on the left.", 38, fore(ext_hex("ff2525"))),
"----",
Colr_rjust("This is on the right.", 38, fore(ext_rgb(255, 53, 125)))
);
if (!colorized) return 1;
printf("%s\n", just);
free(just);
/*
If you don't need several Colr() calls, there is a shortcut for safely
creating colorized text using colr().
*/
char* fast = colr(
"Hello from ColrC.",
fore("#2500FF"),
back(ext_hex("#353535")),
style(UNDERLINE)
);
if (!fast) return 1;
printf("%s\n", fast);
free(fast);
}