terminal user interface to jujutsu. Focused on speed and clarity
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

nottui with picos

+50 -19
+16 -9
forks/nottui/lib/nottui/nottui_main.ml
··· 11 11 val request_var : var -> unit 12 12 val release : handle -> unit 13 13 14 - (** Request the focus and add to the focus stack *) 14 + (** request the focus and add to the focus stack *) 15 15 val request_reversable : handle -> unit 16 16 17 17 (** Release the focus (if the handle has it) and restore the last focus on the stack *) ··· 1056 1056 module Ui_loop = struct 1057 1057 open Notty_unix 1058 1058 1059 + let await_read_unix fd timeout: [`Ready|`NotReady]= 1060 + let rec select ()= 1061 + match Unix.select[fd] [] [fd] timeout with 1062 + | [], [], []-> `NotReady 1063 + | _-> `Ready 1064 + | exception Unix.Unix_error (Unix.EINTR, _, _) -> select () 1065 + in 1066 + select () 1067 + 1068 + 1069 + 1059 1070 (* FIXME Uses of [quick_sample] and [quick_release] should be replaced by 1060 1071 [sample] and [release] with the appropriate release management. *) 1061 1072 1062 - let step ?(process_event = true) ?(timeout = -1.0) ~renderer term root = 1073 + let step ?(await_read=await_read_unix) ?(process_event = true) ?(timeout = -1.0) ~renderer term root = 1063 1074 let size = Term.size term in 1064 1075 let image = 1065 1076 let rec stabilize () = ··· 1075 1086 then ( 1076 1087 let wait_for_event () = 1077 1088 let i, _ = Term.fds term in 1078 - let rec select () = 1079 - match Unix.select [ i ] [] [ i ] timeout with 1080 - | [], [], [] -> Term.pending term 1081 - | _ -> true 1082 - | exception Unix.Unix_error (Unix.EINTR, _, _) -> select () 1083 - in 1084 - select () 1089 + match await_read i timeout with 1090 + | `NotReady -> Term.pending term 1091 + | `Ready-> true 1085 1092 in 1086 1093 let has_event = timeout < 0.0 || Term.pending term || wait_for_event () in 1087 1094 if has_event
+7 -5
forks/nottui/lib/nottui/nottui_main.mli
··· 37 37 val has_focus : status -> bool 38 38 39 39 (** EXPERIMENTAL: Check if the handle is focused.*) 40 - val peek_has_focus:handle->bool 40 + val peek_has_focus : handle -> bool 41 41 (** TODO 42 42 This implements a more general concept of "reactive auction": 43 43 ··· 47 47 - the result can evolve over time, parties can join or leave, or bid 48 48 "more". *) 49 49 50 - (** Request the focus and add to the focus stack. 51 - WARNING: The focus stack is global, if you render multiple nottui ui's you may not want to use this 52 - NOTE: Calling this twice has the same result as calling it once. Trying to focus the currently focused item will not add to the stack*) 50 + (** Request the focus and add to the focus stack. 51 + WARNING: The focus stack is global, if you render multiple nottui ui's you may not want to use this 52 + NOTE: Calling this twice has the same result as calling it once. Trying to focus the currently focused item will not add to the stack*) 53 53 54 54 val request_reversable : handle -> unit 55 55 ··· 366 366 module Ui_loop : sig 367 367 open Notty_unix 368 368 369 + 369 370 (** Run one step of the main loop. 370 371 371 372 Update output image describe by the provided [root]. 372 373 If [process_event], wait up to [timeout] seconds for an input event, then 373 374 consume and dispatch it. *) 374 375 val step 375 - : ?process_event:bool 376 + : ?await_read:(Unix.file_descr -> float -> [ `Ready | `NotReady ]) 377 + -> ?process_event:bool 376 378 -> ?timeout:float 377 379 -> renderer:Renderer.t 378 380 -> Term.t
+27 -5
jj_tui/bin/main.ml
··· 28 28 `Unhandled) 29 29 in 30 30 let rec loop () = 31 + let open Picos_std_event in 31 32 if not (Lwd.peek quit) 32 33 then ( 33 - let start_time = Unix.gettimeofday() in 34 + (* let start_time = Unix.gettimeofday() in *) 34 35 let term_width, term_height = Notty_unix.Term.size (Vars.get_term ()) in 35 36 let prev_term_width, prev_term_height = Lwd.peek Vars.term_width_height in 36 37 if term_width <> prev_term_width || term_height <> prev_term_height 37 38 then Lwd.set Vars.term_width_height (term_width, term_height); 39 + let stored_fd=ref (Obj.magic()) in 38 40 Nottui.Ui_loop.step 41 + ~await_read:(fun unix_fd timeout -> 42 + 43 + let fd = 44 + if (Picos_io_fd.unsafe_get (!stored_fd)) = unix_fd then 45 + !stored_fd 46 + else 47 + let picos_fd=Picos_io_fd.create ~dispose:false unix_fd in 48 + stored_fd:=picos_fd; 49 + picos_fd 50 + in 51 + let res = 52 + let event_ret ret = Event.map (fun _ -> ret) in 53 + Picos_std_event.Event.select 54 + [ 55 + Picos_io_select.on fd `R |> event_ret `Ready 56 + ; Picos_io_select.on fd `W |> event_ret `Ready 57 + ; Picos_io_select.timeout ~seconds:timeout |> event_ret `NotReady 58 + ] 59 + in 60 + res) 39 61 ~process_event:true 40 62 ~timeout:0.01 41 63 ~renderer ··· 44 66 (*Sleep for a bit to stop spinning the cpu 45 67 TODO: May not be needed, nottui may sleep for a bit anyway 46 68 *) 47 - let end_time = Unix.gettimeofday () in 48 - let elapsed = end_time -. start_time in 49 - let sleep_time = max 0.01 (0.01 -. elapsed) in 50 - Picos_io.Unix.sleepf sleep_time; 69 + (* let end_time = Unix.gettimeofday () in *) 70 + (* let elapsed = end_time -. start_time in *) 71 + (* let sleep_time = max 0.01 (0.01 -. elapsed) in *) 72 + (* Picos_io.Unix.sleepf sleep_time; *) 51 73 loop ()) 52 74 in 53 75 loop ()