aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2024-05-15 11:05:27 -0500
committerMarc Coquand <marc@mccd.space>2024-05-15 11:05:27 -0500
commit47be0ea3eeb774102f02b5f85ee974afe6a8170e (patch)
treedc24d5c40f0f70d47697fe99ce9250d1187b7226
parentff680702db85b3eec539b3be1931f92cbb89fe8d (diff)
downloadstitch-47be0ea3eeb774102f02b5f85ee974afe6a8170e.tar.gz
stitch-47be0ea3eeb774102f02b5f85ee974afe6a8170e.tar.bz2
stitch-47be0ea3eeb774102f02b5f85ee974afe6a8170e.zip
Add way to go back and forth between note and todo view
-rw-r--r--lib/headlines.ml3
-rw-r--r--lib/todos.ml26
2 files changed, 9 insertions, 20 deletions
diff --git a/lib/headlines.ml b/lib/headlines.ml
index 0633a73..954d0e2 100644
--- a/lib/headlines.ml
+++ b/lib/headlines.ml
@@ -50,11 +50,12 @@ let rec render t ({ pos; scroll; content; content_pretty } as state) =
| `Mouse ((`Press _ | `Drag), (_, y), _) ->
render t { state with pos = 0, min y content_length }
| `Key (`ASCII '?', []) -> Help_screen.render t { go_back = (fun () -> render t state) }
- | `Key (`ASCII 't', []) ->
+ | `Key (`ASCII '2', []) ->
let todo_content = Grep.get_todos () |> Grep.parse_todo_string in
let todo_pretty = Grep.pretty_format_todo todo_content in
let todo_state =
Todos.init
+ ~goto_headlines:(fun () -> render t state)
~content:(todo_content |> Array.of_list)
~content_pretty:(todo_pretty |> Array.of_list)
in
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 })