forked from
anil.recoil.org/monopam
Monorepo management for opam overlays
1(** Progress reporting for sync operations.
2
3 Provides terminal progress indicators for long-running sync phases.
4
5 Note: For thread-safety during parallel operations, uses an atomic counter
6 that's rendered on each tick. *)
7
8type t = {
9 progress : Tty.Progress.t;
10 completed : int Atomic.t;
11 total : int;
12 phase_name : string;
13}
14
15let v ?ppf ?enabled ~total phase_name =
16 let msg = Fmt.str "%s (0/%d)" phase_name total in
17 let progress = Tty.Progress.v ?ppf ?enabled ~total msg in
18 { progress; completed = Atomic.make 0; total; phase_name }
19
20let tick t name =
21 let n = Atomic.fetch_and_add t.completed 1 + 1 in
22 let msg = Fmt.str "%s (%d/%d)" name n t.total in
23 Tty.Progress.update t.progress ~phase:t.phase_name ~msg
24
25let clear t = Tty.Progress.clear t.progress
26let finish t = Tty.Progress.finish t.progress
27
28(** Module signature for progress implementations *)
29module type S = sig
30 type t
31
32 val v : ?ppf:Format.formatter -> ?enabled:bool -> total:int -> string -> t
33 val tick : t -> string -> unit
34 val clear : t -> unit
35 val finish : t -> unit
36end
37
38(** Active progress with terminal output *)
39module Active : S with type t = t = struct
40 type nonrec t = t
41
42 let v = v
43 let tick = tick
44 let clear = clear
45 let finish = finish
46end
47
48(** Disabled progress (no terminal output) *)
49module Disabled : S with type t = unit = struct
50 type t = unit
51
52 let v ?ppf:_ ?enabled:_ ~total:_ _ = ()
53 let tick () _ = ()
54 let clear () = ()
55 let finish () = ()
56end