123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293(* used to be called common_extra.ml *)(*
* How to use it ? ex in LFS:
* Console.progress (w.prop_iprop#length) (fun k ->
* w.prop_iprop#iter (fun (p, ip) ->
* k ();
* ...
* ));
*
* todo: Unix.isatty, and the spinner trick of jason \ | / -
*)letexecute_and_show_progress~showlenf=let_count=ref0in(* kind of continuation passed to f *)letcontinue_pourcentage()=incr_count;ANSITerminal.set_cursor1(-1);ANSITerminal.printf[]"%d / %d"!_countlen;flushstdout;inletnothing()=()in(* ANSITerminal.printf [] "0 / %d" len; flush stdout; *)(if!Common2._batch_mode||notshowthenfnothingelsefcontinue_pourcentage);Common.pr2""letexecute_and_show_progress2?(show=true)lenf=let_count=ref0in(* kind of continuation passed to f *)letcontinue_pourcentage()=incr_count;ANSITerminal.set_cursor1(-1);ANSITerminal.printf[]"%d / %d"!_countlen;flushstdout;inletnothing()=()in(* ANSITerminal.printf [] "0 / %d" len; flush stdout; *)if!Common2._batch_mode||notshowthenfnothingelsefcontinue_pourcentageletwith_progress_list_metter?showfkxs=letlen=List.lengthxsinexecute_and_show_progress2?showlen(funk->fkkxs)letprogress?showfkxs=with_progress_list_metter?showfkxs(*
(* old code
let ansi_terminal = ref true *)
let (_execute_and_show_progress_func:
(show:bool ->
int (* length *) -> ((unit -> unit) -> 'a) -> 'a) ref)
= ref
(fun ~show a b ->
failwith "no execute yet, have you included common_extra.cmo?"
)
let execute_and_show_progress ?(show=true) len f =
!_execute_and_show_progress_func ~show len f
(* don't forget to call Common_extra.set_link () *)
val _execute_and_show_progress_func :
(show:bool -> int (* length *) -> ((unit -> unit) -> unit) -> unit)
ref
val execute_and_show_progress :
?show:bool -> int (* length *) -> ((unit -> unit) -> unit) -> unit
let set_link () =
Common2._execute_and_show_progress_func := execute_and_show_progress
let _init_execute =
set_link ()
*)(* now in common_extra.ml:
* let execute_and_show_progress len f = ...
*)