]> git.saurik.com Git - apple/system_cmds.git/blame - CPPUtil/UtilTerminalColor.cpp
system_cmds-671.10.3.tar.gz
[apple/system_cmds.git] / CPPUtil / UtilTerminalColor.cpp
CommitLineData
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
11BEGIN_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
26static const char colorcodes[2][2][8][10] = {
27 { ALLCOLORS("3",""), ALLCOLORS("3","1;") },
28 { ALLCOLORS("4",""), ALLCOLORS("4","1;") }
29};
30
31const 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
35const char* TerminalColorResetString(void) {
36 return "\033[0m";
37}
38
39END_UTIL_NAMESPACE