RHEL 5: Replacement for 'Unix.isatty stdout' for old OCaml versions.

Unix.isatty missing on RHEL 5-era OCaml 3.09.3.
This commit is contained in:
Richard W.M. Jones
2013-03-09 19:25:33 +00:00
parent e73944faf4
commit d16bb6b70c
2 changed files with 12 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
#include <caml/alloc.h>
@@ -103,3 +104,12 @@ virt_resize_progress_bar_set (value barv,
CAMLreturn (Val_unit);
}
/* RHEL 5-era ocaml didn't have Unix.isatty. */
value
virt_resize_isatty_stdout (value unitv)
{
CAMLparam1 (unitv);
CAMLreturn (isatty(1) ? Val_true : Val_false);
}

View File

@@ -28,12 +28,13 @@ external progress_bar_reset : progress_bar -> unit
= "virt_resize_progress_bar_reset"
external progress_bar_set : progress_bar -> int64 -> int64 -> unit
= "virt_resize_progress_bar_set"
external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout"
let set_up_progress_bar ?(machine_readable = false) (g : Guestfs.guestfs) =
(* Only display progress bars if the machine_readable flag is set or
* the output is a tty.
*)
if machine_readable || isatty stdout then (
if machine_readable || isatty_stdout () then (
(* Initialize the C mini library. *)
let bar = progress_bar_init ~machine_readable in