···11+open Jj_tui.Logging
22+13module Make (Vars : Global_vars.Vars) = struct
24 open Lwd_infix
35 open Vars
···415417 items
416418 |> W.Lists.selection_list_exclusions
417419 ~on_selection_change:(fun revision ->
418418- (* Eio.Fiber.fork ~sw @@ fun _ -> *)
419419- (* Vars.update_ui_state @@ fun _ -> *)
420420- (* TODO: Do i need this now that we have the concurrency safeguards?*)
420420+ (*Respond to change in selected revision*)
421421 Lwd.set Vars.ui_state.selected_revision revision;
422422 Show_view.(pushStatus (Graph_preview (Vars.get_selected_rev ())));
423423+ [%log debug "Selected revision: '%s'" (Global_vars.get_unique_id revision)];
423424 Picos_std_structured.Flock.fork (fun () -> Global_funcs.update_views ()))
424425 ~custom_handler:(fun _ key -> handleKeys key)
425426 in
+7-2
jj_tui/bin/jj_commands.ml
···22 It allows us to define a command list: A list of keys, commands and descriptions
33 We can then run a command matching a key or generate a documentation UI element showing all available commands *)
4455+open Jj_tui.Logging
66+57(** Internal to this module. I'm trying this out as a way to avoid .mli files*)
68module Shared = struct
77- type cmd_args = string list
99+ type cmd_args = string list [@@deriving show]
810911 (** Regular jj command *)
1012 type 'a command_variant =
···3234 (** Allows nesting of commands, shows a popup with command options and waits for the user to press the appropriate key*)
3335 | Fun of (unit -> unit)
3436 (** Execute an arbitrary function. Prefer other command types if possible *)
3737+ [@@deriving show]
35383639 (** A command that should be run when it's key is pressed*)
3740 and 'a command = {
···3942 ; description : string
4043 ; cmd : 'a command_variant
4144 }
4545+ [@@deriving show]
4246end
43474448(** Internal to this module. I'm trying this out as a way to avoid .mli files*)
···105109 ;;
106110107111 let rec handleCommand description cmd =
112112+ [%log info "Handling command: %s" description];
108113 let noOut args =
109114 let _ = args in
110110- let _result = jj (args ) in
115115+ let _result = jj args in
111116 Global_funcs.update_status ~cause_snapshot:false ();
112117 ()
113118 in
+10-7
jj_tui/bin/jj_process.ml
···22open Picos_std_sync
33open Picos_std_finally
44open Spawn
55+open Jj_tui.Logging
5667module type t = sig
78 val jj : ?snapshot:bool -> string list -> string
···115116 (* This should ensure that all children processes are killed before we cleanup the pipes*)
116117 Flock.join_after @@ fun () ->
117118 let pid =
118118- Picos_io.Unix.create_process_env
119119- cmd
120120- (cmd :: args |> Array.of_list)
121121- (Unix.environment ())
122122- stdin_o
123123- stdout_i
124124- stderr_i
119119+ Picos_io.Unix.create_process_env
120120+ cmd
121121+ (cmd :: args |> Array.of_list)
122122+ (Unix.environment ())
123123+ stdin_o
124124+ stdout_i
125125+ stderr_i
125126 in
126127 let prom = Flock.fork_as_promise (fun () -> Picos_io.Unix.waitpid [] pid) in
127128 (* Close unused pipe ends in the parent process *)
···165166 When true snapshots the state when running the command and also aquires a lock before running it. Set to false for commands you wish to run concurrently. like those for generating content in the UI
166167 @param ?color=true When true output will have terminal escape codes for color *)
167168 let jj_no_log_errorable ?(snapshot = true) ?(color = true) args =
169169+ [%log debug "Running 'jj %s'" (args |> String.concat " ")];
168170 let locked =
169171 if snapshot
170172 then (
···186188 | Picos_std_structured.Control.Terminate as e ->
187189 raise e
188190 | e ->
191191+ [%log warn "Exception running jj: %s" (Printexc.to_string e)];
189192 Error (`Exception (Printexc.to_string e))
190193 in
191194 if locked then Mutex.unlock access_lock;
+15-5
jj_tui/bin/main.ml
···33open Nottui
44module Jj_ui = Jj_ui.Make (Vars)
55open Picos_std_structured
66+open Jj_tui.Logging
77+88+(* let file_logger ~logs_stream=
99+ let logs_crs=Picos_std_sync.Stream.tap logs_stream in
1010+ let file=Picos_io.Unix.openfile "" in
1111+ let handle_log cursor=
1212+ let log,cursor =Picos_std_sync.Stream.read cursor in
1313+1414+ Picos_io.Unix.wri
1515+*)
616717let ui_loop ~quit ~term root =
818 print_endline "starting loop";
···1222 root
1323 |> Nottui.Ui.event_filter (fun x ->
1424 match x with
1515- | `Key (`ASCII 'q', [`Ctrl]) ->
2525+ | `Key (`ASCII 'q', [ `Ctrl ]) ->
1626 Lwd.set quit true;
1727 `Handled
1828 | _ ->
···3343 ~renderer
3444 term
3545 (Lwd.observe @@ root);
3636-3746 (*Sleep for a bit to stop spinning the cpu
3838- TODO: May not be needed, nottui may sleep for a bit anyway
4747+ TODO: May not be needed, nottui may sleep for a bit anyway
3948 *)
4049 let end_time = Sys.time () in
4150 let elapsed = end_time -. start_time in
···5362 Vars.term := Some term;
5463 ui_loop ~quit:Vars.quit ~term (Jj_ui.mainUi ());
5564 Flock.terminate ()
5656-5765;;
58665967let start () =
6068 Picos_mux_multififo.run_on ~n_domains:8 (fun _ ->
6161- Flock.join_after @@ fun () -> start_ui ())
6969+ Flock.join_after @@ fun () ->
7070+ init_logging ();
7171+ start_ui ())
6272(* Picos_mux_multififo.run (fun () -> Flock.join_after (fun _ -> start_ui ())) *)
6373;;
6474
···149149 join3 (wrap_line pa) ub (wrap_line sb)))
150150;;
151151152152-(* Grab the mouse and repeat an event until button is released *)
153153-let grab_and_repeat ~sw f =
154154- let stop = ref false in
155155- let rec step delay () =
156156- if not !stop
157157- then (
158158- f ();
159159- (*TODO: this should not be a clock*)
160160- Eio_unix.sleep delay;
161161- step 0.025 ())
162162- else ()
163163- in
164164- Eio.Fiber.fork ~sw (step 0.4);
165165- `Grab ((fun ~x:_ ~y:_ -> ()), fun ~x:_ ~y:_ -> stop := true)
166166-;;
167167-168152let on_click f ~x:_ ~y:_ = function
169153 | `Left ->
170154 f ();