aboutsummaryrefslogtreecommitdiff
path: root/lib/helpers/console.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2024-03-14 08:26:58 +0100
committerSébastien Dailly <sebastien@dailly.me>2024-03-14 08:26:58 +0100
commit6b377719c10d5ab3343fd5221f99a4a21008e25a (patch)
treea7c1e9a820d339a2f161af3e09cf9e3161286796 /lib/helpers/console.ml
Initial commitmain
Diffstat (limited to 'lib/helpers/console.ml')
-rw-r--r--lib/helpers/console.ml16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/helpers/console.ml b/lib/helpers/console.ml
new file mode 100644
index 0000000..838b25a
--- /dev/null
+++ b/lib/helpers/console.ml
@@ -0,0 +1,16 @@
+let cursors = [| '|'; '/'; '-'; '\\' |]
+let pos = ref 0
+
+let update_cursor () =
+ if Unix.(isatty stdout) then (
+ Printf.printf "%c[?25l%c[1D%c[0K%c" (char_of_int 27) (char_of_int 27)
+ (char_of_int 27) (Array.get cursors !pos);
+ pos := (!pos + 1) mod Array.length cursors)
+
+let close_cursor () =
+ if Unix.(isatty stdout) then
+ Printf.printf "%c[?25h%c[1D%c[0K\n%!" (char_of_int 27) (char_of_int 27)
+ (char_of_int 27)
+
+let clear_line () =
+ if Unix.(isatty stdout) then Printf.printf "%c[2K\r%!" (char_of_int 27)