diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-23 13:45:28 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-23 13:45:28 -0500 |
commit | eed9e36b661009e5bcf1c4f5ec3a9279bbb7cda5 (patch) | |
tree | 65940a73db6096bd5f7bcb8d3b9a86f4f28864ab /lib/headlines.ml | |
parent | 833716046de9b3ee8e4f277f383967c0d35ba28a (diff) | |
download | stitch-eed9e36b661009e5bcf1c4f5ec3a9279bbb7cda5.tar.gz stitch-eed9e36b661009e5bcf1c4f5ec3a9279bbb7cda5.tar.bz2 stitch-eed9e36b661009e5bcf1c4f5ec3a9279bbb7cda5.zip |
Add ability to export current view
Diffstat (limited to 'lib/headlines.ml')
-rw-r--r-- | lib/headlines.ml | 27 |
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 |