Gyoto
GyotoAnsi.h
1 /*
2  Copyright 2026 Thibaut Paumard
3 
4  This file is part of Gyoto.
5 
6  Gyoto is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Gyoto is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
64 #ifndef __GyotoAnsi_H_
65 #define __GyotoAnsi_H_
66 
67 #include <ostream>
68 
69 // ============================================================================
70 // RESET TO DEFAULT
71 // ============================================================================
72 
74 #define GYOTO_ANSI_RESET "\033[0m"
75 
76 // ============================================================================
77 // FOREGROUND COLORS (Standard: 30-37)
78 // ============================================================================
79 
81 #define GYOTO_ANSI_FG_BLACK "\033[30m"
82 #define GYOTO_ANSI_FG_RED "\033[31m"
84 #define GYOTO_ANSI_FG_GREEN "\033[32m"
86 #define GYOTO_ANSI_FG_YELLOW "\033[33m"
88 #define GYOTO_ANSI_FG_BLUE "\033[34m"
90 #define GYOTO_ANSI_FG_MAGENTA "\033[35m"
92 #define GYOTO_ANSI_FG_CYAN "\033[36m"
94 #define GYOTO_ANSI_FG_WHITE "\033[37m"
96 
97 // ============================================================================
98 // FOREGROUND COLORS (Bright: 90-97)
99 // ============================================================================
100 
102 #define GYOTO_ANSI_FG_BRIGHT_BLACK "\033[90m"
103 #define GYOTO_ANSI_FG_BRIGHT_RED "\033[91m"
105 #define GYOTO_ANSI_FG_BRIGHT_GREEN "\033[92m"
107 #define GYOTO_ANSI_FG_BRIGHT_YELLOW "\033[93m"
109 #define GYOTO_ANSI_FG_BRIGHT_BLUE "\033[94m"
111 #define GYOTO_ANSI_FG_BRIGHT_MAGENTA "\033[95m"
113 #define GYOTO_ANSI_FG_BRIGHT_CYAN "\033[96m"
115 #define GYOTO_ANSI_FG_BRIGHT_WHITE "\033[97m"
117 
118 // ============================================================================
119 // BACKGROUND COLORS (Standard: 40-47)
120 // ============================================================================
121 
123 #define GYOTO_ANSI_BG_BLACK "\033[40m"
124 #define GYOTO_ANSI_BG_RED "\033[41m"
126 #define GYOTO_ANSI_BG_GREEN "\033[42m"
128 #define GYOTO_ANSI_BG_YELLOW "\033[43m"
130 #define GYOTO_ANSI_BG_BLUE "\033[44m"
132 #define GYOTO_ANSI_BG_MAGENTA "\033[45m"
134 #define GYOTO_ANSI_BG_CYAN "\033[46m"
136 #define GYOTO_ANSI_BG_WHITE "\033[47m"
138 
139 // ============================================================================
140 // BACKGROUND COLORS (Bright: 100-107)
141 // ============================================================================
142 
144 #define GYOTO_ANSI_BG_BRIGHT_BLACK "\033[100m"
145 #define GYOTO_ANSI_BG_BRIGHT_RED "\033[101m"
147 #define GYOTO_ANSI_BG_BRIGHT_GREEN "\033[102m"
149 #define GYOTO_ANSI_BG_BRIGHT_YELLOW "\033[103m"
151 #define GYOTO_ANSI_BG_BRIGHT_BLUE "\033[104m"
153 #define GYOTO_ANSI_BG_BRIGHT_MAGENTA "\033[105m"
155 #define GYOTO_ANSI_BG_BRIGHT_CYAN "\033[106m"
157 #define GYOTO_ANSI_BG_BRIGHT_WHITE "\033[107m"
159 
160 // ============================================================================
161 // TEXT ATTRIBUTES
162 // ============================================================================
163 
165 #define GYOTO_ANSI_BOLD "\033[1m"
166 #define GYOTO_ANSI_BOLD_OFF "\033[22m"
168 
170 #define GYOTO_ANSI_DIM "\033[2m"
171 #define GYOTO_ANSI_DIM_OFF "\033[22m"
173 
175 #define GYOTO_ANSI_ITALIC "\033[3m"
176 #define GYOTO_ANSI_ITALIC_OFF "\033[23m"
178 
180 #define GYOTO_ANSI_UNDERLINE "\033[4m"
181 #define GYOTO_ANSI_UNDERLINE_OFF "\033[24m"
183 
185 #define GYOTO_ANSI_BLINK "\033[5m"
186 #define GYOTO_ANSI_BLINK_OFF "\033[25m"
188 
190 #define GYOTO_ANSI_REVERSE "\033[7m"
191 #define GYOTO_ANSI_REVERSE_OFF "\033[27m"
193 
195 #define GYOTO_ANSI_HIDDEN "\033[8m"
196 #define GYOTO_ANSI_HIDDEN_OFF "\033[28m"
198 
200 #define GYOTO_ANSI_STRIKETHROUGH "\033[9m"
201 #define GYOTO_ANSI_STRIKETHROUGH_OFF "\033[29m"
203 
204 // ============================================================================
205 // COMBINED FORMATTING (Common use cases)
206 // ============================================================================
207 
209 #define GYOTO_ANSI_SEVERE_TAG \
210  GYOTO_ANSI_RESET GYOTO_ANSI_BOLD GYOTO_ANSI_FG_BRIGHT_RED
211 #define GYOTO_ANSI_SEVERE \
213  GYOTO_ANSI_RESET GYOTO_ANSI_FG_RED
214 #define GYOTO_ANSI_WARNING_TAG \
216  GYOTO_ANSI_RESET GYOTO_ANSI_BOLD GYOTO_ANSI_FG_BRIGHT_YELLOW
217 #define GYOTO_ANSI_WARNING GYOTO_ANSI_RESET GYOTO_ANSI_FG_YELLOW
219 #define GYOTO_ANSI_INFO_TAG \
221  GYOTO_ANSI_RESET GYOTO_ANSI_BOLD GYOTO_ANSI_FG_BRIGHT_GREEN
222 #define GYOTO_ANSI_INFO GYOTO_ANSI_RESET GYOTO_ANSI_FG_GREEN
224 
226 #define GYOTO_ANSI_DEBUG_TAG \
227  GYOTO_ANSI_RESET GYOTO_ANSI_BOLD GYOTO_ANSI_FG_BRIGHT_BLUE
228 
230 #define GYOTO_ANSI_DEBUG_PRETTY_FUNCTION \
231  GYOTO_ANSI_RESET GYOTO_ANSI_FG_BRIGHT_CYAN
232 
234 #define GYOTO_ANSI_DEBUG \
235  GYOTO_ANSI_RESET GYOTO_ANSI_FG_BLUE
236 
238 #define GYOTO_ANSI_DEBUG_VALUE \
239  GYOTO_ANSI_RESET GYOTO_ANSI_FG_BRIGHT_YELLOW
240 
242 #define GYOTO_ANSI_DEBUG_VARIABLE \
243  GYOTO_ANSI_RESET GYOTO_ANSI_FG_BRIGHT_MAGENTA
244 
245 namespace Gyoto {
252  class AnsiScope;
253 
254 }
255 
257  std::ostream& stream_;
258  bool reset_;
259 public:
260  AnsiScope(std::ostream& s);
261  ~AnsiScope();
262  void no_reset();
263  static Gyoto::AnsiScope cout();
264  static Gyoto::AnsiScope cerr();
265  void append(std::string txt);
266  template<typename T>
267  AnsiScope& operator<<(const T& value) {
268  stream_ << value;
269  return *this;
270  }
271  AnsiScope& operator<<(std::ostream& (*manip)(std::ostream&));
272  void flush();
273 };
274 #endif
Definition: GyotoAnsi.h:256
Namespace for the Gyoto library.
Definition: GyotoAnsi.h:245