···291291 | `Paste of Unescape.paste
292292 ]
293293294294+ let pp_semantic_key ppf = function
295295+ | `Copy -> Format.pp_print_string ppf "Copy"
296296+ | `Paste -> Format.pp_print_string ppf "Paste"
297297+ | `Focus `Out -> Format.pp_print_string ppf "Focus(Out)"
298298+ | `Focus `Next -> Format.pp_print_string ppf "Focus(Next)"
299299+ | `Focus `Prev -> Format.pp_print_string ppf "Focus(Prev)"
300300+ | `Focus `Left -> Format.pp_print_string ppf "Focus(Left)"
301301+ | `Focus `Right -> Format.pp_print_string ppf "Focus(Right)"
302302+ | `Focus `Up -> Format.pp_print_string ppf "Focus(Up)"
303303+ | `Focus `Down -> Format.pp_print_string ppf "Focus(Down)"
304304+ ;;
305305+306306+ let pp_special_key ppf = function
307307+ | `Arrow `Up -> Format.pp_print_string ppf "↑"
308308+ | `Arrow `Down -> Format.pp_print_string ppf "↓"
309309+ | `Arrow `Left -> Format.pp_print_string ppf "←"
310310+ | `Arrow `Right -> Format.pp_print_string ppf "→"
311311+ | `Enter -> Format.pp_print_string ppf "Enter"
312312+ | `Tab -> Format.pp_print_string ppf "Tab"
313313+ | `Backspace -> Format.pp_print_string ppf "Backspace"
314314+ | `Delete -> Format.pp_print_string ppf "Delete"
315315+ | `Escape -> Format.pp_print_string ppf "Escape"
316316+ | `Function n -> Format.fprintf ppf "F%d" n
317317+ | `Page `Up -> Format.pp_print_string ppf "PgUp"
318318+ | `Page `Down -> Format.pp_print_string ppf "PgDn"
319319+ | `Home -> Format.pp_print_string ppf "Home"
320320+ | `End -> Format.pp_print_string ppf "End"
321321+ | `Insert -> Format.pp_print_string ppf "Insert"
322322+ ;;
323323+324324+ let pp_main_key ppf = function
325325+ | #Unescape.special as special -> pp_special_key ppf special
326326+ | `Uchar u ->
327327+ if Uchar.is_char u then
328328+ Format.fprintf ppf "'%c'" (Uchar.to_char u)
329329+ else
330330+ Format.fprintf ppf "U+%04X" (Uchar.to_int u)
331331+ | `ASCII c -> Format.fprintf ppf "'%c'" c
332332+ | #semantic_key as sem -> pp_semantic_key ppf sem
333333+ ;;
334334+335335+ let pp_modifier ppf = function
336336+ | `Ctrl -> Format.pp_print_string ppf "Ctrl"
337337+ | `Alt -> Format.pp_print_string ppf "Alt"
338338+ | `Shift -> Format.pp_print_string ppf "Shift"
339339+ | `Meta -> Format.pp_print_string ppf "Meta"
340340+ ;;
341341+342342+ let pp_key ppf (main_key, mods) =
343343+ match mods with
344344+ | [] -> pp_main_key ppf main_key
345345+ | _ ->
346346+ Format.pp_print_list
347347+ ~pp_sep:(fun ppf () -> Format.pp_print_string ppf "+")
348348+ pp_modifier
349349+ ppf
350350+ mods;
351351+ Format.pp_print_string ppf "+";
352352+ pp_main_key ppf main_key
353353+ ;;
354354+294355 type layout_spec =
295356 { w : int
296357 ; h : int
···575636 | Focus_area (u, _)
576637 | Shift_area (u, _, _)
577638 | Event_filter (u, _) -> f u
578578- | X (u1, u2) | Y (u1, u2) | Z (u1, u2) ->
579579- f u1;
580580- f u2
639639+ | X (a, b) | Y (a, b) | Z (a, b) ->
640640+ f a;
641641+ f b
581642 ;;
582643end
583644
+3
forks/nottui/lib/nottui/nottui_main.mli
···199199 [ Unescape.special | `Uchar of Uchar.t | `ASCII of char | semantic_key ]
200200 * Unescape.mods
201201202202+ (** Pretty print a key *)
203203+ val pp_key : Format.formatter -> key -> unit
204204+202205 (** An event is propagated until it gets handled.
203206 Handler functions return a value of type [may_handle] to indicate
204207 whether the event was handled, not handled, or should be remapped to aonother event. *)
+1-1
jj_tui/bin/jj_commands.ml
···263263 (* Use exceptions so we can break out of the list*)
264264 let input = Lwd.peek ui_state.input in
265265 try
266266+ [%log debug "command recieved key: %a" Ui.pp_key key];
266267 match key with
267268 | `ASCII k, modifiers ->
268269 let key = { key = k; modifiers } in
269269- [%log info "key: %s" (key_to_string key)];
270270 let cmd = keymap |> Key_Map.find_opt key in
271271 (match cmd with
272272 | Some cmd ->
+18-4
jj_tui/bin/jj_process.ml
···162162 if not !isDone
163163 then (
164164 try
165165- [%log debug "Cleaning up cancelled command %s" (args |> String.concat " ")];
165165+ [%log debug "pid: %i Cleaning up cancelled command %s" pid (args |> String.concat " ")];
166166 Unix.kill pid Sys.sigkill;
167167 Unix.waitpid [ Unix.WUNTRACED ] pid |> ignore
168168 with
···177177 stdout_i
178178 stderr_i)
179179 in
180180+181181+ [%log debug "pid: %i started" pid ];
180182 let prom = Flock.fork_as_promise (fun () -> Unix.waitpid [] pid) in
181183 (* Close unused pipe ends in the parent process *)
182184 Unix.close stdout_i;
···191193 isDone := true;
192194 (* let stderr = read_fd_to_end stderr_i in *)
193195 (* let stdout= ""in *)
194194- code, status, stdout, stderr
196196+ code, status, stdout, stderr,pid
195197 ;;
196198197199 (* Ui_loop.run (Lwd.pure (W.printf "Hello world"));; *)
198200 let cmdArgs cmd args =
199201 let start_time = Unix.gettimeofday () in
200200- let code, status, out_content, err_content = picos_process cmd args in
202202+ let code, status, out_content, err_content,pid = picos_process cmd args in
201203 let end_time = Unix.gettimeofday () in
204204+ let exit_code_text=
205205+ match status with
206206+ | Unix.WEXITED code ->
207207+ Printf.sprintf "exit: %i" code
208208+ | Unix.WSIGNALED x->
209209+ Printf.sprintf "signalled: %i" x
210210+ | Unix.WSTOPPED x->
211211+ Printf.sprintf "stopped: %i" x
212212+ in
213213+202214 [%log
203215 debug
204204- "Executing '%s %s' took: %fms "
216216+ "Executing pid:%i %s '%s %s' took: %fms "
217217+ pid
218218+ exit_code_text
205219 cmd
206220 (args |> String.concat " ")
207221 ((end_time -. start_time) *. 1000.)];
+24-2
jj_tui/bin/show_view.ml
···11open Picos_std_sync
22open Picos_std_structured
33open Jj_tui.Logging
44+module Log = (val src_log ~src:(Logs.Src.create "status view"))
4556type detail_state =
67 | Loading
···7879 res
7980 ;;
80818282+ let get_latest_message cursor =
8383+8484+ let rec seek_latest last cursor=
8585+ let peeked=Stream.peek_opt cursor in
8686+ match peeked with
8787+ |Some (last,new_cursor)->
8888+ seek_latest last new_cursor
8989+ |None->
9090+ [%log debug "skipping to next status because two were queued"];
9191+ (last,cursor)
9292+ in
9393+ let msg, new_cursor = cursor |> Stream.read in
9494+9595+ (*little 50ms delay to let us move to the next one if it's ready*)
9696+ Picos.Fiber.sleep ~seconds:0.05;
9797+ (*if the queue isn't empty just skip the current because we really only ever want the newest*)
9898+ seek_latest msg new_cursor
9999+100100+81101 (* Wait for messages to come in the stream.
82102 When a message comes, we try to render it.
83103 If a new message comes, we cancel the current computation and then start the new rendering
···88108 let current_loading_computation = ref (Promise.of_value ()) in
89109 let cursor = ref (Stream.tap stream) in
90110 while true do
9191- let msg, new_cursor = !cursor |> Stream.read in
9292- cursor := new_cursor;
111111+ [%log debug "waiting for next status"];
112112+ let msg,new_cursor=get_latest_message !cursor in
113113+ cursor:=new_cursor;
114114+ [%log debug "cancelling older status because of new message"];
93115 Promise.terminate_after ~seconds:0. !current_summary_computation;
94116 Promise.terminate_after ~seconds:0. !current_detail_computation;
95117 Promise.terminate_after ~seconds:0. !current_loading_computation;
+51-28
jj_tui/lib/logging.ml
···1414 ms
1515;;
16161717+module type MYLOG = sig
1818+ include Logs.LOG
17192020+ val timestamp_tag : float Logs.Tag.def
2121+end
18221919-module Log = struct
2020- let timestamp_tag =
2121- Logs.Tag.def "timestamp" ~doc:"Timestamp" (fun fmt tm ->
2222- time_to_string tm |> Format.pp_print_string fmt)
2323- ;;
2323+let timestamp_tag =
2424+ Logs.Tag.def "timestamp" ~doc:"Timestamp" (fun fmt tm ->
2525+ time_to_string tm |> Format.pp_print_string fmt)
2626+;;
24272525- let timestamp_wrap fn : ('a, 'b) Logs.msgf =
2626- fun m ->
2727- fn (fun ?header ?(tags = Logs.Tag.empty) fmt ->
2828- let timestamp = Unix.gettimeofday () in
2929- let tags = Logs.Tag.add timestamp_tag timestamp tags in
3030- m ?header ~tags fmt)
3131- ;;
2828+(**
2929+my own custom version of src log that also includes a timestamp
3030+*)
3131+let src_log ~src =
3232+ let open Logs in
3333+ let module Log = struct
3434+ let timestamp_wrap fn : ('a, 'b) Logs.msgf =
3535+ fun m ->
3636+ fn (fun ?header ?(tags = Logs.Tag.empty) fmt ->
3737+ let timestamp = Unix.gettimeofday () in
3838+ let tags = Logs.Tag.add timestamp_tag timestamp tags in
3939+ m ?header ~tags fmt)
4040+ ;;
4141+4242+ let msg level msgf = msg ~src level (timestamp_wrap msgf)
4343+ let kmsg k level msgf = kmsg k ~src level (timestamp_wrap msgf)
4444+ let app msgf = msg App msgf
4545+ let err msgf = msg Error msgf
4646+ let warn msgf = msg Warning msgf
4747+ let info msgf = msg Info msgf
4848+ let debug msgf = msg Debug msgf
4949+5050+ let on_error ?level ?header ?tags ~pp ~use =
5151+ on_error ~src ?level ?header ?tags ~pp ~use
5252+ ;;
5353+5454+ let on_error_msg ?level ?header ?tags ~use =
5555+ on_error_msg ~src ?level ?header ?tags ~use
5656+ ;;
5757+ end
5858+ in
5959+ (module Log : Logs.LOG)
6060+;;
32613333- let debug ?src fn = Logs.debug ?src (timestamp_wrap fn)
3434- let info ?src fn = Logs.info ?src (timestamp_wrap fn)
3535- let warn ?src fn = Logs.warn ?src (timestamp_wrap fn)
3636- let err ?src fn = Logs.err ?src (timestamp_wrap fn)
3737- let app ?src fn = Logs.app ?src (timestamp_wrap fn)
3838-end
6262+module Log = (val src_log ~src:(Logs.Src.create "app"))
39634064module Internal = struct
4165 let reporter ppf =
···5074 | None ->
5175 None
5276 | Some tags ->
5353- Logs.Tag.find Log.timestamp_tag tags
7777+ Logs.Tag.find timestamp_tag tags
5478 in
5555- let dt = Format.pp_print_option (Logs.Tag.printer Log.timestamp_tag) in
7979+ let dt = Format.pp_print_option (Logs.Tag.printer timestamp_tag) in
5680 Format.kfprintf
5781 k
5882 ppf
5959- ("%a[%a] @[" ^^ fmt ^^ "@]@.")
8383+ ("%a[%a][%s] @[" ^^ fmt ^^ "@]@.")
6084 Logs.pp_header
6185 (level, h)
6286 dt
6387 stamp
8888+ (Logs.Src.name src)
6489 in
6590 msgf @@ fun ?header ?tags fmt -> with_stamp header tags k ppf fmt
6691 in
···80105 then
81106 List.iteri
82107 (fun i file ->
8383- if i >= 20
8484- then (
8585- let file_path = Filename.concat log_path file in
8686- Unix.unlink file_path;
8787- [%log debug "deleted log file:%s" file_path]))
108108+ if i >= 20
109109+ then (
110110+ let file_path = Filename.concat log_path file in
111111+ Unix.unlink file_path;
112112+ [%log debug "deleted log file:%s" file_path]))
88113 log_files
89114 ;;
9011591116 let normalise_os raw =
92117 match String.lowercase_ascii raw with "darwin" | "osx" -> "macos" | s -> s
93118 ;;
9494-9595-9611997120 (*tries to get the logging dir for macos and linux*)
98121 let get_log_dir () =