diff options
author | Roy Marples <roy@marples.name> | 2007-12-03 16:16:08 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-12-03 16:16:08 +0000 |
commit | 52b6cd1c9be5b7c4c0ed16c69239ae2c6839fba0 (patch) | |
tree | 6f3fe10ef31b70c266fe6e550d4c92a7b359f3d5 /src/libeinfo.c | |
parent | 82f7dae3e81a4054464bee42b49f1d872c7ca63d (diff) |
As ecolor does not take a tty, try and guess a valid one.
Diffstat (limited to 'src/libeinfo.c')
-rw-r--r-- | src/libeinfo.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libeinfo.c b/src/libeinfo.c index 9561028e..fdbf18bf 100644 --- a/src/libeinfo.c +++ b/src/libeinfo.c @@ -286,7 +286,7 @@ static const char *_ecolor (FILE *f, einfo_color_t color) if (! colour_terminal (f)) return (""); - + switch (color) { case ECOLOR_GOOD: if (! (col = getenv ("ECOLOR_GOOD"))) @@ -319,7 +319,19 @@ hidden_def(ecolor) const char *ecolor (einfo_color_t color) { - return (_ecolor (stdout, color)); + FILE *f = stdout; + + /* Try and guess a valid tty */ + if (! isatty (fileno (f))) { + f = stderr; + if (! isatty (fileno (f))) { + f = stdin; + if (! isatty (fileno (f))) + f = NULL; + } + } + + return (_ecolor (f, color)); } #define EINFOVN(_file, _color) \ |