···11+module Mutex : Mutex_backend.MUTEX
22+(**
33+This is the mutex we use. it can be different depending on the backend we use.
44+For example, if we use picos, we use the picos mutex.
55+If we use the stdlib, we use the stdlib mutex.
66+*)
77+18type +'a t
29(** A dynamic document of type ['a]. Documents can be produced in several
310 different ways:
···11+12include Lwd_impl.Make(Mutex_picos)
2334(* This should prevent the set from being cancelled and leaving hanging locks*)
+2
forks/nottui/lib/nottui/nottui_main.ml
···11open Notty
22open Lwd_utils
33+(*Use the same mutex backend as lwd*)
44+module Mutex=Lwd.Mutex
35(* test comment *)
46module Log = (val Logs.src_log (Logs.Src.create "nottui"))
57
+2-2
jj_tui/bin/jj_commands.ml
···4545 | SubCmd of 'a command Key_Map.t
4646 (** Allows nesting of commands, shows a popup with command options and waits for the user to press the appropriate key*)
4747 | Fun of (unit -> unit)
4848- (** Execute an arbitrary function. Prefer other command types if possible *)
4848+ (** Just like command, except that it runs async and shows a throbber while it's running. Useful for long running commands*)
4949 | Cmd_async of string * cmd_args
5050 [@@deriving show]
5151···211211 | Cmd_async (loading_msg,args) ->
212212 jj_async
213213 args
214214- ~on_start:(fun () -> show_popup @@ Some (W.hbox [ Jj_widgets.throbber ;(W.string (" "^loading_msg)|>Lwd.pure) ], loading_msg))
214214+ ~on_start:(fun () -> show_popup @@ Some (W.hbox [ Jj_widgets.throbber ;(W.string (" "^loading_msg)|>Lwd.pure) ], "loading..."))
215215 ~on_success:(fun _ ->
216216 Global_funcs.update_status ~cause_snapshot:true ();
217217 show_popup None)
+22-48
jj_tui/bin/jj_process.ml
···196196 code, status, stdout, stderr,pid
197197 ;;
198198199199- let jj_async ?(snapshot = true) ?(color = true) args ~on_start ~on_success ~on_error =
200200- let run () =
201201- let locked =
202202- if snapshot
203203- then (
204204- Mutex.lock access_lock;
205205- true)
206206- else false
207207- in
208208- let res =
209209- try
210210- let _, status, out, err, _ =
211211- picos_process
212212- "jj"
213213- (List.concat
214214- [
215215- args
216216- ; [ "--no-pager" ]
217217- ; (if snapshot then [] else [ "--ignore-working-copy" ])
218218- ; (if color then [ "--color"; "always" ] else [ "--color"; "never" ])
219219- ])
220220- in
221221- let exit_code =
222222- match status with
223223- | Unix.WEXITED code ->
224224- code
225225- | Unix.WSIGNALED _ | Unix.WSTOPPED _ ->
226226- -1
227227- in
228228- if exit_code = 0 then Ok (out, err) else Error (exit_code, out, err)
229229- with
230230- | exn ->
231231- if locked then Mutex.unlock access_lock;
232232- raise exn
233233- in
234234- if locked then Mutex.unlock access_lock;
235235- match res with
236236- | Ok (out, err) ->
237237- on_success (out, err)
238238- | Error (code, out, err) ->
239239- on_error code (err ^ out)
240240- in
241241- on_start ();
242242- Picos_std_structured.Flock.fork(fun _ ->
243243- run();
244244-245245- );
246246- ;;
247199248200 (* Ui_loop.run (Lwd.pure (W.printf "Hello world"));; *)
249201 let cmdArgs cmd args =
···350302 Vars.ui_state.command_log
351303 (([ "jj" ] @ args |> String.concat " ") :: current_log);
352304 jj_no_log ~snapshot args
305305+ ;;
306306+307307+ (**Run a jj command asynchronously with callbacks for success, error, and start*)
308308+ let jj_async ?(snapshot = true) ?(color = true) args ~on_start ~on_success ~on_error =
309309+ let run () =
310310+ let res = jj_no_log_errorable ~snapshot ~color args in
311311+ match res with
312312+ | Ok (out, err) ->
313313+ on_success (out, err)
314314+ | Error (`BadExit (code, msg)) ->
315315+ on_error code msg
316316+ | Error (`Exception msg) ->
317317+ on_error (-1) msg
318318+ in
319319+ on_start ();
320320+ Picos_std_structured.Flock.fork (fun () ->
321321+ try run ()
322322+ with
323323+ | exn ->
324324+ let msg = Printexc.to_string exn in
325325+ [%log warn "Exception in jj_async: %s" msg];
326326+ on_error (-1) msg)
353327 ;;
354328355329 (**gets the description of the current and previous change. Useful when squashing*)
+3-2
jj_tui/bin/jj_widgets.ml
···216216217217 (* let update_throb= Lwd.var 0 in *)
218218 Lwd.bind (Lwd.get frame_var) ~f:(fun frame ->
219219+ (*each time we re-render, we start a new thread to update the frame the next time*)
219220 Picos_std_structured.Flock.fork(fun _ ->
220220- Unix.sleepf 0.2;
221221+ Unix.sleepf 0.1;
221222 Lwd.set frame_var (Lwd.peek frame_var + 1);
222223 );
223223- W.string ~attr:A.(fg red) (frames.(frame mod len) )|>Lwd.pure
224224+ W.string ~attr:A.(fg blue) (frames.(frame mod len) )|>Lwd.pure
224225 )
225226 ;;
226227