|
25 | 25 | #include <termios.h> |
26 | 26 | #endif |
27 | 27 |
|
28 | | -#define ANSI_COLOR_RED "\x1b[31m" |
29 | | -#define ANSI_COLOR_GREEN "\x1b[32m" |
30 | | -#define ANSI_COLOR_YELLOW "\x1b[33m" |
31 | | -#define ANSI_COLOR_BLUE "\x1b[34m" |
32 | | -#define ANSI_COLOR_MAGENTA "\x1b[35m" |
33 | | -#define ANSI_COLOR_CYAN "\x1b[36m" |
34 | | -#define ANSI_COLOR_RESET "\x1b[0m" |
35 | | -#define ANSI_BOLD "\x1b[1m" |
| 28 | +#define ANSI_COLOR_RED LOG_COL_RED |
| 29 | +#define ANSI_COLOR_GREEN LOG_COL_GREEN |
| 30 | +#define ANSI_COLOR_YELLOW LOG_COL_YELLOW |
| 31 | +#define ANSI_COLOR_BLUE LOG_COL_BLUE |
| 32 | +#define ANSI_COLOR_MAGENTA LOG_COL_MAGENTA |
| 33 | +#define ANSI_COLOR_CYAN LOG_COL_CYAN |
| 34 | +#define ANSI_COLOR_RESET LOG_COL_DEFAULT |
| 35 | +#define ANSI_BOLD LOG_COL_BOLD |
36 | 36 |
|
37 | 37 | namespace console { |
38 | 38 |
|
@@ -143,30 +143,58 @@ namespace console { |
143 | 143 | // Keep track of current display and only emit ANSI code if it changes |
144 | 144 | void set_display(display_t display) { |
145 | 145 | if (advanced_display && current_display != display) { |
146 | | - fflush(stdout); |
147 | | - switch(display) { |
148 | | - case reset: |
149 | | - fprintf(out, ANSI_COLOR_RESET); |
150 | | - break; |
151 | | - case prompt: |
152 | | - fprintf(out, ANSI_COLOR_YELLOW); |
153 | | - break; |
154 | | - case user_input: |
155 | | - fprintf(out, ANSI_BOLD ANSI_COLOR_GREEN); |
156 | | - break; |
157 | | - case error: |
158 | | - fprintf(out, ANSI_BOLD ANSI_COLOR_RED); |
159 | | - break; |
160 | | - case reasoning: |
161 | | - fprintf(out, ANSI_COLOR_BLUE); |
162 | | - break; |
163 | | - } |
164 | 146 | current_display = display; |
165 | | - fflush(out); |
| 147 | + |
| 148 | + if (display == user_input && common_log_is_active(common_log_main())) { |
| 149 | + common_log_flush(common_log_main()); |
| 150 | + } |
| 151 | + |
| 152 | + if (display == user_input || !common_log_is_active(common_log_main())) { |
| 153 | + fflush(stdout); |
| 154 | + switch(display) { |
| 155 | + case reset: |
| 156 | + fprintf(out, ANSI_COLOR_RESET); |
| 157 | + break; |
| 158 | + case prompt: |
| 159 | + fprintf(out, ANSI_COLOR_YELLOW); |
| 160 | + break; |
| 161 | + case user_input: |
| 162 | + fprintf(out, ANSI_BOLD ANSI_COLOR_GREEN); |
| 163 | + break; |
| 164 | + case error: |
| 165 | + fprintf(out, ANSI_BOLD ANSI_COLOR_RED); |
| 166 | + break; |
| 167 | + case reasoning: |
| 168 | + fprintf(out, ANSI_COLOR_BLUE); |
| 169 | + break; |
| 170 | + } |
| 171 | + fflush(out); |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + display_t get_display() { |
| 177 | + return current_display; |
| 178 | + } |
| 179 | + |
| 180 | + const char * get_display_color() { |
| 181 | + switch(current_display) { |
| 182 | + case reset: |
| 183 | + return ANSI_COLOR_RESET; |
| 184 | + case prompt: |
| 185 | + return ANSI_COLOR_YELLOW; |
| 186 | + case user_input: |
| 187 | + return ANSI_BOLD ANSI_COLOR_GREEN; |
| 188 | + case error: |
| 189 | + return ANSI_BOLD ANSI_COLOR_RED; |
| 190 | + case reasoning: |
| 191 | + return ANSI_COLOR_BLUE; |
| 192 | + default: |
| 193 | + return ""; |
166 | 194 | } |
167 | 195 | } |
168 | 196 |
|
169 | | - void write(const char* format, ...) { |
| 197 | + void write_console(const char* format, ...) { |
170 | 198 | va_list args; |
171 | 199 | va_start(args, format); |
172 | 200 | vfprintf(out, format, args); |
|
0 commit comments