aboutsummaryrefslogtreecommitdiff
path: root/lib/todos.ml
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2024-05-20 09:07:45 -0500
committerMarc Coquand <marc@mccd.space>2024-05-20 09:07:45 -0500
commit5aec082b915416107cec9e8c811bbbedafb70b59 (patch)
treea39601d40898e332508d9708014e0415c069b01b /lib/todos.ml
parent0bc408515cfc9c8feff686f8c758dfaf6c997bb4 (diff)
downloadstitch-5aec082b915416107cec9e8c811bbbedafb70b59.tar.gz
stitch-5aec082b915416107cec9e8c811bbbedafb70b59.tar.bz2
stitch-5aec082b915416107cec9e8c811bbbedafb70b59.zip
Enable hiding the file name using 'h'
Diffstat (limited to 'lib/todos.ml')
-rw-r--r--lib/todos.ml29
1 files changed, 23 insertions, 6 deletions
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