diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-29 09:51:57 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-29 09:51:57 -0500 |
commit | 9ffd8422de06adab52c0b7873a6ce181d82b5391 (patch) | |
tree | 84d092603ffd984ee8ef1073972946a708010579 | |
parent | 4aea286edd92845f17c490e1009cd8f7e271e596 (diff) | |
download | stitch-9ffd8422de06adab52c0b7873a6ce181d82b5391.tar.gz stitch-9ffd8422de06adab52c0b7873a6ce181d82b5391.tar.bz2 stitch-9ffd8422de06adab52c0b7873a6ce181d82b5391.zip |
Refresh when editing in stitched and headline view
-rw-r--r-- | lib/grep.ml | 5 | ||||
-rw-r--r-- | lib/headlines.ml | 8 | ||||
-rw-r--r-- | lib/stitched_article.ml | 17 |
3 files changed, 25 insertions, 5 deletions
diff --git a/lib/grep.ml b/lib/grep.ml index 30df423..7ec664e 100644 --- a/lib/grep.ml +++ b/lib/grep.ml @@ -161,8 +161,7 @@ let find_sort_modification () = let find_sort_name () = let open Shexp_process in - let open Shexp_process.Infix in - call [ "find"; "." ] |- call [ "cut"; "-c3-" ] + call [ "ls" ] let run_print ~dir args = @@ -283,7 +282,7 @@ let get_file_names tag = let open Shexp_process in let open Shexp_process.Infix in find_sort_name () - |- call [ "xargs"; grep_cmd; "-H"; "-r"; "-l"; "--no-messages"; "-E"; tag ] + |- call [ "xargs"; grep_cmd; "-H"; "-l"; "-E"; tag ] |- call [ "sort"; "-n"; "-r" ] |- read_all in diff --git a/lib/headlines.ml b/lib/headlines.ml index cefe31d..3c94f12 100644 --- a/lib/headlines.ml +++ b/lib/headlines.ml @@ -43,6 +43,11 @@ let title ~tag = | a -> I.strf ~attr:A.(st bold) "%s > %s" "Notes" a |> I.pad ~l:0 ~t:0 +let refresh regexp = + let content = Grep.get_tagged_headlines regexp () |> Grep.parse_headlines in + content, content |> Grep.pretty_format + + let rec render t ({ pos @@ -252,7 +257,8 @@ let rec render match Unix.wait () with | _, _ -> Common.Term.cursor t None; - render t state + let content, content_pretty = refresh tag in + render t { state with content; content_pretty } (* Capture resizing events *) | exception Unix.Unix_error (Unix.EINTR, _, _) -> run_editor () | exception Unix.Unix_error (_, _, _) -> failwith "ERROR" diff --git a/lib/stitched_article.ml b/lib/stitched_article.ml index 86a22e9..d333747 100644 --- a/lib/stitched_article.ml +++ b/lib/stitched_article.ml @@ -22,6 +22,20 @@ let title ~tag = | a -> I.strf ~attr:A.(st bold) "%s > %s" "Notes" a |> I.pad ~l:0 ~t:0 +let refresh tag = + let content = Grep.get_file_names tag |> Array.of_list in + let oc = open_out "/tmp/stitch-output" in + Printf.fprintf oc "%s\n" (String.concat "\n" (content |> Array.to_list)); + close_out oc; + let content = + Array.map (fun file_name -> Grep.get_full_file_content_content file_name) content + |> Array.to_list + in + let content = Grep.parse_full_content content in + let content_pretty = Grep.pretty_print_parsed_content content |> Array.of_list in + content |> Array.of_list, content_pretty + + let content_start = 1 (* TODO: Use grep -l to filter notes by regexp and rerender those files*) @@ -235,7 +249,8 @@ let rec render match Unix.wait () with | _, _ -> Common.Term.cursor t None; - render t state + let content, content_pretty = refresh tag in + render t { state with content; content_pretty } (* Capture resizing events *) | exception Unix.Unix_error (Unix.EINTR, _, _) -> run_editor () | exception Unix.Unix_error (_, str_err, str_err_2) -> |