···11open Notty
22open Nottui
33-open Eio.Std
43open Picos_std_structured
54open Lwd_infix
65open Jj_tui.Process
···47464847(** Global variables for the ui. Here we keep anything that's just a pain to pipe around*)
4948module type Vars = sig
5050- type eio_vars = {
5151- env : Eio_unix.Stdenv.base
5252- ; mgr : Eio_unix.Process.mgr_ty Eio.Resource.t
5353- ; cwd : Eio.Fs.dir_ty Eio.Path.t
5454- }
55495650 val quit : bool Lwd.var
5751 val term : Notty_unix.Term.t option ref
5852 val term_width_height : (int * int) Lwd.var
5959- val get_eio_env : unit -> Eio_unix.Stdenv.base
6060- val set_eio_env : Eio_unix.Stdenv.base -> unit
6161- val get_eio_vars : unit -> eio_vars
6253 val get_term : unit -> Notty_unix.Term.t
6354 val ui_state : ui_state_t
6464- val update_ui_state : (ui_state_t -> unit) -> unit
6565- val render_mutex : Eio.Mutex.t
6655 val reset_selection : unit -> unit
67566857 (**returns either a change_id or if their are change_id conflicts, a commit_id *)
···7867end
79688069module Vars : Vars = struct
8181- type eio_vars = {
8282- env : Eio_unix.Stdenv.base
8383- ; mgr : Eio_unix.Process.mgr_ty Eio.Resource.t
8484- ; cwd : Eio.Fs.dir_ty Eio.Path.t
8585- }
86708771 let quit = Lwd.var false
8888- let eio = ref None
89729090- (** DONT DIRECTLY SET FROM EIO FIBERS!! When setting variables within a fiber use update_ui_state*)
9173 let ui_state =
9274 {
9375 view = Lwd.var `Main
···10991 }
11092 ;;
11193112112- (** allows other fibers to set lwd vars only when not during rendering*)
113113- let render_mutex = Eio.Mutex.create ()
11494115115- (** Safely ensures your update doesn't occur during a render*)
116116- let update_ui_state f =
117117- Eio.Mutex.lock render_mutex;
118118- f ui_state;
119119- Eio.Mutex.unlock render_mutex
120120- ;;
121121-122122- let set_eio_env env =
123123- eio := Some { env; mgr = Eio.Stdenv.process_mgr env; cwd = Eio.Stdenv.cwd env }
124124- ;;
1259512696 let term = ref None
12797 let term_width_height : (int * int) Lwd.var = Lwd.var (0, 0)
128128- let get_eio_env () = (Option.get !eio).env
129129- let get_eio_vars () = Option.get !eio
13098 let get_term () = Option.get !term
13199132100 let reset_selection () =
-2
jj_tui/bin/jj_ui.ml
···176176 while true do
177177 Picos.Fiber.sleep ~seconds:5.0;
178178 (*we need to lock this becasue we could end up updating while the ui is rendering*)
179179- (* Vars.render_mutex |> Eio.Mutex.lock; *)
180179 update_status ~cause_snapshot:true ()
181181- (* Vars.render_mutex |> Eio.Mutex.unlock *)
182180 done;
183181 ());
184182 let$* running = Lwd.get ui_state.view in
-2
jj_tui/bin/main.ml
···3636 let prev_term_width, prev_term_height = Lwd.peek Vars.term_width_height in
3737 if term_width <> prev_term_width || term_height <> prev_term_height
3838 then Lwd.set Vars.term_width_height (term_width, term_height);
3939- (* Vars.render_mutex |> Eio.Mutex.lock; *)
4039 Nottui.Ui_loop.step
4140 ~process_event:true
4241 ~timeout:0.01
···5554 loop ()
5655;;
57565858-(*TODO:For hosting a subprocess i should look into using EIO and Ui_loop.step like some of the other libraries built with nottui*)
5957let start_ui () =
6058 (*initialse the state*)
6159 let term = Notty_unix.Term.create () in