aboutsummaryrefslogtreecommitdiff
path: root/lib/headlines.ml
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/headlines.ml61
1 files changed, 39 insertions, 22 deletions
diff --git a/lib/headlines.ml b/lib/headlines.ml
index 6ed3ab3..38bba58 100644
--- a/lib/headlines.ml
+++ b/lib/headlines.ml
@@ -18,24 +18,31 @@ type state =
}
let init ~goto_done_view ~goto_todos_view ~regexp =
- let content = Grep.get_tagged_headlines regexp () |> Grep.parse_headlines in
- if Array.length content == 0
- then (
- print_endline "Regexp not found";
- exit 0)
- else (
- let hide_file_name = true in
- let content_pretty = content |> Grep.pretty_format ~hide_file_name in
- { pos = 0, 2
- ; scroll = 0
- ; content
- ; content_pretty
- ; goto_done_view
- ; goto_todos_view
- ; output = None
- ; tag = regexp
- ; hide_file_name
- })
+ let content = Grep.get_tagged_headlines regexp () |> Option.map Grep.parse_headlines in
+ match content with
+ | None ->
+ Error
+ "There are no notes to load. Make sure to create some in order to view them in \
+ stitch. Check stitch --help for how to get started."
+ | Some content ->
+ if Array.length content == 0
+ then (
+ print_endline "Unable to load any content. Check grep commands and make sure there are notes";
+ exit 0)
+ else (
+ let hide_file_name = true in
+ let content_pretty = content |> Grep.pretty_format ~hide_file_name in
+ Ok
+ { pos = 0, 2
+ ; scroll = 0
+ ; content
+ ; content_pretty
+ ; goto_done_view
+ ; goto_todos_view
+ ; output = None
+ ; tag = regexp
+ ; hide_file_name
+ })
let title ~tag =
@@ -45,8 +52,12 @@ let title ~tag =
let refresh ~hide_file_name regexp =
- let content = Grep.get_tagged_headlines regexp () |> Grep.parse_headlines in
- content, content |> Grep.pretty_format ~hide_file_name
+ let content =
+ Grep.get_tagged_headlines regexp ()
+ |> Option.map Grep.parse_headlines
+ |> Option.value ~default:[||]
+ in
+ content, Grep.pretty_format ~hide_file_name content
let rec render
@@ -173,7 +184,11 @@ let rec render
; prompt = "REGEXP"
; on_enter =
(fun tag ->
- let content = Grep.get_tagged_headlines tag () |> Grep.parse_headlines in
+ let content =
+ Grep.get_tagged_headlines tag ()
+ |> Option.map Grep.parse_headlines
+ |> Option.value ~default:[||]
+ in
let content_pretty = Grep.pretty_format ~hide_file_name content in
Common.Term.cursor t None;
render
@@ -225,7 +240,9 @@ let rec render
~selected_file
~on_return:(fun result ->
let content =
- Grep.get_tagged_headlines tag () |> Grep.parse_headlines
+ Grep.get_tagged_headlines tag ()
+ |> Option.map Grep.parse_headlines
+ |> Option.value ~default:[||]
in
let content_pretty = Grep.pretty_format ~hide_file_name content in
Common.Term.cursor t None;