From 681c9e3a618a6834aa778102d8f4fd201d488244 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Sun, 30 Jun 2024 17:23:27 -0500 Subject: Bug fixes --- lib/headlines.ml | 61 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'lib/headlines.ml') 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; -- cgit v1.2.3