[Pkg-libvirt-commits] [libguestfs] 110/116: mllib: check the right out channel for tty

Hilko Bengen bengen at moszumanska.debian.org
Wed Nov 26 22:05:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.29.10-1
in repository libguestfs.

commit 7ce73d898025b07c391d6d66a7aa13314cbc453f
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Tue Nov 25 11:53:11 2014 +0100

    mllib: check the right out channel for tty
    
    Make sure to check whether the given output channel is a tty before
    sending ANSI terminal codes to it, instead of always check what stdout
    is.
---
 mllib/common_utils.ml | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 9fcd8dd..83ebd3a 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -205,17 +205,20 @@ let rec combine3 xs ys zs =
   | x::xs, y::ys, z::zs -> (x, y, z) :: combine3 xs ys zs
   | _ -> invalid_arg "combine3"
 
+let istty chan =
+  Unix.isatty (Unix.descr_of_out_channel chan)
+
 (* ANSI terminal colours. *)
 let ansi_green ?(chan = stdout) () =
-  if Unix.isatty Unix.stdout then output_string chan "\x1b[0;32m"
+  if istty chan then output_string chan "\x1b[0;32m"
 let ansi_red ?(chan = stdout) () =
-  if Unix.isatty Unix.stdout then output_string chan "\x1b[1;31m"
+  if istty chan then output_string chan "\x1b[1;31m"
 let ansi_blue ?(chan = stdout) () =
-  if Unix.isatty Unix.stdout then output_string chan "\x1b[1;34m"
+  if istty chan then output_string chan "\x1b[1;34m"
 let ansi_magenta ?(chan = stdout) () =
-  if Unix.isatty Unix.stdout then output_string chan "\x1b[1;35m"
+  if istty chan then output_string chan "\x1b[1;35m"
 let ansi_restore ?(chan = stdout) () =
-  if Unix.isatty Unix.stdout then output_string chan "\x1b[0m"
+  if istty chan then output_string chan "\x1b[0m"
 
 (* Timestamped progress messages, used for ordinary messages when not
  * --quiet.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list