From 5aec082b915416107cec9e8c811bbbedafb70b59 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Mon, 20 May 2024 09:07:45 -0500 Subject: Enable hiding the file name using 'h' --- lib/headlines.ml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/headlines.ml') diff --git a/lib/headlines.ml b/lib/headlines.ml index eaa68d9..90bad7d 100644 --- a/lib/headlines.ml +++ b/lib/headlines.ml @@ -14,6 +14,7 @@ type state = ; goto_done_view : (unit -> unit) -> unit ; output : string option ; tag : string + ; hide_file_name : bool } let init ~goto_done_view ~goto_todos_view ~regexp = @@ -37,6 +38,7 @@ let init ~goto_done_view ~goto_todos_view ~regexp = ; goto_todos_view ; output = None ; tag = "" + ; hide_file_name = false }) @@ -45,8 +47,16 @@ let title = I.strf ~attr:A.(st bold) "%s" "Notes" |> I.pad ~l:0 ~t:0 (* TODO: Add page title *) let rec render t - ({ pos; scroll; content; content_pretty; goto_todos_view; goto_done_view; tag; output } - as state) + ({ pos + ; scroll + ; content + ; content_pretty + ; goto_todos_view + ; goto_done_view + ; tag + ; output + ; hide_file_name + } as state) = let content_start = 2 in let size_x, size_y = Common.Term.size t in @@ -96,6 +106,10 @@ let rec render render t { state with pos = 0, min y content_end; output = None } | `Key (`ASCII '?', []) -> Help_screen.render t { go_back = (fun () -> render t state) } | `Key (`ASCII '2', []) -> goto_todos_view (fun () -> render t state) + | `Key (`ASCII 'h', []) -> + let hide_file_name = not hide_file_name in + let content_pretty = content |> Grep.pretty_format ~hide_file_name in + render t { state with hide_file_name; content_pretty } | `Key (`ASCII '3', []) -> goto_done_view (fun () -> render t state) | `Key (`ASCII 'f', []) -> let content = @@ -128,7 +142,7 @@ let rec render ; on_enter = (fun tag -> let content = Grep.get_tagged_headlines tag () |> Grep.parse_headlines in - let content_pretty = Grep.pretty_format content in + let content_pretty = Grep.pretty_format ~hide_file_name content in Common.Term.cursor t None; render t @@ -176,7 +190,7 @@ let rec render let content = Grep.get_tagged_headlines tag () |> Grep.parse_headlines in - let content_pretty = Grep.pretty_format content in + let content_pretty = Grep.pretty_format ~hide_file_name content in Common.Term.cursor t None; render t -- cgit v1.2.3