1 /* 2 * Copyright (C) Tildeslash Ltd. All rights reserved. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Affero General Public License version 3. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU Affero General Public License for more details. 11 * 12 * You should have received a copy of the GNU Affero General Public License 13 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * 15 * In addition, as a special exception, the copyright holders give 16 * permission to link the code of portions of this program with the 17 * OpenSSL library under certain conditions as described in each 18 * individual source file, and distribute linked combinations 19 * including the two. 20 * 21 * You must obey the GNU Affero General Public License in all respects 22 * for all of the code used other than OpenSSL. 23 */ 24 25 26 #ifndef TEXTCOLOR_INCLUDED 27 #define TEXTCOLOR_INCLUDED 28 29 30 /** 31 * Class for terminal color output. 32 * 33 * @author http://www.tildeslash.com/ 34 * @see http://www.mmonit.com/ 35 * @file 36 */ 37 38 39 #define COLOR_RESET "\033[0m" 40 #define COLOR_BOLD "\033[1m" 41 42 #define COLOR_BLACK "\033[0;30m" 43 #define COLOR_RED "\033[0;31m" 44 #define COLOR_GREEN "\033[0;32m" 45 #define COLOR_YELLOW "\033[0;33m" 46 #define COLOR_BLUE "\033[0;34m" 47 #define COLOR_MAGENTA "\033[0;35m" 48 #define COLOR_CYAN "\033[0;36m" 49 #define COLOR_WHITE "\033[0;37m" 50 #define COLOR_DEFAULT "\033[0;39m" 51 52 #define COLOR_BOLDBLACK "\033[1;30m" 53 #define COLOR_BOLDRED "\033[1;31m" 54 #define COLOR_BOLDGREEN "\033[1;32m" 55 #define COLOR_BOLDYELLOW "\033[1;33m" 56 #define COLOR_BOLDBLUE "\033[1;34m" 57 #define COLOR_BOLDMAGENTA "\033[1;35m" 58 #define COLOR_BOLDCYAN "\033[1;36m" 59 #define COLOR_BOLDWHITE "\033[1;37m" 60 61 #define COLOR_DARKGRAY "\033[0;90m" 62 #define COLOR_LIGHTRED "\033[0;91m" 63 #define COLOR_LIGHTGREEN "\033[0;92m" 64 #define COLOR_LIGHTYELLOW "\033[0;93m" 65 #define COLOR_LIGHTBLUE "\033[0;94m" 66 #define COLOR_LIGHTMAGENTA "\033[0;95m" 67 #define COLOR_LIGHTCYAN "\033[0;96m" 68 #define COLOR_LIGHTWHITE "\033[0;97m" 69 70 71 #define TextColor_black(format, ...) COLOR_BLACK format COLOR_RESET, ##__VA_ARGS__ 72 #define TextColor_red(format, ...) COLOR_RED format COLOR_RESET, ##__VA_ARGS__ 73 #define TextColor_green(format, ...) COLOR_GREEN format COLOR_RESET, ##__VA_ARGS__ 74 #define TextColor_yellow(format, ...) COLOR_YELLOW format COLOR_RESET, ##__VA_ARGS__ 75 #define TextColor_blue(format, ...) COLOR_BLUE format COLOR_RESET, ##__VA_ARGS__ 76 #define TextColor_magenta(format, ...) COLOR_MAGENTA format COLOR_RESET, ##__VA_ARGS__ 77 #define TextColor_cyan(format, ...) COLOR_CYAN format COLOR_RESET, ##__VA_ARGS__ 78 #define TextColor_white(format, ...) COLOR_WHITE format COLOR_RESET, ##__VA_ARGS__ 79 #define TextColor_boldBlack(format, ...) COLOR_BOLDBLACK format COLOR_RESET, ##__VA_ARGS__ 80 #define TextColor_boldRed(format, ...) COLOR_BOLDRED format COLOR_RESET, ##__VA_ARGS__ 81 #define TextColor_boldGreen(format, ...) COLOR_BOLDGREEN format COLOR_RESET, ##__VA_ARGS__ 82 #define TextColor_boldYellow(format, ...) COLOR_BOLDYELLOW format COLOR_RESET, ##__VA_ARGS__ 83 #define TextColor_boldBlue(format, ...) COLOR_BOLDBLUE format COLOR_RESET, ##__VA_ARGS__ 84 #define TextColor_boldMagenta(format, ...) COLOR_BOLDMAGENTA format COLOR_RESET, ##__VA_ARGS__ 85 #define TextColor_boldCyan(format, ...) COLOR_BOLDCYAN format COLOR_RESET, ##__VA_ARGS__ 86 #define TextColor_boldWhite(format, ...) COLOR_BOLDWHITE format COLOR_RESET, ##__VA_ARGS__ 87 #define TextColor_darkGray(format, ...) COLOR_DARKGRAY format COLOR_RESET, ##__VA_ARGS__ 88 #define TextColor_lightRed(format, ...) COLOR_LIGHTRED format COLOR_RESET, ##__VA_ARGS__ 89 #define TextColor_lightGreen(format, ...) COLOR_LIGHTGREEN format COLOR_RESET, ##__VA_ARGS__ 90 #define TextColor_lightYellow(format, ...) COLOR_LIGHTYELLOW format COLOR_RESET, ##__VA_ARGS__ 91 #define TextColor_lightBlue(format, ...) COLOR_LIGHTBLUE format COLOR_RESET, ##__VA_ARGS__ 92 #define TextColor_lightMagenta(format, ...) COLOR_LIGHTMAGENTA format COLOR_RESET, ##__VA_ARGS__ 93 #define TextColor_lightCyan(format, ...) COLOR_LIGHTCYAN format COLOR_RESET, ##__VA_ARGS__ 94 #define TextColor_lightWhite(format, ...) COLOR_LIGHTWHITE format COLOR_RESET, ##__VA_ARGS__ 95 96 /** 97 * Test terminal color support 98 * @return true if colors are supported, otherwise false 99 */ 100 bool TextColor_support(void); 101 102 103 /** 104 * Return length of ANSI color sequences in the string. 105 * @return bytes used by control sequences or 0 if the string has no colors 106 */ 107 int TextColor_length(char *s); 108 109 110 /** 111 * Strip the ANSI color sequences in the string. 112 * Example: 113 * <pre> 114 * char s[] = "\033[31mHello\033[0m"; 115 * Color_strip(s) -> Hello 116 * </pre> 117 * @param s The string to strip 118 * @return A pointer to s 119 */ 120 char *TextColor_strip(char *s); 121 122 123 #endif 124 125