example: in reranger, add quit button, use more accurate clock

This commit is contained in:
Simon Cruanes 2019-12-13 16:03:18 -06:00 committed by Frédéric Bour
parent 20f54eeff8
commit aef7bd2ee6
1 changed files with 7 additions and 2 deletions

View File

@ -9,7 +9,7 @@ let is_double_click =
let k' = !k in
incr k;
fun () ->
let time = Unix.time () in
let time = Unix.gettimeofday () in
let result =
let k, t = !last in
k = k' && t +. 0.4 >= time
@ -21,6 +21,8 @@ let remember_width ~wref ui =
wref := max (Ui.layout_spec ui).Ui.w !wref;
Ui.resize ~w:!wref ui
let menu_quit = main_menu_item "Quit" (fun () -> exit 0)
let rec dir ?(initial_path = []) ?after_width:(wref = ref 0) path =
let column = Lwd.var (Lwd.return Ui.empty) in
let header = string ~attr:Notty.(A.bg A.green) (Filename.basename path) in
@ -130,6 +132,9 @@ let () =
in
List.rev (split (Sys.getcwd ()))
in
let ui =
Lwd_utils.pack Ui.pack_y [ menu_quit; dir ~initial_path "/"]
in
Ui_loop.run
(Lwd.map' (dir ~initial_path "/") (fun ui ->
(Lwd.map' ui (fun ui ->
ui |> Ui.resize ~fill:gravity_fill ~crop:gravity_crop))