forked from arminbiere/satch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.h
55 lines (43 loc) · 1.22 KB
/
colors.h
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
#ifndef _colors_h_INCLUDED
#define _colors_h_INCLUDED
#ifndef NCOLOR
#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#define COLORS(FD) \
assert (FD == 1 || FD == 2); \
bool colors = isatty (FD); \
FILE * terminal_file = ((FD == 1) ? stdout : stderr); \
(void) terminal_file /* needed if 'terminal_file' is not used */
#define BLUE_CODE "\033[34m"
#define BOLD_CODE "\033[1m"
#define BOLD_GREEN_CODE "\033[1;32m"
#define GREEN_CODE "\033[32m"
#define MAGENTA_CODE "\033[35m"
#define NORMAL_CODE "\033[0m"
#define RED_CODE "\033[31m"
#define YELLOW_CODE "\033[33m"
#define BLUE (colors ? BLUE_CODE : "")
#define BOLD (colors ? BOLD_CODE : "")
#define BOLD_GREEN (colors ? BOLD_GREEN_CODE : "")
#define GREEN (colors ? GREEN_CODE : "")
#define MAGENTA (colors ? MAGENTA_CODE : "")
#define NORMAL (colors ? NORMAL_CODE : "")
#define RED (colors ? RED_CODE : "")
#define YELLOW (colors ? YELLOW_CODE : "")
#define COLOR(NAME) \
do { \
if (colors) \
fputs (NAME ## _CODE, terminal_file); \
} while (0)
#else
#define COLORS(...) do { } while (0)
#define BLUE ""
#define BOLD ""
#define MAGENTA ""
#define NORMAL ""
#define RED ""
#define YELLOW ""
#define COLOR(NAME) do { } while (0)
#endif
#endif