Skip to content

Commit fa3e43f

Browse files
committed
Do not use color unless output is a tty
1 parent bce03cd commit fa3e43f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: textcolor.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <stdio.h>
7878
#include <stdlib.h>
7979
#include <stdarg.h>
80+
#include <unistd.h>
8081

8182

8283
#if __WIN32__
@@ -207,7 +208,7 @@ void text_color_init (int enable_color)
207208
g_enable_color = enable_color;
208209

209210

210-
if (g_enable_color == 0) {
211+
if (g_enable_color == 0 || isatty(fileno(stdout)) == 0) {
211212
return;
212213
}
213214
#if __WIN32__
@@ -250,7 +251,7 @@ void text_color_set ( enum dw_color_e c )
250251
WORD attr;
251252
HANDLE h;
252253

253-
if (g_enable_color == 0) {
254+
if (g_enable_color == 0 || isatty(fileno(stdout)) == 0) {
254255
return;
255256
}
256257

@@ -294,7 +295,7 @@ void text_color_set ( enum dw_color_e c )
294295
void text_color_set ( enum dw_color_e c )
295296
{
296297

297-
if (g_enable_color == 0) {
298+
if (g_enable_color == 0 || isatty(fileno(stdout)) == 0) {
298299
return;
299300
}
300301

0 commit comments

Comments
 (0)