summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util.ml b/src/util.ml
index 5e5654d1..f9603f8e 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -465,3 +465,14 @@ let log_line str line msg =
"\n[" ^ (str ^ ":" ^ string_of_int line |> blue |> clear) ^ "] " ^ msg
let header str n = "\n" ^ str ^ "\n" ^ String.make (String.length str - 9 * n) '='
+
+let progress n total =
+ let len = truncate ((float n /. float total) *. 50.0) in
+ let percent = truncate ((float n /. float total) *. 100.0) in
+ let str = "[" ^ String.make len '=' ^ String.make (50 - len) ' ' ^ "] " ^ string_of_int percent ^ "%" in
+ prerr_string str;
+ if n = total then
+ prerr_char '\n'
+ else
+ prerr_string ("\x1B[" ^ string_of_int (String.length str) ^ "D");
+ flush stderr