Add terminal color manipulation.
authorSiraaj Khandkar <siraaj@khandkar.net>
Sat, 28 Sep 2013 19:10:38 +0000 (15:10 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sat, 28 Sep 2013 19:10:38 +0000 (15:10 -0400)
polymorphism/001/src/polymorphism.ml

index af46bc5..cb65462 100644 (file)
@@ -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
 
This page took 0.027666 seconds and 4 git commands to generate.