mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
resize: Move isatty_stdout function to separate module (TTY.isatty_stdout).
It was jammed into the Progress module just for convenience. (cherry picked from commitb56990ddf8) (cherry picked from commit93daf42b52)
This commit is contained in:
@@ -220,6 +220,7 @@ python/guestfs-py.c
|
||||
rescue/test-virt-rescue.pl
|
||||
rescue/virt-rescue.c
|
||||
resize/progress-c.c
|
||||
resize/tty-c.c
|
||||
ruby/ext/guestfs/_guestfs.c
|
||||
src/actions-0.c
|
||||
src/actions-1.c
|
||||
|
||||
@@ -3,6 +3,7 @@ resize/common_utils.ml
|
||||
resize/common_utils_tests.ml
|
||||
resize/progress.ml
|
||||
resize/resize.ml
|
||||
resize/tTY.ml
|
||||
sparsify/sparsify.ml
|
||||
sysprep/firstboot.ml
|
||||
sysprep/main.ml
|
||||
|
||||
@@ -32,16 +32,21 @@ SOURCES = \
|
||||
progress-c.c \
|
||||
progress.mli \
|
||||
progress.ml \
|
||||
resize.ml
|
||||
resize.ml \
|
||||
tty-c.c \
|
||||
tTY.mli \
|
||||
tTY.ml
|
||||
|
||||
if HAVE_OCAML
|
||||
|
||||
# Note this list must be in dependency order.
|
||||
OBJECTS = \
|
||||
$(top_builddir)/fish/guestfish-progress.o \
|
||||
tty-c.o \
|
||||
progress-c.o \
|
||||
common_gettext.cmx \
|
||||
common_utils.cmx \
|
||||
tTY.cmx \
|
||||
progress.cmx \
|
||||
resize.cmx
|
||||
|
||||
|
||||
@@ -104,12 +104,3 @@ 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);
|
||||
}
|
||||
|
||||
@@ -28,13 +28,12 @@ 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 || TTY.isatty_stdout () then (
|
||||
(* Initialize the C mini library. *)
|
||||
let bar = progress_bar_init ~machine_readable in
|
||||
|
||||
|
||||
19
resize/tTY.ml
Normal file
19
resize/tTY.ml
Normal file
@@ -0,0 +1,19 @@
|
||||
(* virt-resize
|
||||
* Copyright (C) 2013 Red Hat Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
external isatty_stdout : unit -> bool = "virt_resize_isatty_stdout"
|
||||
23
resize/tTY.mli
Normal file
23
resize/tTY.mli
Normal file
@@ -0,0 +1,23 @@
|
||||
(* virt-resize
|
||||
* Copyright (C) 2013 Red Hat Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
(** TTY utilities. *)
|
||||
|
||||
val isatty_stdout : unit -> bool
|
||||
(** RHEL 5-era ocaml didn't have Unix.isatty. This is not needed in
|
||||
recent OCaml. *)
|
||||
35
resize/tty-c.c
Normal file
35
resize/tty-c.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* virt-resize - interface to isatty
|
||||
* Copyright (C) 2013 Red Hat Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <caml/memory.h>
|
||||
#include <caml/mlvalues.h>
|
||||
|
||||
/* 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);
|
||||
}
|
||||
@@ -33,9 +33,11 @@ if HAVE_OCAML
|
||||
# Note this list must be in dependency order.
|
||||
OBJECTS = \
|
||||
$(top_builddir)/fish/guestfish-progress.o \
|
||||
$(top_builddir)/resize/tty-c.o \
|
||||
$(top_builddir)/resize/progress-c.o \
|
||||
$(top_builddir)/resize/common_gettext.cmx \
|
||||
$(top_builddir)/resize/common_utils.cmx \
|
||||
$(top_builddir)/resize/tTY.cmx \
|
||||
$(top_builddir)/resize/progress.cmx \
|
||||
sparsify.cmx
|
||||
|
||||
|
||||
Reference in New Issue
Block a user