diff options
Diffstat (limited to 'lib/helpers/console.ml')
-rw-r--r-- | lib/helpers/console.ml | 16 |
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) |