-
Notifications
You must be signed in to change notification settings - Fork 2
/
printf_colour.c
44 lines (37 loc) · 861 Bytes
/
printf_colour.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
/* printf_colour.c
a sample showing how to print text in colour (in terminal).
C.D.Luminate
at 30/06/2014
*/
#include <stdio.h>
int
main (void)
{
/* int fprintf(FILE *stream, const char *format, ...); */
fprintf (stdout, "\033[31m RED hello world.\033[m\n");
/* chars after "\033[31m" will be printed in red,
while colour of chars after "\033[m" is restored.
*/
/* it is green */
fprintf (stdout, "\033[32m what colour is it\033[m\n");
/* tips :
using vim, press Ctrl^V then ESC, will insert a char '\033',
which is displayed as '^[' and it is one char, rather than
'^' + '['
*/
/* 31 red
32 green
33 yellow
34 blue
35 purple
36 colour bettwen green and blue.
37 grey
*/
return 0;
}
/*
* Reference:
*
* screen(1), where an amount of terminal control sequences are introduced.
*
*/