diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-15 12:32:39 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-15 12:32:39 -0500 |
commit | 9f3d3d40ddf6db70f8395adf4290241f7c5735db (patch) | |
tree | 3972cd631f438451538144e697ebd8f310833209 /lib/stitch.ml | |
parent | db4e445ee0f29c1179b5d0746217e5b5525ff3e2 (diff) | |
download | stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.tar.gz stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.tar.bz2 stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.zip |
Update state management
Diffstat (limited to 'lib/stitch.ml')
-rw-r--r-- | lib/stitch.ml | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/stitch.ml b/lib/stitch.ml new file mode 100644 index 0000000..e49ed9c --- /dev/null +++ b/lib/stitch.ml @@ -0,0 +1,32 @@ +module Grep = Grep +module Common = Common +module Todos = Todos +module Headlines = Headlines + +let start (tag : string) () = + (* This is a rather funky state management that isn't maybe entirely functional. + What we do is store a function for each view that restores it's state. + + This allows us to remember the state of the view and restore it as we travel between different views. + + It does create a rather funky, cyclical state though. + *) + let term = Common.Term.create () in + let restore_headline_state = ref (fun () -> ()) in + let restore_todo_state = ref (fun () -> ()) in + let goto_headline_from_todo new_todo_state = + restore_todo_state := new_todo_state; + !restore_headline_state () + in + (restore_todo_state + := fun () -> + let todo = Todos.init ~goto_headlines:goto_headline_from_todo in + Todos.render term todo); + let headline = + Headlines.init + ~goto_todos_view:(fun new_state -> + restore_headline_state := new_state; + !restore_todo_state ()) + ~regexp:tag + in + Headlines.render term headline |