diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/done.ml | 29 | ||||
-rw-r--r-- | lib/grep.ml | 14 | ||||
-rw-r--r-- | lib/headlines.ml | 22 | ||||
-rw-r--r-- | lib/help_screen.ml | 1 | ||||
-rw-r--r-- | lib/todos.ml | 29 |
5 files changed, 75 insertions, 20 deletions
diff --git a/lib/done.ml b/lib/done.ml index a8b4750..f7e1a0b 100644 --- a/lib/done.ml +++ b/lib/done.ml @@ -12,6 +12,7 @@ type state = ; goto_todo : (unit -> unit) -> unit ; tag : string ; output : string option + ; hide_file_name : bool } let title = I.strf ~attr:A.(st bold) "%s" "Done" |> I.pad ~l:0 ~t:0 @@ -28,18 +29,28 @@ let init ~goto_todo ~goto_headlines = ; goto_todo ; tag = "" ; output = None + ; hide_file_name = false } -let load_done () = +let load_done ?(hide_file_name = false) () = let done_content = Grep.get_done () |> Grep.parse_todo_string in - let done_pretty = Grep.pretty_format_todo done_content in + let done_pretty = Grep.pretty_format_todo ~hide_file_name done_content in done_content, done_pretty let rec render t - ({ pos; scroll; content; content_pretty; goto_headlines; goto_todo; output; _ } as state) + ({ pos + ; scroll + ; content + ; content_pretty + ; goto_headlines + ; goto_todo + ; output + ; hide_file_name + ; _ + } as state) = let x, y = pos in let size_x, size_y = Common.Term.size t in @@ -112,8 +123,14 @@ let rec render Input_prompt.render t input_state | `Key (`ASCII '1', []) -> goto_headlines (fun () -> render t state) | `Key (`ASCII '2', []) -> goto_todo (fun () -> render t state) + | `Key (`ASCII 'h', []) -> + let hide_file_name = not hide_file_name in + let content_pretty = + Grep.pretty_format_todo ~hide_file_name (content |> Array.to_list) |> Array.of_list + in + render t { state with hide_file_name; content_pretty } | `Key (`ASCII 'g', []) -> - let content, content_pretty = load_done () in + let content, content_pretty = load_done ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in render t @@ -142,7 +159,7 @@ let rec render ~content ~selected_file ~on_return:(fun result -> - let content, content_pretty = load_done () in + let content, content_pretty = load_done ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in Common.Term.cursor t None; render @@ -166,7 +183,7 @@ let rec render | `Key (`ASCII 'T', [ `Ctrl ]) -> let selected_file, _ = Array.get content (y - content_start) in let _ = Grep.toggle_todo selected_file in - let content, content_pretty = load_done () in + let content, content_pretty = load_done ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in render t diff --git a/lib/grep.ml b/lib/grep.ml index c5acbb6..94b4b48 100644 --- a/lib/grep.ml +++ b/lib/grep.ml @@ -94,10 +94,13 @@ let parse_todo_string s = | _ -> raise (Not_A_Tuple (String.concat " SPLIT " split, message)))) -let pretty_format_todo parsed_headlines = +let pretty_format_todo ?(hide_file_name = false) parsed_headlines = let padding = get_padding_list parsed_headlines in List.map - (fun (file_name, content) -> String.concat " | " [ pad file_name padding; content ]) + (fun (file_name, content) -> + if not hide_file_name + then String.concat " | " [ pad file_name padding; content ] + else content) parsed_headlines @@ -236,10 +239,13 @@ let parse_headlines s = (** Turns "2024-03-05.org:* Hello world" into "2024-03-05 | * Hello world" *) -let pretty_format parsed_headlines = +let pretty_format ?(hide_file_name = false) parsed_headlines = let padding = get_padding_arr parsed_headlines in Array.map - (fun (file_name, content) -> String.concat " | " [ pad file_name padding; content ]) + (fun (file_name, content) -> + if not hide_file_name + then String.concat " | " [ pad file_name padding; content ] + else content) parsed_headlines 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 diff --git a/lib/help_screen.ml b/lib/help_screen.ml index 0759d26..6e98015 100644 --- a/lib/help_screen.ml +++ b/lib/help_screen.ml @@ -31,6 +31,7 @@ let general_help_menu = ; "Done", "3" ; "Run Shell Command", "!" ; "Edit File in $EDITOR", "Enter, e" + ; "Toggle Hide File Name", "h" ] diff --git a/lib/todos.ml b/lib/todos.ml index f657d6c..237732f 100644 --- a/lib/todos.ml +++ b/lib/todos.ml @@ -12,6 +12,7 @@ type state = ; goto_done : (unit -> unit) -> unit ; output : string option ; tag : string + ; hide_file_name : bool } let title = I.strf ~attr:A.(st bold) "%s" "Todo" |> I.pad ~l:0 ~t:0 @@ -28,18 +29,28 @@ let init ~goto_done ~goto_headlines = ; goto_done ; output = None ; tag = "" + ; hide_file_name = false } -let load_todos () = +let load_todos ?(hide_file_name = false) () = let todo_content = Grep.get_todos () |> Grep.parse_todo_string in - let todo_pretty = Grep.pretty_format_todo todo_content in + let todo_pretty = Grep.pretty_format_todo ~hide_file_name todo_content in todo_content, todo_pretty let rec render t - ({ pos; scroll; content; content_pretty; goto_headlines; goto_done; output; _ } as state) + ({ pos + ; scroll + ; content + ; content_pretty + ; goto_headlines + ; goto_done + ; output + ; hide_file_name + ; _ + } as state) = let x, y = pos in let size_x, size_y = Common.Term.size t in @@ -90,7 +101,7 @@ let rec render | `Key (`ASCII '1', []) -> goto_headlines (fun () -> render t state) | `Key (`ASCII '3', []) -> goto_done (fun () -> render t state) | `Key (`ASCII 'g', []) -> - let content, content_pretty = load_todos () in + let content, content_pretty = load_todos ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in render t @@ -145,7 +156,7 @@ let rec render ~content ~selected_file ~on_return:(fun result -> - let content, content_pretty = load_todos () in + let content, content_pretty = load_todos ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in Common.Term.cursor t None; render @@ -164,10 +175,16 @@ let rec render } in Input_prompt.render t input_state + | `Key (`ASCII 'h', []) -> + let hide_file_name = not hide_file_name in + let content_pretty = + Grep.pretty_format_todo ~hide_file_name (content |> Array.to_list) |> Array.of_list + in + render t { state with hide_file_name; content_pretty } | `Key (`ASCII 'T', [ `Ctrl ]) -> let selected_file, _ = Array.get content (y - content_start) in let _ = Grep.toggle_done selected_file in - let content, content_pretty = load_todos () in + let content, content_pretty = load_todos ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in render t |