From 479645750e2782b77b97a06cd8142dcfb8d704dd Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Sat, 28 Sep 2013 15:10:38 -0400 Subject: [PATCH] Add terminal color manipulation. --- polymorphism/001/src/polymorphism.ml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index af46bc5..cb65462 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -198,12 +198,30 @@ end module Terminal : sig + type color = [ `green + | `red + ] + + val string_with_color : string -> color -> string + val clear : unit -> unit + val reset : unit -> unit end = struct + type color = [ `green + | `red + ] + let ansi_code_clear = "\027[2J" (* Clear screen *) let ansi_code_reset = "\027[1;1H" (* Reset cursor position *) + let string_of_color = function + | `green -> "\027[0;32m" + | `red -> "\027[1;31m" + + let string_with_color s c = + sprintf "%s%s\027[0m" (string_of_color c) s + let clear () = print_string ansi_code_clear -- 2.20.1