]>
Commit | Line | Data |
---|---|---|
bd6521f0 A |
1 | // |
2 | // UtilTerminalColor.cpp | |
3 | // CPPUtil | |
4 | // | |
5 | // Created by James McIlree on 4/26/13. | |
6 | // Copyright (c) 2013 Apple. All rights reserved. | |
7 | // | |
8 | ||
9 | #include "CPPUtil.h" | |
10 | ||
11 | BEGIN_UTIL_NAMESPACE | |
12 | ||
13 | #define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m" | |
14 | ||
15 | #define ALLCOLORS(FGBG,BOLD) {\ | |
16 | COLOR(FGBG, "0", BOLD),\ | |
17 | COLOR(FGBG, "1", BOLD),\ | |
18 | COLOR(FGBG, "2", BOLD),\ | |
19 | COLOR(FGBG, "3", BOLD),\ | |
20 | COLOR(FGBG, "4", BOLD),\ | |
21 | COLOR(FGBG, "5", BOLD),\ | |
22 | COLOR(FGBG, "6", BOLD),\ | |
23 | COLOR(FGBG, "7", BOLD)\ | |
24 | } | |
25 | ||
26 | static const char colorcodes[2][2][8][10] = { | |
27 | { ALLCOLORS("3",""), ALLCOLORS("3","1;") }, | |
28 | { ALLCOLORS("4",""), ALLCOLORS("4","1;") } | |
29 | }; | |
30 | ||
31 | const char* TerminalColorStringFor(kTerminalColor code, bool is_bold, bool is_background) { | |
32 | return colorcodes[is_background ? 1 : 0][is_bold ? 1 : 0][(uint32_t)code & 7]; | |
33 | } | |
34 | ||
35 | const char* TerminalColorResetString(void) { | |
36 | return "\033[0m"; | |
37 | } | |
38 | ||
39 | END_UTIL_NAMESPACE |