From 5835b73456898c7bd48d3ed9ec2539c1b560f9b8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 9 Dec 2018 20:59:11 +0100 Subject: sidparse: flush linewise when run interactively MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide immediate feedback on stdout when running in an interactive terminal the assumption being we’re dealing with a human. --- util/sidparse.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/sidparse.ml b/util/sidparse.ml index 8027692..0440751 100644 --- a/util/sidparse.ml +++ b/util/sidparse.ml @@ -1,5 +1,7 @@ (* SPDX-License-Identifier: LGPL-3.0-only WITH OCaml-LGPL-linking-exception *) +let interactive = Unix.(isatty stdin) + let err q v = match q, v with | true, _ -> Printf.ifprintf stdout @@ -61,6 +63,7 @@ let traverse q v next = | `Done s -> begin if n = 0 then header q v; emit q v s; + if interactive then flush_all (); aux (n + 1) ne end end @@ -71,7 +74,7 @@ let sidparse validate quiet args = let next = match args with | [] -> begin - if Unix.(isatty stdin) then + if interactive then err quiet validate "reading input from stdin\n%!"; from_stdin end -- cgit v1.2.3