add minimal example
This commit is contained in:
parent
7d424cc772
commit
20f54eeff8
5
Makefile
5
Makefile
|
@ -1,7 +1,10 @@
|
|||
all:
|
||||
dune build
|
||||
|
||||
TESTS=misc reranger stress
|
||||
TESTS=minimal misc reranger stress
|
||||
|
||||
run-minimal:
|
||||
dune exec examples/minimal.bc
|
||||
|
||||
run-misc:
|
||||
dune exec examples/misc.bc
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
(executable
|
||||
(name minimal)
|
||||
(modules minimal)
|
||||
(libraries notty notty.unix nottui nottui-widgets))
|
||||
|
||||
(executable
|
||||
(name misc)
|
||||
(modules misc)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
open Nottui
|
||||
|
||||
(* Put the UI here *)
|
||||
|
||||
let bind x f = Lwd.join (Lwd.map f x)
|
||||
|
||||
let node title ~f =
|
||||
let vopened = Lwd.var false in
|
||||
let label =
|
||||
Lwd.map' (Lwd.get vopened) @@ fun opened ->
|
||||
let text = if opened then "[-]" else "[+]" in
|
||||
Ui.mouse_area (fun ~x:_ ~y:_ -> function
|
||||
| `Left -> Lwd.set vopened (not opened); `Handled
|
||||
| _ -> `Unhandled
|
||||
) (Ui.atom Notty.(I.string A.empty text))
|
||||
in
|
||||
let content = Lwd.bind (Lwd.get vopened) @@ function
|
||||
| true -> f ()
|
||||
| false -> Lwd.pure Ui.empty
|
||||
in
|
||||
Lwd.map2' label content (fun lbl content ->
|
||||
Ui.join_x lbl
|
||||
(Ui.join_y (Ui.atom Notty.(I.string A.empty title)) content)
|
||||
)
|
||||
|
||||
let rec count_to_10 () =
|
||||
Lwd_utils.pack Ui.pack_y (
|
||||
List.map
|
||||
(fun i -> node (string_of_int i) ~f:count_to_10)
|
||||
[1;2;3;4;5;6;7;8;9;10]
|
||||
)
|
||||
|
||||
let root = count_to_10 ()
|
||||
|
||||
(*let () = Statmemprof_emacs.start 1E-4 30 5*)
|
||||
|
||||
let () = Ui_loop.run ~tick_period:0.2 root
|
Loading…
Reference in New Issue