From: Siraaj Khandkar Date: Sat, 28 Sep 2013 17:12:14 +0000 (-0400) Subject: Reset cursor position before printing each grid. X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;ds=inline;h=21c4909c309089428292ce2850f2d4751da5634d;p=cellular-automata.git Reset cursor position before printing each grid. --- diff --git a/polymorphism/001/src/polymorphism.ml b/polymorphism/001/src/polymorphism.ml index c52df93..af46bc5 100644 --- a/polymorphism/001/src/polymorphism.ml +++ b/polymorphism/001/src/polymorphism.ml @@ -197,6 +197,21 @@ module Conway : RULE = struct end +module Terminal : sig + val clear : unit -> unit + val reset : unit -> unit +end = struct + let ansi_code_clear = "\027[2J" (* Clear screen *) + let ansi_code_reset = "\027[1;1H" (* Reset cursor position *) + + let clear () = + print_string ansi_code_clear + + let reset () = + print_string ansi_code_reset +end + + module Automaton : sig type t @@ -227,6 +242,7 @@ end = struct ; data = Rule.create () } in + Terminal.clear (); { grid = Matrix.map ~f:init (Matrix.create ~rs ~ks ()) ; interval = Time.Span.of_float interval ; bar = String.make ks '-' @@ -236,6 +252,7 @@ end = struct cell.data.Cell.pheno let print t = + Terminal.reset (); print_endline t.bar; Matrix.print t.grid ~to_string:cell_to_string; print_endline t.bar