aboutsummaryrefslogtreecommitdiff
path: root/lib/todos.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/todos.ml')
-rw-r--r--lib/todos.ml26
1 files changed, 7 insertions, 19 deletions
diff --git a/lib/todos.ml b/lib/todos.ml
index 3162615..907538c 100644
--- a/lib/todos.ml
+++ b/lib/todos.ml
@@ -8,9 +8,12 @@ type state =
; scroll : int
; content : (string * string) array
; content_pretty : string array
+ ; goto_headlines : unit -> unit
}
-let init ~content ~content_pretty = { pos = 0, 0; scroll = 0; content; content_pretty }
+let init ~goto_headlines ~content ~content_pretty =
+ { pos = 0, 0; scroll = 0; content; content_pretty; goto_headlines }
+
let load_todos () =
let todo_content = Grep.get_todos () |> Grep.parse_todo_string in
@@ -18,7 +21,7 @@ let load_todos () =
todo_content, todo_pretty
-let rec render t ({ pos; scroll; content; content_pretty } as state) =
+let rec render t ({ pos; scroll; content; content_pretty; goto_headlines } as state) =
let x, y = pos in
let img =
let dot = I.string A.(st bold) ">" |> I.pad ~l:0 ~t:(y - scroll)
@@ -64,7 +67,7 @@ let rec render t ({ pos; scroll; content; content_pretty } as state) =
let content = Grep.get_tagged_headlines tag () |> Grep.parse_headlines in
let content_pretty = Grep.pretty_format content in
Common.Term.cursor t None;
- render t { content; content_pretty; pos = 0, 0; scroll = 0 })
+ render t { state with content; content_pretty })
; on_cancel =
(fun _ ->
Common.Term.cursor t None;
@@ -72,6 +75,7 @@ let rec render t ({ pos; scroll; content; content_pretty } as state) =
}
in
Input_screen.render t input_state
+ | `Key (`ASCII '1', []) -> goto_headlines ()
| `Key (`ASCII 'j', []) | `Key (`ASCII 'N', [ `Ctrl ]) -> scroll_down ()
| `Key (`ASCII 'k', []) | `Key (`ASCII 'P', [ `Ctrl ]) -> scroll_up ()
| `Key (`ASCII 't', []) ->
@@ -118,19 +122,3 @@ let rec render t ({ pos; scroll; content; content_pretty } as state) =
in
run_editor ()
| _ -> render t state
-
-
-let start (tag : string) () =
- let tag = if String.equal tag "" then None else Some tag in
- let content =
- match tag with
- | None -> Grep.get_headlines () |> Grep.parse_headlines
- | Some tag -> Grep.get_tagged_headlines tag () |> Grep.parse_headlines
- in
- if Array.length content == 0
- then (
- print_endline "No entry for tag";
- exit 0)
- else (
- let content_pretty = content |> Grep.pretty_format in
- render (Common.Term.create ()) { pos = 0, 0; scroll = 0; content; content_pretty })