aboutsummaryrefslogtreecommitdiff
path: root/lib/stitch.ml
blob: e49ed9c3ae03dd88367ed4a420eac639960fca0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Grep = Grep
module Common = Common
module Todos = Todos
module Headlines = Headlines

let start (tag : string) () =
  (* This is a rather funky state management that isn't maybe entirely functional.
     What we do is store a function for each view that restores it's state.

     This allows us to remember the state of the view and restore it as we travel between different views.

     It does create a rather funky, cyclical state though.
  *)
  let term = Common.Term.create () in
  let restore_headline_state = ref (fun () -> ()) in
  let restore_todo_state = ref (fun () -> ()) in
  let goto_headline_from_todo new_todo_state =
    restore_todo_state := new_todo_state;
    !restore_headline_state ()
  in
  (restore_todo_state
   := fun () ->
        let todo = Todos.init ~goto_headlines:goto_headline_from_todo in
        Todos.render term todo);
  let headline =
    Headlines.init
      ~goto_todos_view:(fun new_state ->
        restore_headline_state := new_state;
        !restore_todo_state ())
      ~regexp:tag
  in
  Headlines.render term headline