Created
June 27, 2021 07:04
-
-
Save hellojukay/595f6b14dfb11cd45bb57d9c11ba7143 to your computer and use it in GitHub Desktop.
progress bar write in Ocaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
#load "unix.cma" | |
let rec repeat str n = | |
match n with 0 -> str | 1 -> str | n -> str ^ repeat str (n - 1) | |
let () = | |
let sum = ref 1 in | |
while true do | |
Printf.printf "[%d%%]%s" !sum (repeat "#" !sum); | |
flush stdout; | |
Unix.sleepf 0.03; | |
Printf.printf "%s" "\r"; | |
Printf.printf "%s" (repeat " " 110); | |
Printf.printf "%s" "\r"; | |
flush stdout; | |
if !sum == 100 then sum := 0; | |
sum := !sum + 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment