diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-15 14:05:03 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-15 14:05:03 -0500 |
commit | 3f696169ab1a560d94d169c1a5b744346da4c081 (patch) | |
tree | d2aa5d6b0b9d70a594ede7795e423250a92729e1 /lib/headlines.ml | |
parent | 961339f0bd28c0f30bdb3c995a27927def8a991e (diff) | |
download | stitch-3f696169ab1a560d94d169c1a5b744346da4c081.tar.gz stitch-3f696169ab1a560d94d169c1a5b744346da4c081.tar.bz2 stitch-3f696169ab1a560d94d169c1a5b744346da4c081.zip |
Add done view + visual
Diffstat (limited to 'lib/headlines.ml')
-rw-r--r-- | lib/headlines.ml | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/headlines.ml b/lib/headlines.ml index f61d8b9..51bcc6b 100644 --- a/lib/headlines.ml +++ b/lib/headlines.ml @@ -11,9 +11,10 @@ type state = ; content : (string * string) array ; content_pretty : string array ; goto_todos_view : (unit -> unit) -> unit + ; goto_done_view : (unit -> unit) -> unit } -let init ~goto_todos_view ~regexp = +let init ~goto_done_view ~goto_todos_view ~regexp = let tag = if String.equal regexp "" then None else Some regexp in let content = match tag with @@ -26,15 +27,19 @@ let init ~goto_todos_view ~regexp = exit 0) else ( let content_pretty = content |> Grep.pretty_format in - { pos = 0, 2; scroll = 0; content; content_pretty; goto_todos_view }) + { pos = 0, 2; scroll = 0; content; content_pretty; goto_done_view; goto_todos_view }) +let title = I.strf ~attr:A.(st bold) "%s" "Note View" |> I.pad ~l:0 ~t:0 + (* TODO: Add page title *) -let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as state) = - let title = I.strf ~attr:A.(st underline) "%s" "Note View" |> I.pad ~l:0 ~t:0 in +let rec render + t + ({ pos; scroll; content; content_pretty; goto_todos_view; goto_done_view } as state) + = let content_start = 2 in let x, y = pos in - let content_position = y - content_start + 1 in + let content_position = y - content_start in let img = let dot = I.string A.(st bold) ">" |> I.pad ~l:0 ~t:(y - scroll) and elements = @@ -56,7 +61,6 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as s render t { state with pos = x, max (y - 1) content_start; scroll } in let scroll_down () = - print_endline (Int.to_string y); let scroll = if y - scroll >= size_y - 1 then scroll + 1 else scroll in render t { state with pos = x, min (y + 1) content_end; scroll } in @@ -71,6 +75,7 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as s render t { state with pos = 0, min y content_end } | `Key (`ASCII '?', []) -> Help_screen.render t { go_back = (fun () -> render t state) } | `Key (`ASCII '2', []) -> goto_todos_view (fun () -> render t state) + | `Key (`ASCII '3', []) -> goto_done_view (fun () -> render t state) | `Key (`ASCII 's', []) -> let content = Array.map @@ -84,7 +89,7 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as s in Stitched_article.render t - { pos = 0, 0 + { pos = 0, Stitched_article.content_start ; content = full_content |> Array.of_list ; content_pretty = full_content_pretty ; scroll = 0 @@ -101,7 +106,9 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as s let content = Grep.get_tagged_headlines tag () |> Grep.parse_headlines in let content_pretty = Grep.pretty_format content in Common.Term.cursor t None; - render t { state with content; content_pretty; pos = 0, 0; scroll = 0 }) + render + t + { state with content; content_pretty; pos = 0, content_start; scroll = 0 }) ; on_cancel = (fun _ -> Common.Term.cursor t None; |