-
Notifications
You must be signed in to change notification settings - Fork 6
/
ColorPrint.h
47 lines (43 loc) · 1.05 KB
/
ColorPrint.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
// Copyright(C) 2021 Intel Corporation
// SPDX - License - Identifier: MIT
#pragma once
#include <sstream>
enum class ansi_color_code : int {
black = 30,
red = 31,
green = 32,
yellow = 33,
blue = 34,
magenta = 35,
cyan = 36,
white = 37,
bright_black = 90,
bright_red = 91,
bright_green = 92,
bright_yellow = 93,
bright_blue = 94,
bright_magenta = 95,
bright_cyan = 96,
bright_white = 97,
none = 98,
};
template<typename printable>
std::string print_as_color(printable const& value, ansi_color_code color) {
std::stringstream sstr;
#ifndef _WIN32
if (color != ansi_color_code::none) sstr << "\033[1;" << static_cast<int>(color) << "m" << value << "\033[0m"; else sstr << value;
#else
sstr << value;
#endif
return sstr.str();
}
template<ansi_color_code color, typename printable>
std::string print_as_color(printable const& value) {
std::stringstream sstr;
#ifndef _WIN32
if (color != ansi_color_code::none) sstr << "\033[1;" << static_cast<int>(color) << "m" << value << "\033[0m"; else sstr << value;
#else
sstr << value;
#endif
return sstr.str();
}