From 961339f0bd28c0f30bdb3c995a27927def8a991e Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Wed, 15 May 2024 12:58:00 -0500 Subject: Update Note view --- lib/headlines.ml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/headlines.ml') diff --git a/lib/headlines.ml b/lib/headlines.ml index 7d410d7..f61d8b9 100644 --- a/lib/headlines.ml +++ b/lib/headlines.ml @@ -26,35 +26,39 @@ let init ~goto_todos_view ~regexp = exit 0) else ( let content_pretty = content |> Grep.pretty_format in - { pos = 0, 0; scroll = 0; content; content_pretty; goto_todos_view }) + { pos = 0, 2; scroll = 0; content; content_pretty; goto_todos_view }) (* 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 content_start = 2 in let x, y = pos in + let content_position = y - content_start + 1 in let img = let dot = I.string A.(st bold) ">" |> I.pad ~l:0 ~t:(y - scroll) and elements = Array.mapi (fun i el -> - if i == y - scroll - then I.strf ~attr:A.(st underline) "%s" el |> I.pad ~l:2 ~t:i - else I.strf "%s" el |> I.pad ~l:2 ~t:i) + if i + 1 == y - scroll (* TODO: Should be reverse *) + then I.strf "%s" el |> I.pad ~l:2 ~t:(i + content_start) + else I.strf "%s" el |> I.pad ~l:2 ~t:(i + content_start)) (Array.to_seq content_pretty |> Seq.drop scroll |> Array.of_seq) in let open I in - Array.fold_left (fun sum el -> el sum) dot elements + Array.fold_left (fun sum el -> el sum) (title dot) elements in let _, size_y = Common.Term.size t in Common.Term.image t img; - let content_length = Array.length content_pretty in + let content_end = Array.length content_pretty + (content_start - 1) in let scroll_up () = - let scroll = if y - scroll = 0 then max (scroll - 1) 0 else scroll in - render t @@ { state with pos = x, max (y - 1) 0; scroll } + let scroll = if y - content_start - scroll = 0 then max (scroll - 1) 0 else scroll in + 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_length - 1); scroll } + render t { state with pos = x, min (y + 1) content_end; scroll } in match Common.Term.event t with | `End | `Key (`Escape, []) | `Key (`ASCII 'q', []) | `Key (`ASCII 'C', [ `Ctrl ]) -> () @@ -64,7 +68,7 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as s | `Up -> scroll_up ()) | `Resize _ -> render t state | `Mouse ((`Press _ | `Drag), (_, y), _) -> - render t { state with pos = 0, min y content_length } + 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 's', []) -> @@ -117,7 +121,7 @@ let rec render t ({ pos; scroll; content; content_pretty; goto_todos_view } as s let[@warning "-8"] (editor :: args) = String.split_on_char ' ' (Sys.getenv "EDITOR") in - let selected_file, _ = Array.get content y in + let selected_file, _ = Array.get content content_position in let full_path_file = Grep.execution_directory ^ "/" ^ selected_file in let full_args = Array.append (Array.of_list args) [| full_path_file |] in Common.Term.cursor t (Some (0, 0)); -- cgit v1.2.3