Last active
August 14, 2021 03:57
-
-
Save hellojukay/808262b788a86607cc788d747c8f87de to your computer and use it in GitHub Desktop.
OCaml print with color
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
module Log = struct | |
type color = Black | Red | Green | Yellow | Blue | Magenta | Cyan | White | |
let log_with_color c text = | |
match c with | |
| Black -> Printf.printf "\027[38;5;%dm%s\027[0m" 0 text | |
| Red -> Printf.printf "\027[38;5;%dm%s\027[0m" 1 text | |
| Green -> Printf.printf "\027[38;5;%dm%s\027[0m" 2 text | |
| Yellow -> Printf.printf "\027[38;5;%dm%s\027[0m" 3 text | |
| Blue -> Printf.printf "\027[38;5;%dm%s\027[0m" 4 text | |
| Magenta -> Printf.printf "\027[38;5;%dm%s\027[0m" 5 text | |
| Cyan -> Printf.printf "\027[38;5;%dm%s\027[0m" 6 text | |
| White -> Printf.printf "\027[38;5;%dm%s\027[0m" 7 text | |
end | |
let () = | |
Log.log_with_color Log.Red "hello world\n"; | |
Log.log_with_color Log.Green "Hello World\n"; | |
Log.log_with_color Log.Yellow "Hello World\n"; | |
Log.log_with_color Log.Blue "Hello World\n"; | |
Log.log_with_color Log.Cyan "Hello World\n"; | |
Log.log_with_color Log.Magenta "Hello World\n" |
Author
hellojukay
commented
Aug 14, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment