bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3] colorize: use isatty module


From: Paolo Bonzini
Subject: [PATCH 1/3] colorize: use isatty module
Date: Tue, 3 Jan 2012 09:28:28 +0100

* bootstrap.conf: Add isatty module.
* gnulib: Update to latest.
* lib/colorize.h: Remove argument from should_colorize.
* lib/ms/colorize.h: Likewise.
* lib/colorize-impl.c: Factor isatty call out of here...
* lib/ms/colorize-impl.c: ... and here...
* src/main.c: ... into here.
---
 bootstrap.conf         |    1 +
 gnulib                 |    2 +-
 lib/colorize-impl.c    |   11 +++--------
 lib/colorize.h         |    2 +-
 lib/ms/colorize-impl.c |   22 +++++++---------------
 lib/ms/colorize.h      |    2 +-
 src/main.c             |    2 +-
 7 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index b02c26b..4aee59a 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -41,6 +41,7 @@ gnupload
 hard-locale
 ignore-value
 intprops
+isatty
 isblank
 isdir
 iswctype
diff --git a/gnulib b/gnulib
index 55c6e4b..464f9e7 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 55c6e4b6fe65fdfd5154228209a5c9828bb8ec9d
+Subproject commit 464f9e7b25ea50440cd453931e18329844023fef
diff --git a/lib/colorize-impl.c b/lib/colorize-impl.c
index b7c0a3f..e9d5c73 100644
--- a/lib/colorize-impl.c
+++ b/lib/colorize-impl.c
@@ -27,13 +27,8 @@
 /* Return non-zero if we should highlight matches in output to file
    descriptor FD.  */
 int
-should_colorize (int fd)
+should_colorize (void)
 {
-  if (! isatty (fd))
-    return 0;
-  else
-    {
-      char const *t = getenv ("TERM");
-      return t && strcmp (t, "dumb") != 0;
-    }
+  char const *t = getenv ("TERM");
+  return t && strcmp (t, "dumb") != 0;
 }
diff --git a/lib/colorize.h b/lib/colorize.h
index 104f7a0..93f3b10 100644
--- a/lib/colorize.h
+++ b/lib/colorize.h
@@ -19,7 +19,7 @@
 #include <stdio.h>
 
 static inline void init_colorize (void) { }
-extern int should_colorize (int);
+extern int should_colorize (void);
 
 /* Start a colorized text attribute on stdout using the SGR_START
    format; the attribute is specified by SGR_SEQ.  */
diff --git a/lib/ms/colorize-impl.c b/lib/ms/colorize-impl.c
index d9d9b95..7341fe2 100644
--- a/lib/ms/colorize-impl.c
+++ b/lib/ms/colorize-impl.c
@@ -49,22 +49,14 @@ init_colorize (void)
 
 /* Return non-zero if we should highlight matches in output.  */
 int
-should_colorize (int fd)
+should_colorize (void)
 {
-  if (! isatty (fd))
-    return 0;
-  /* Windows isatty returns non-zero for the null device too.  */
-  else if (lseek (fd, SEEK_CUR, 0) != -1)
-    return 0;
-  else
-    {
-      /* $TERM is not normally defined on DOS/Windows, so don't require
-         it for highlighting.  But some programs, like Emacs, do define
-         it when running Grep as a subprocess, so make sure they don't
-         set TERM=dumb.  */
-      char const *t = getenv ("TERM");
-      return ! (t && strcmp (t, "dumb") == 0);
-    }
+  /* $TERM is not normally defined on DOS/Windows, so don't require
+     it for highlighting.  But some programs, like Emacs, do define
+     it when running Grep as a subprocess, so make sure they don't
+     set TERM=dumb.  */
+  char const *t = getenv ("TERM");
+  return ! (t && strcmp (t, "dumb") == 0);
 }
 
 /* Convert a color spec, a semi-colon separated list of the form
diff --git a/lib/ms/colorize.h b/lib/ms/colorize.h
index c49657d..bb94e76 100644
--- a/lib/ms/colorize.h
+++ b/lib/ms/colorize.h
@@ -1,4 +1,4 @@
 extern void colorize_init (void);
-extern int should_colorize (int);
+extern int should_colorize (void);
 extern void print_start_colorize (char const *, char const *);
 extern void print_end_colorize (char const *);
diff --git a/src/main.c b/src/main.c
index 8ad84f4..a768d36 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2132,7 +2132,7 @@ main (int argc, char **argv)
       }
 
   if (color_option == 2)
-    color_option = should_colorize (STDOUT_FILENO);
+    color_option = isatty (STDOUT_FILENO) && should_colorize ();
   init_colorize ();
 
   /* POSIX.2 says that -q overrides -l, which in turn overrides the
-- 
1.7.7.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]