tree_nav :3

This commit is contained in:
cqc
2023-01-22 23:16:15 -06:00
parent 97730899c6
commit f0c5556450
3 changed files with 4818 additions and 4557 deletions

File diff suppressed because one or more lines are too long

View File

@ -89,13 +89,13 @@ let _ =
let gravity_pad = Gravity.make ~h:`Negative ~v:`Negative in
let gravity_crop = Gravity.make ~h:`Positive ~v:`Negative in
let body = Lwd.var (Lwd.pure Ui.empty) in
let wm = Nottui_widgets.window_manager (Lwd.join (Lwd.get body)) in
let wm = Widgets.window_manager (Lwd.join (Lwd.get body)) in
Nav.test_pull () >>= fun test_tree ->
Nottui_widgets.(tree_nav test_tree []) >>= fun ui ->
Widgets.(tree_nav test_tree []) >>= fun ui ->
let root =
Lwd.set body
(Lwd.map ~f:(Ui.resize ~pad:gravity_pad ~crop:gravity_crop) ui);
Nottui_widgets.window_manager_view wm
Widgets.window_manager_view wm
in
let events, push_event = Lwt_stream.create () in

View File

@ -2345,7 +2345,9 @@ module Nottui_lwt = struct
(fun () -> Term.release term) *)
end
module Nottui_widgets = struct
module Widgets = struct
(* Majority of this was adapted from Nottui_widgets *)
open Nottui
let string ?(attr = A.empty) str = Ui.atom (I.string ~attr str)
@ -2941,6 +2943,55 @@ module Nottui_widgets = struct
Option.iter (fun (f, _) -> Focus.request f)
@@ Lwd_table.get cursor)
(Lwd.peek cursor);
(* Lwd.observe ~on_invalidate:(fun _ ->
Lwd.set cursorview (Lwd.quick_sample (root ()))); *)
let cursorview =
Lwd.var @@ Lwd.pure @@ string "initializing..."
in
let cv, push_cv = Lwt_stream.create () in
let cvroot =
Lwd.observe ~on_invalidate:(fun _ ->
Log.info (fun m ->
m
"tree_nav cursorviewroot on_invalidate push_cv \
triggered??");
push_cv (Some ()))
@@ Lwd.map (Lwd.get cursor) ~f:(function
| Some cursor_row -> (
match Lwd_table.get cursor_row with
| Some (_focus, (step, tree)) -> (
Nav.S.Tree.kind tree [] >>= function
| Some `Node ->
Lwt.return @@ Lwd.pure @@ string "Sub-node??"
| Some `Contents -> (
Nav.S.Tree.find_all tree [] >>= function
| Some (contents, _metadata) ->
Lwt.return
(edit_area
~table:(edit_area_of_string contents)
())
| None ->
Lwt.return @@ Lwd.pure
@@ string ("could not find path: " ^ step))
| None -> Lwt.return @@ Lwd.pure @@ string step)
| None ->
Lwt.return @@ Lwd.pure
@@ string "cursor table row doesn't exist")
| None ->
Lwt.return @@ Lwd.pure @@ string "cursor doesn't exist")
in
Lwt.async (fun () ->
Lwt_stream.iter_s
(fun _ ->
Lwd.quick_sample cvroot >>= fun cursorview'' ->
Log.info (fun m ->
m
"tree_nav cursorviewroot on_invalidate Lwt.async \
(Lwd.set cursorview) triggered??");
Lwt.return (Lwd.set cursorview cursorview''))
cv);
push_cv (Some ());
Lwt.return
(Lwd_table.map_reduce
(fun _ (f, (s, _)) ->
@ -2976,7 +3027,11 @@ module Nottui_widgets = struct
| `Backspace, [] -> `Unhandled
| `Uchar u, [ `Ctrl ] when eq_uc_c u 'k' -> `Handled
| _ -> `Unhandled))
(Focus.status focus))
(Focus.status focus)
|> Lwd.map2
~f:(fun cursorview' tree_view ->
Ui.join_x tree_view cursorview')
(Lwd.join @@ Lwd.get cursorview))
(** Tab view, where exactly one element of [l] is shown at a time. *)
let tabs (tabs : (string * (unit -> Ui.t Lwd.t)) list) : Ui.t Lwd.t