Skip to content

Commit cab34ac

Browse files
committed
delay UI updates by 40ms, improves pasting speed (and potential deadlocks)
1 parent 63e7212 commit cab34ac

3 files changed

Lines changed: 29 additions & 22 deletions

File tree

.merlin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PKG lwt
1414
PKG sexplib
1515
PKG hex
1616
PKG nocrypto
17-
PKG notty
17+
PKG notty notty.lwt
1818
PKG ptime
1919
PKG ptime.clock.os
2020
PKG ppx_sexp_conv

bin/jackline.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ let start_client cfgdir debug unicode fd_gui fd_nfy () =
144144
Lwt.async (Cli_input.read_terminal term ui_mvar input_mvar) ;
145145
(* main loop *)
146146
let size = Notty_lwt.Term.size term in
147-
Cli_client.loop term size ui_mvar input_mvar state >>= fun state ->
147+
Cli_client.loop term size Lwt_engine.fake_event ui_mvar input_mvar state >>= fun state ->
148148

149149
closing () >>= fun () ->
150150

cli/cli_client.ml

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -361,44 +361,51 @@ let quit state =
361361
Lwt_list.iter_s send_out otr_sessions)
362362
!xmpp_session
363363

364+
(* how should I know what is smooth? *)
365+
let redraw_interval = 0.04
366+
364367
(* this is rendering and drawing stuff to terminal, waiting for updates of the ui_mvar... *)
365-
let rec loop term size mvar input_mvar state =
368+
let rec loop term size redrawer mvar input_mvar state =
366369
let reset state =
367370
let buddies = Contact.fold (fun _ b acc -> Contact.reset b :: acc) state.contacts [] in
368371
List.iter (Contact.replace_contact state.contacts) buddies
369372
in
370-
let image, cursorc =
371-
try
372-
render_state size state
373-
with e ->
374-
let e = A.(fg red), (Printexc.to_string e)
375-
and note = A.empty,
376-
"While trying to render the UI. Try to scroll to another buddy (Page \
377-
Up/Down), switch rendering of buddy list (F12), or clear this \
378-
buddies messages (/clear<ret>); please report this bug \
379-
(including the offending characters and the error message)\n"
373+
Lwt_engine.stop_event redrawer ;
374+
let redraw = Lwt_engine.on_timer redraw_interval false (fun _ ->
375+
let image, cursorc =
376+
try
377+
render_state size state
378+
with e ->
379+
let e = A.(fg red), (Printexc.to_string e)
380+
and note =
381+
"While trying to render the UI. Try to scroll to another buddy \
382+
(Page Up/Down), switch rendering of buddy list (F12), or clear \
383+
this buddies messages (/clear<ret>); please report this bug \
384+
(including the offending characters and the error message)\n"
385+
in
386+
let w = fst size in
387+
(render_wrapped_list true w [e ; A.empty, note], 1)
380388
in
381-
let w = fst size in
382-
(render_wrapped_list true w [e ; note], 1)
389+
Lwt.async (fun () ->
390+
Notty_lwt.Term.image term image >>= fun () ->
391+
Notty_lwt.Term.cursor term (Some (cursorc, snd size))))
383392
in
384-
Notty_lwt.Term.image term image >>= fun () ->
385-
Notty_lwt.Term.cursor term (Some (cursorc, snd size)) >>= fun () ->
386393
Lwt_mvar.take mvar >>= fun action ->
387394
Lwt.catch (fun () -> action state)
388395
(fun exn ->
389396
add_status state (`Local ((`Full state.config.Xconfig.jid), "error")) (Printexc.to_string exn) ;
390397
Lwt.return (`Failure state)) >>= function
391-
| `Ok state -> loop term size mvar input_mvar state
392-
| `Resize size -> loop term size mvar input_mvar state
393-
| `Disconnect state -> reset state ; loop term size mvar input_mvar state
398+
| `Ok state -> loop term size redraw mvar input_mvar state
399+
| `Resize size -> loop term size redraw mvar input_mvar state
400+
| `Disconnect state -> reset state ; loop term size redraw mvar input_mvar state
394401
| `Failure state ->
395402
reset state ;
396403
ignore (Lwt_engine.on_timer 10. false
397404
(fun _ -> Lwt.async (fun () -> Lwt_mvar.put state.connect_mvar Reconnect))) ;
398-
loop term size mvar input_mvar state
405+
loop term size redraw mvar input_mvar state
399406
| `Ask c ->
400407
c state input_mvar mvar >>= fun s ->
401-
loop term size mvar input_mvar s
408+
loop term size redraw mvar input_mvar s
402409
| `Quit state ->
403410
quit state >>= fun () ->
404411
Lwt.return state

0 commit comments

Comments
 (0)