aboutsummaryrefslogtreecommitdiff
path: root/lib/headlines.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/headlines.ml')
-rw-r--r--lib/headlines.ml27
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/headlines.ml b/lib/headlines.ml
index 94e7709..5c740ed 100644
--- a/lib/headlines.ml
+++ b/lib/headlines.ml
@@ -18,9 +18,7 @@ type state =
}
let init ~goto_done_view ~goto_todos_view ~regexp =
- let content =
- Grep.get_tagged_headlines regexp () |> Grep.parse_headlines
- in
+ let content = Grep.get_tagged_headlines regexp () |> Grep.parse_headlines in
if Array.length content == 0
then (
print_endline "Regexp not found";
@@ -77,7 +75,7 @@ let rec render
and elements =
Array.mapi
(fun i el ->
- if i + 1 == y - scroll
+ if i + 1 == y - scroll
then I.strf "%s" el |> I.pad ~l:2 ~t:(i + content_start)
else I.strf "%s" el |> I.pad ~l:2 ~t:(i + content_start))
(Basic.array_drop scroll content_pretty)
@@ -109,6 +107,27 @@ 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 'o', []) ->
+ let (input_state : Input_prompt.state) =
+ { screen = img
+ ; user_input = ""
+ ; prompt = "EXPORT TO"
+ ; on_enter =
+ (fun path ->
+ Common.Term.cursor t None;
+ if String.equal (String.trim path) String.empty |> not
+ then (
+ let export = String.concat "\n" (Array.to_list content_pretty) in
+ Export.to_path path ~content:export;
+ render t { state with output = Some ("Export written to: " ^ path) })
+ else render t { state with output = Some "Export Blank; skipping" })
+ ; on_cancel =
+ (fun _ ->
+ Common.Term.cursor t None;
+ render t { state with output = Some "Export Cancelled" })
+ }
+ in
+ Input_prompt.render t input_state
| `Key (`ASCII 'h', []) ->
let hide_file_name = not hide_file_name in
let content_pretty = content |> Grep.pretty_format ~hide_file_name in