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/todos.ml | |
parent | db4e445ee0f29c1179b5d0746217e5b5525ff3e2 (diff) | |
download | stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.tar.gz stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.tar.bz2 stitch-9f3d3d40ddf6db70f8395adf4290241f7c5735db.zip |
Update state management
Diffstat (limited to 'lib/todos.ml')
-rw-r--r-- | lib/todos.ml | 15 |
1 files changed, 11 insertions, 4 deletions
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', []) -> |