Lwd

Experimenting with Lwd

module Ui = Nottui.Ui

let mk_clock (v:float Lwd.t) : Ui.t Lwd.t =
  Lwd.map
    (fun t ->
       Ui.resize ~fill:(Nottui.Gravity.make ~h:`Neutral ~v:`Neutral)
         (Ui.atom (Notty.I.strf ~attr:Notty.A.(bg red) "%.2fs" t)))
    v

let () =
  let now = Unix.gettimeofday() in
  let v = Lwd.var 0. in
  let ui = mk_clock (Lwd.get v) in
  Nottui.Ui_loop.run
    ~tick:(fun () -> Lwd.set v (Unix.gettimeofday () -. now))
    ~tick_period:0.05 ui