From 9f3d3d40ddf6db70f8395adf4290241f7c5735db Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Wed, 15 May 2024 12:32:39 -0500 Subject: Update state management --- lib/todos.ml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/todos.ml') diff --git a/lib/todos.ml b/lib/todos.ml index 4e52cd4..d2af47f 100644 --- a/lib/todos.ml +++ b/lib/todos.ml @@ -8,11 +8,18 @@ type state = ; scroll : int ; content : (string * string) array ; content_pretty : string array - ; goto_headlines : state -> unit + ; goto_headlines : (unit -> unit) -> unit } -let init ~goto_headlines ~content ~content_pretty = - { pos = 0, 0; scroll = 0; content; content_pretty; goto_headlines } +let init ~goto_headlines = + let content = Grep.get_todos () |> Grep.parse_todo_string in + let content_pretty = Grep.pretty_format_todo content in + { pos = 0, 0 + ; scroll = 0 + ; content = content |> Array.of_list + ; content_pretty = content_pretty |> Array.of_list + ; goto_headlines + } let load_todos () = @@ -75,7 +82,7 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_headlines } as st } in Input_screen.render t input_state - | `Key (`ASCII '1', []) -> goto_headlines state + | `Key (`ASCII '1', []) -> goto_headlines (fun () -> render t state) | `Key (`ASCII 'j', []) | `Key (`ASCII 'N', [ `Ctrl ]) -> scroll_down () | `Key (`ASCII 'k', []) | `Key (`ASCII 'P', [ `Ctrl ]) -> scroll_up () | `Key (`ASCII 't', []) -> -- cgit v1.2.3