diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-15 12:58:00 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-15 12:58:00 -0500 |
commit | 961339f0bd28c0f30bdb3c995a27927def8a991e (patch) | |
tree | 179866ee379f97efa3f72460f6df4b0f9bfe3ad1 | |
parent | 9f3d3d40ddf6db70f8395adf4290241f7c5735db (diff) | |
download | stitch-961339f0bd28c0f30bdb3c995a27927def8a991e.tar.gz stitch-961339f0bd28c0f30bdb3c995a27927def8a991e.tar.bz2 stitch-961339f0bd28c0f30bdb3c995a27927def8a991e.zip |
Update Note view
-rw-r--r-- | lib/headlines.ml | 26 | ||||
-rw-r--r-- | lib/help_screen.ml | 9 |
2 files changed, 20 insertions, 15 deletions
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)); diff --git a/lib/help_screen.ml b/lib/help_screen.ml index 0726be3..b07cad2 100644 --- a/lib/help_screen.ml +++ b/lib/help_screen.ml @@ -23,10 +23,10 @@ let general_help_menu = ; "Down", "Ctrl-n, j" ; "Up", "Ctrl-p, k" ; "Regexp", "r" - ; "Note view", "1" - ; "Todo view", "2" - ; "Done view", "3" - ; "Edit", "Enter, e" + ; "Note View", "1" + ; "Todo View", "2" + ; "Done View", "3" + ; "Edit File", "Enter, e" ] @@ -83,6 +83,7 @@ let rec render t ({ go_back } as state) = info_img </> general_img </> note_img </> todo_img </> done_img in Common.Term.image t img; + (* TODO: Add controls for scroll *) match Common.Term.event t with | `End | `Key (`Escape, []) | `Key (`ASCII 'q', []) | `Key (`ASCII 'C', [ `Ctrl ]) -> () | `Resize _ -> render t state |