Skip to content

Disable color on non-tty output #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Do not use color unless output is a tty
  • Loading branch information
doctaweeks committed Jan 27, 2016
commit fa3e43f3092b3144be2911dfc23dc69bfbf85bc3
7 changes: 4 additions & 3 deletions textcolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>


#if __WIN32__
Expand Down Expand Up @@ -207,7 +208,7 @@ void text_color_init (int enable_color)
g_enable_color = enable_color;


if (g_enable_color == 0) {
if (g_enable_color == 0 || isatty(fileno(stdout)) == 0) {
return;
}
#if __WIN32__
Expand Down Expand Up @@ -250,7 +251,7 @@ void text_color_set ( enum dw_color_e c )
WORD attr;
HANDLE h;

if (g_enable_color == 0) {
if (g_enable_color == 0 || isatty(fileno(stdout)) == 0) {
return;
}

Expand Down Expand Up @@ -294,7 +295,7 @@ void text_color_set ( enum dw_color_e c )
void text_color_set ( enum dw_color_e c )
{

if (g_enable_color == 0) {
if (g_enable_color == 0 || isatty(fileno(stdout)) == 0) {
return;
}

Expand Down