···1111 val request_var : var -> unit
1212 val release : handle -> unit
13131414- (** Request the focus and add to the focus stack *)
1414+ (** request the focus and add to the focus stack *)
1515 val request_reversable : handle -> unit
16161717 (** Release the focus (if the handle has it) and restore the last focus on the stack *)
···10561056module Ui_loop = struct
10571057 open Notty_unix
1058105810591059+ let await_read_unix fd timeout: [`Ready|`NotReady]=
10601060+ let rec select ()=
10611061+ match Unix.select[fd] [] [fd] timeout with
10621062+ | [], [], []-> `NotReady
10631063+ | _-> `Ready
10641064+ | exception Unix.Unix_error (Unix.EINTR, _, _) -> select ()
10651065+ in
10661066+ select ()
10671067+10681068+10691069+10591070 (* FIXME Uses of [quick_sample] and [quick_release] should be replaced by
10601071 [sample] and [release] with the appropriate release management. *)
1061107210621062- let step ?(process_event = true) ?(timeout = -1.0) ~renderer term root =
10731073+ let step ?(await_read=await_read_unix) ?(process_event = true) ?(timeout = -1.0) ~renderer term root =
10631074 let size = Term.size term in
10641075 let image =
10651076 let rec stabilize () =
···10751086 then (
10761087 let wait_for_event () =
10771088 let i, _ = Term.fds term in
10781078- let rec select () =
10791079- match Unix.select [ i ] [] [ i ] timeout with
10801080- | [], [], [] -> Term.pending term
10811081- | _ -> true
10821082- | exception Unix.Unix_error (Unix.EINTR, _, _) -> select ()
10831083- in
10841084- select ()
10891089+ match await_read i timeout with
10901090+ | `NotReady -> Term.pending term
10911091+ | `Ready-> true
10851092 in
10861093 let has_event = timeout < 0.0 || Term.pending term || wait_for_event () in
10871094 if has_event
+7-5
forks/nottui/lib/nottui/nottui_main.mli
···3737 val has_focus : status -> bool
38383939 (** EXPERIMENTAL: Check if the handle is focused.*)
4040- val peek_has_focus:handle->bool
4040+ val peek_has_focus : handle -> bool
4141 (** TODO
4242 This implements a more general concept of "reactive auction":
4343···4747 - the result can evolve over time, parties can join or leave, or bid
4848 "more". *)
49495050- (** Request the focus and add to the focus stack.
5151- WARNING: The focus stack is global, if you render multiple nottui ui's you may not want to use this
5252- 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*)
5050+ (** Request the focus and add to the focus stack.
5151+ WARNING: The focus stack is global, if you render multiple nottui ui's you may not want to use this
5252+ 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*)
53535454 val request_reversable : handle -> unit
5555···366366module Ui_loop : sig
367367 open Notty_unix
368368369369+369370 (** Run one step of the main loop.
370371371372 Update output image describe by the provided [root].
372373 If [process_event], wait up to [timeout] seconds for an input event, then
373374 consume and dispatch it. *)
374375 val step
375375- : ?process_event:bool
376376+ : ?await_read:(Unix.file_descr -> float -> [ `Ready | `NotReady ])
377377+ -> ?process_event:bool
376378 -> ?timeout:float
377379 -> renderer:Renderer.t
378380 -> Term.t
+27-5
jj_tui/bin/main.ml
···2828 `Unhandled)
2929 in
3030 let rec loop () =
3131+ let open Picos_std_event in
3132 if not (Lwd.peek quit)
3233 then (
3333- let start_time = Unix.gettimeofday() in
3434+ (* let start_time = Unix.gettimeofday() in *)
3435 let term_width, term_height = Notty_unix.Term.size (Vars.get_term ()) in
3536 let prev_term_width, prev_term_height = Lwd.peek Vars.term_width_height in
3637 if term_width <> prev_term_width || term_height <> prev_term_height
3738 then Lwd.set Vars.term_width_height (term_width, term_height);
3939+ let stored_fd=ref (Obj.magic()) in
3840 Nottui.Ui_loop.step
4141+ ~await_read:(fun unix_fd timeout ->
4242+4343+ let fd =
4444+ if (Picos_io_fd.unsafe_get (!stored_fd)) = unix_fd then
4545+ !stored_fd
4646+ else
4747+ let picos_fd=Picos_io_fd.create ~dispose:false unix_fd in
4848+ stored_fd:=picos_fd;
4949+ picos_fd
5050+ in
5151+ let res =
5252+ let event_ret ret = Event.map (fun _ -> ret) in
5353+ Picos_std_event.Event.select
5454+ [
5555+ Picos_io_select.on fd `R |> event_ret `Ready
5656+ ; Picos_io_select.on fd `W |> event_ret `Ready
5757+ ; Picos_io_select.timeout ~seconds:timeout |> event_ret `NotReady
5858+ ]
5959+ in
6060+ res)
3961 ~process_event:true
4062 ~timeout:0.01
4163 ~renderer
···4466 (*Sleep for a bit to stop spinning the cpu
4567 TODO: May not be needed, nottui may sleep for a bit anyway
4668 *)
4747- let end_time = Unix.gettimeofday () in
4848- let elapsed = end_time -. start_time in
4949- let sleep_time = max 0.01 (0.01 -. elapsed) in
5050- Picos_io.Unix.sleepf sleep_time;
6969+ (* let end_time = Unix.gettimeofday () in *)
7070+ (* let elapsed = end_time -. start_time in *)
7171+ (* let sleep_time = max 0.01 (0.01 -. elapsed) in *)
7272+ (* Picos_io.Unix.sleepf sleep_time; *)
5173 loop ())
5274 in
5375 loop ()