Skip to content

Commit 21ef9c1

Browse files
fix(color): make CI opt in to colored output (FORCE_COLOR)
- Added `FORCE_COLOR` so CI can explicitly enable color, since it fails the `isatty` check by default. Signed-off-by: Shashwat Agrawal <shashwatagrawal473@gmail.com>
1 parent c48e064 commit 21ef9c1

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
env:
99
TERM: xterm-256color
10+
FORCE_COLOR: 1
1011

1112
jobs:
1213
test:

tec.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -619,17 +619,22 @@ void tec_init_prefixes(void) {
619619
}
620620

621621
void _tec_detect_color_support(void) {
622-
if (tec_context.options.no_color && tec_context.options.use_ascii) {
623-
return;
624-
}
625-
626-
const char *term = getenv("TERM");
627-
if ((getenv("NO_COLOR") != NULL) || (!isatty(STDOUT_FILENO)) ||
628-
(!term || term[0] == '\0' || strcmp(term, "dumb") == 0)) {
629-
tec_context.options.no_color = true;
630-
tec_context.options.use_ascii = true;
631-
return;
622+
bool want_color;
623+
if (getenv("NO_COLOR") != NULL) {
624+
want_color = false;
625+
} else if (getenv("FORCE_COLOR") != NULL) {
626+
want_color = true;
627+
} else {
628+
want_color = isatty(STDOUT_FILENO);
629+
if (want_color) {
630+
const char *term = getenv("TERM");
631+
if (!term || !*term || strcmp(term, "dumb") == 0) {
632+
want_color = false;
633+
}
634+
}
632635
}
636+
tec_context.options.no_color = !want_color;
637+
tec_context.options.use_ascii = !want_color;
633638
}
634639

635640
void TEC_POST_FAIL(void) {

0 commit comments

Comments
 (0)