summaryrefslogtreecommitdiff
path: root/src/kahn_stdio.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-05-25 12:29:07 +0200
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-05-25 12:29:07 +0200
commit60ba54ffe01be85ec6f1d6948c1ca4b6db1cf165 (patch)
treec52b747b196e8183470efbe9ccb66779cb34b6c5 /src/kahn_stdio.ml
parenta3fc292095c9e29046c737c4164beab2faadc035 (diff)
downloadSystemeReseaux-Projet-60ba54ffe01be85ec6f1d6948c1ca4b6db1cf165.tar.gz
SystemeReseaux-Projet-60ba54ffe01be85ec6f1d6948c1ca4b6db1cf165.zip
Add pretty colors.
Diffstat (limited to 'src/kahn_stdio.ml')
-rw-r--r--src/kahn_stdio.ml20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/kahn_stdio.ml b/src/kahn_stdio.ml
index 234c1d4..1bed0a1 100644
--- a/src/kahn_stdio.ml
+++ b/src/kahn_stdio.ml
@@ -79,6 +79,7 @@ module ProtoKahn: S = struct
let origin = ref false
let dbg_out = ref false
+ let color = ref 0
let dbg x = if !dbg_out then Format.eprintf "(cli) %s@." x
let parse_args () =
@@ -86,12 +87,21 @@ module ProtoKahn: S = struct
let options = [
"-org", Arg.Set origin, "Launch root process";
"-dbg", Arg.Set dbg_out, "Show debug output";
+ "-col", Arg.Set_int color, "Color for output";
] in
Arg.parse options (fun _ -> assert false) usage
let run proc =
- Random.self_init();
parse_args();
+
+ Random.self_init();
+ let color =
+ if !color = 0
+ then Random.int 6 + 31
+ else 30 + !color in
+ let cseq = Format.sprintf "\x1B[%dm" color in
+ let ncseq = "\x1B[0m" in
+
(* Initialize protocol *)
send Hello;
if read () <> Hello then raise (ProtocolError "Server did not say Hello correctly.");
@@ -107,15 +117,15 @@ module ProtoKahn: S = struct
| GiveTask(td, _) ->
dbg "Got task!";
let t : task = Marshal.from_string td 0 in
- Format.eprintf "[@?";
+ Format.eprintf "%s[%s@?" cseq ncseq;
t();
- Format.eprintf "]@?";
+ Format.eprintf "%s]%s@?" cseq ncseq;
| GiveMsgTask(msg, td) ->
dbg "Got msg task!";
let t : msg_task = Marshal.from_string td 0 in
- Format.eprintf "{@?";
+ Format.eprintf "%s{%s@?" cseq ncseq;
t msg;
- Format.eprintf "}@?";
+ Format.eprintf "%s}%s@?" cseq ncseq;
| FinalResult(x) ->
dbg "Got result!";
result := Some (Marshal.from_string x 0)