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/stitched_article.ml | |
parent | db4e445ee0f29c1179b5d0746217e5b5525ff3e2 (diff) | |
download | stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.tar.gz stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.tar.bz2 stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.zip |
Update state management
Diffstat (limited to '')
-rw-r--r-- | lib/stitched_article.ml | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/lib/stitched_article.ml b/lib/stitched_article.ml index c71ca14..66a108e 100644 --- a/lib/stitched_article.ml +++ b/lib/stitched_article.ml @@ -10,11 +10,14 @@ type state = ; content : (string * int * string * int) array ; go_back : unit -> unit ; content_pretty : Grep.display_type array - ; todo_state : Todos.state option + ; goto_todos_view : (unit -> unit) -> unit } (* TODO: Use grep -l to filter notes by regexp and rerender those files*) -let rec render t ({ pos; scroll; content_pretty; go_back; content; todo_state } as state) = +let rec render + t + ({ pos; scroll; content_pretty; go_back; content; goto_todos_view } as state) + = let size_x, size_y = Common.Term.size t in let x, y = pos in let img = @@ -50,26 +53,7 @@ let rec render t ({ pos; scroll; content_pretty; go_back; content; todo_state } | `Key (`ASCII 'j', []) | `Key (`ASCII 'N', [ `Ctrl ]) -> scroll_down () | `Key (`ASCII 'k', []) | `Key (`ASCII 'P', [ `Ctrl ]) -> scroll_up () | `Key (`ASCII '?', []) -> Help_screen.render t { go_back = (fun () -> render t state) } - | `Key (`ASCII '2', []) -> - (match todo_state with - | Some todo_state -> - Todos.render - t - { todo_state with - goto_headlines = - (fun new_state -> render t { state with todo_state = Some new_state }) - } - | None -> - let todo_content = Grep.get_todos () |> Grep.parse_todo_string in - let todo_pretty = Grep.pretty_format_todo todo_content in - let todo_state = - Todos.init - ~goto_headlines:(fun new_state -> - render t { state with todo_state = Some new_state }) - ~content:(todo_content |> Array.of_list) - ~content_pretty:(todo_pretty |> Array.of_list) - in - Todos.render t todo_state) + | `Key (`ASCII '2', []) -> goto_todos_view (fun () -> render t state) | `Key (`ASCII 'e', []) | `Key (`Enter, []) -> (* Editor might be set with extra args, in that case we need to separate these *) let[@warning "-8"] (editor :: args) = |