1 #pragma once 2 // color_print.hpp: base classes to print color to a shell 3 // 4 // Copyright (C) 2017-2021 Stillwater Supercomputing, Inc. 5 // 6 // This file is part of the universal numbers project, which is released under an MIT Open Source license. 7 #include <iostream> 8 9 namespace sw::universal { 10 11 struct ColorCode { 12 static constexpr int FG_DEFAULT = 39; 13 static constexpr int FG_BLACK = 30; 14 static constexpr int FG_RED = 31; 15 static constexpr int FG_GREEN = 32; 16 static constexpr int FG_YELLOW = 33; 17 static constexpr int FG_BLUE = 34; 18 static constexpr int FG_MAGENTA = 35; 19 static constexpr int FG_CYAN = 36; 20 static constexpr int FG_LIGHT_GRAY = 37; 21 static constexpr int FG_DARK_GRAY = 90; 22 static constexpr int FG_LIGHT_RED = 91; 23 static constexpr int FG_LIGHT_GREEN = 92; 24 static constexpr int FG_LIGHT_YELLOW = 93; 25 static constexpr int FG_LIGHT_BLUE = 94; 26 static constexpr int FG_LIGHT_MAGENTA = 95; 27 static constexpr int FG_LIGHT_CYAN = 96; 28 static constexpr int FG_WHITE = 97; 29 30 static constexpr int BG_DEFAULT = 49; 31 static constexpr int BG_BLACK = 40; 32 static constexpr int BG_RED = 41; 33 static constexpr int BG_GREEN = 42; 34 static constexpr int BG_YELLOW = 43; 35 static constexpr int BG_BLUE = 44; 36 static constexpr int BG_MAGENTA = 45; 37 static constexpr int BG_CYAN = 46; 38 static constexpr int BG_LIGHT_GRAY = 47; 39 static constexpr int BG_DARK_GRAY = 100; 40 static constexpr int BG_LIGHT_RED = 101; 41 static constexpr int BG_LIGHT_GREEN = 102; 42 static constexpr int BG_LIGHT_YELLOW = 103; 43 static constexpr int BG_LIGHT_BLUE = 104; 44 static constexpr int BG_LIGHT_MAGENTA = 105; 45 static constexpr int BG_LIGHT_CYAN = 106; 46 static constexpr int BG_WHITE = 107; 47 }; 48 49 class Color { 50 int code; 51 public: Color(int pCode)52 Color(int pCode) : code(pCode) {} operator <<(std::ostream & os,const Color & mod)53 friend std::ostream& operator<<(std::ostream& os, const Color& mod) { 54 return os << "\033[" << mod.code << "m"; 55 } 56 }; 57 58 } // namespace sw::universal 59 60