@ -7,7 +7,6 @@
open ! IStd
open ! IStd
module F = Format
module F = Format
module L = Logging
(* * {2 arbitrary constants } *)
(* * {2 arbitrary constants } *)
@ -35,7 +34,7 @@ type multiline_info =
type t =
type t =
| MultiLine of multiline_info (* * interactive *)
| MultiLine of multiline_info (* * interactive *)
| NonInteractive (* * display terse progress, to use when output is redirected *)
| NonInteractive (* * display terse progress, to use when output is redirected *)
| Dummy (* * ignore everything *)
| Quiet (* * ignore everything *)
(* * print [c] [n] times *)
(* * print [c] [n] times *)
let rec pp_n c fmt n =
let rec pp_n c fmt n =
@ -123,10 +122,15 @@ let refresh_multiline task_bar =
()
()
let refresh = function MultiLine t -> refresh_multiline t | NonInteractive | Dummy -> ()
let refresh = function MultiLine t -> refresh_multiline t | NonInteractive | Quiet -> ()
let create_multiline ~ jobs =
let create ~ jobs =
if Unix . ( isatty stdin ) && Unix . ( isatty stderr ) then (
match Config . progress_bar with
| ` Quiet ->
Quiet
| ` Plain ->
NonInteractive
| ` MultiLine ->
let t0 = Mtime_clock . now () in
let t0 = Mtime_clock . now () in
let task_bar =
let task_bar =
{ jobs
{ jobs
@ -136,12 +140,9 @@ let create_multiline ~jobs =
; tasks_done = 0
; tasks_done = 0
; tasks_total = 0 }
; tasks_total = 0 }
in
in
ANSITerminal . erase Below ; MultiLine task_bar )
ANSITerminal . erase Below ; MultiLine task_bar
else NonInteractive
let create_dummy () = Dummy
let update_status_multiline task_bar ~ slot : job t0 status =
let update_status_multiline task_bar ~ slot : job t0 status =
( task_bar . jobs_statuses ) . ( job ) <- status ;
( task_bar . jobs_statuses ) . ( job ) <- status ;
( task_bar . jobs_start_times ) . ( job ) <- t0 ;
( task_bar . jobs_start_times ) . ( job ) <- t0 ;
@ -152,7 +153,7 @@ let update_status task_bar ~slot t0 status =
match task_bar with
match task_bar with
| MultiLine t ->
| MultiLine t ->
update_status_multiline t ~ slot t0 status
update_status_multiline t ~ slot t0 status
| NonInteractive | Dummy ->
| NonInteractive | Quiet ->
()
()
@ -160,7 +161,7 @@ let set_tasks_total task_bar n =
match task_bar with
match task_bar with
| MultiLine multiline ->
| MultiLine multiline ->
multiline . tasks_total <- n
multiline . tasks_total <- n
| NonInteractive | Dummy ->
| NonInteractive | Quiet ->
()
()
@ -168,9 +169,7 @@ let tasks_done_add task_bar n =
match task_bar with
match task_bar with
| MultiLine multiline ->
| MultiLine multiline ->
multiline . tasks_done <- multiline . tasks_done + n
multiline . tasks_done <- multiline . tasks_done + n
| NonInteractive ->
| NonInteractive | Quiet ->
L . progress " #%! "
| Dummy ->
()
()
@ -178,7 +177,7 @@ let tasks_done_reset task_bar =
match task_bar with
match task_bar with
| MultiLine multiline ->
| MultiLine multiline ->
multiline . tasks_done <- 0
multiline . tasks_done <- 0
| NonInteractive | Dummy ->
| NonInteractive | Quiet ->
()
()
@ -188,8 +187,8 @@ let finish = function
Out_channel . output_string stderr " \n " ;
Out_channel . output_string stderr " \n " ;
ANSITerminal . erase Below ;
ANSITerminal . erase Below ;
Out_channel . flush stderr
Out_channel . flush stderr
| NonInteractive | Dummy ->
| NonInteractive | Quiet ->
()
()
let is_interactive = function MultiLine _ -> true | NonInteractive | Dummy -> false
let is_interactive = function MultiLine _ -> true | NonInteractive | Quiet -> false