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.

finish invalidation tracker cleanup

+97 -25
+6 -7
forks/nottui/lib/nottui/nottui_main.ml
··· 1065 1065 ?process_event:bool 1066 1066 -> ?timeout:float 1067 1067 -> renderer:Renderer.t 1068 + -> cache: image option ref 1068 1069 -> Term.t 1069 1070 -> ui Lwd.root 1070 1071 -> unit ··· 1082 1083 (* FIXME Uses of [quick_sample] and [quick_release] should be replaced by 1083 1084 [sample] and [release] with the appropriate release management. *) 1084 1085 1085 - let cache = ref None 1086 - 1087 1086 let step 1088 1087 ?(await_read = await_read_unix) 1089 1088 ?(process_event = true) 1090 1089 ?(timeout = -1.0) 1091 1090 ~renderer 1091 + ~cache 1092 1092 term 1093 1093 root 1094 1094 = 1095 - Printf.eprintf "running step\n"; 1095 + Printf.eprintf "running step\n"; 1096 1096 let size = Term.size term in 1097 1097 let image = 1098 1098 if (not (Lwd.is_damaged root)) && !cache |> Option.is_some ··· 1105 1105 (* If we are already damaged then we should re-calculate*) 1106 1106 if Lwd.is_damaged root then stabilize () else image 1107 1107 in 1108 - stabilize () 1109 - 1110 - ) 1108 + stabilize ()) 1111 1109 in 1112 1110 cache := Some image; 1113 1111 Term.image term image; ··· 1165 1163 t -> 1166 1164 let quit = Lwd.observe (Lwd.get quit) in 1167 1165 let root = Lwd.observe ~on_invalidate t in 1166 + let cache = ref None in 1168 1167 let rec loop () = 1169 1168 let quit = Lwd.quick_sample quit in 1170 1169 if not quit 1171 1170 then ( 1172 - step ~process_event:true ?timeout:tick_period ~renderer term root; 1171 + step ~process_event:true ?timeout:tick_period ~renderer ~cache term root ; 1173 1172 tick (); 1174 1173 loop ()) 1175 1174 in
+3
forks/nottui/lib/nottui/nottui_main.mli
··· 374 374 : ?process_event:bool 375 375 -> ?timeout:float 376 376 -> renderer:Renderer.t 377 + -> cache: image option ref 377 378 -> Term.t 378 379 -> ui Lwd.root 379 380 -> unit ··· 412 413 ?process_event:bool 413 414 -> ?timeout:float 414 415 -> renderer:Renderer.t 416 + -> cache: image option ref 415 417 -> Term.t 416 418 -> ui Lwd.root 417 419 -> unit ··· 430 432 -> ?process_event:bool 431 433 -> ?timeout:float 432 434 -> renderer:Renderer.t 435 + -> cache: image option ref 433 436 -> Term.t 434 437 -> ui Lwd.root 435 438 -> unit
+88 -18
forks/nottui/lib/nottui_picos/nottui_picos.ml
··· 5 5 open Picos_std_finally 6 6 open Picos_std_event 7 7 open Picos_std_sync 8 + open Notty 9 + open Notty_unix 10 + 11 + (*Super simple method for tracking invalidations that occur outside of a computation using picos. 12 + We already track and apply invaldations that happen within a ui recompute 13 + *) 14 + module InvalidationTracker = struct 15 + type t = unit Picos.Computation.t ref 16 + 17 + let start_tracking tracker = tracker := Computation.create () 18 + let create () : t = Computation.create () |> ref 19 + let invalidated_evt tracker = Event.from_computation !tracker 20 + let invalidate (tracker : t) = Computation.finish !tracker 21 + end 22 + 23 + module It = InvalidationTracker 8 24 9 25 module Ui_loop = struct 10 - let step computation in_fd = 11 - Ui_loop.Internal.step ~await_read:(fun _ timeout -> 12 - let rec select () = 13 - let ret = 14 - Event.select 15 - [ Picos_io_select.on in_fd `R |> Event.map (fun x -> `Ready) 16 - (* This doesn't seem to be needed *) 17 - (* ; Picos_io_select.on in_fd `W |> Event.map (fun _ -> `Ready) *) 18 - ; Event.from_computation !computation |> Event.map (fun _ -> `LwdStateUpdate) 19 - ] 26 + let wait_for_event invalidation_tracker in_fd () = 27 + let rec select () = 28 + let ret = 29 + Event.select 30 + [ Picos_io_select.on in_fd `R |> Event.map (fun x -> `Ready) 31 + (* This doesn't seem to be needed *) 32 + (* ; Picos_io_select.on in_fd `W |> Event.map (fun _ -> `Ready) *) 33 + (*If our compution*) 34 + ; It.invalidated_evt invalidation_tracker 35 + |> Event.map (fun _ -> `LwdStateUpdate) 36 + ] 37 + in 38 + Printf.eprintf "done waiting\n"; 39 + ret 40 + in 41 + select () 42 + ;; 43 + 44 + let step 45 + ?(process_event = true) 46 + ?(timeout = -1.0) 47 + ~awaiter 48 + ~invalidation_tracker 49 + ~renderer 50 + ~cache 51 + term 52 + root 53 + = 54 + Printf.eprintf "running step\n"; 55 + let size = Term.size term in 56 + let image = 57 + if (not (Lwd.is_damaged root)) && !cache |> Option.is_some 58 + then !cache |> Option.get 59 + else ( 60 + let rec stabilize () = 61 + let tree = Lwd.quick_sample root in 62 + Renderer.update renderer size tree; 63 + It.start_tracking invalidation_tracker; 64 + let image = Renderer.image renderer in 65 + (* If we are already damaged then we should re-calculate*) 66 + if Lwd.is_damaged root then stabilize () else image 20 67 in 21 - Printf.eprintf "done waiting\n"; 22 - ret 68 + stabilize ()) 69 + in 70 + cache := Some image; 71 + Term.image term image; 72 + (* Now we wait for another event or the timeout*) 73 + if process_event 74 + then ( 75 + let wait_for_event () = 76 + match awaiter () with 77 + | `NotReady -> false 78 + | `Ready -> true 79 + | `LwdStateUpdate -> false 23 80 in 24 - select ()) 81 + (* for async I should extend this to include changed lwd.var values*) 82 + (* let has_event =Term.pending term in *) 83 + if wait_for_event () 84 + then ( 85 + match Term.event term with 86 + | `End -> () 87 + | `Resize _ -> () 88 + | #Unescape.event as event -> 89 + let event = (event : Unescape.event :> Ui.event) in 90 + ignore (Renderer.dispatch_event renderer event : [> `Handled | `Unhandled ]))) 25 91 ;; 26 92 27 93 let a = ref 0 ··· 34 100 then Picos_io.Unix.stdin 35 101 else Picos_io_fd.create ~dispose:false in_fd 36 102 in 37 - let trigger = ref (Computation.create ()) in 38 - let step = step trigger in_picos_fd in 103 + let invalidation_tracker = It.create () in 104 + (* let step = step trigger in_picos_fd in *) 39 105 a := !a + 1; 106 + let cache = ref None in 40 107 Ui_loop.Internal.run_with_term 41 - ~on_invalidate:(fun _ -> Computation.finish !trigger;) 42 - ~step 108 + ~on_invalidate:(fun _ -> It.invalidate invalidation_tracker) 109 + ~step: 110 + (step 111 + ~awaiter:(wait_for_event invalidation_tracker in_picos_fd) 112 + ~invalidation_tracker) 43 113 term 44 114 ;; 45 115 46 - let run = Ui_loop.Internal.run ~run_with_term ~tick_period:100.0 116 + let run = Ui_loop.Internal.run ~run_with_term ~tick_period:0.01 47 117 end