Skip to content

Commit e763266

Browse files
committed
Honor the NO_COLOR environment variable
Refrain from coloring output if NO_COLOR is defined and has a non-empty value. This is a common convention. Link: https://no-color.org
1 parent 835e2d1 commit e763266

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

simavr/sim/run_avr.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333

3434
#include "sim_core_decl.h"
3535

36+
#ifndef NO_COLOR
37+
/* Replacements for ANSI escape codes if color is disabled. */
38+
static const struct text_colors font_no_color = {
39+
.green = "",
40+
.red = "",
41+
.normal = ""
42+
};
43+
#endif
44+
3645
static void
3746
display_usage(
3847
const char * app)
@@ -111,6 +120,12 @@ main(
111120
int trace_vectors_count = 0;
112121
const char *vcd_input = NULL;
113122

123+
#ifndef NO_COLOR
124+
const char *no_color = getenv("NO_COLOR");
125+
if (no_color && no_color[0])
126+
simavr_font = font_no_color;
127+
#endif
128+
114129
if (argc == 1)
115130
display_usage(basename(argv[0]));
116131

0 commit comments

Comments
 (0)