Skip to content

Commit

Permalink
Hide cursor while rendering to avoid flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
nojb committed Apr 28, 2024
1 parent d09e233 commit ac35a9b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/down.ml
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,10 @@ module Prompt = struct
| false -> acc
in
let ui = String.concat "" (List.rev acc) in
clear_ui p; p.output ui;
p.output Tty.cursor_hide;
clear_ui p;
p.output ui;
p.output Tty.cursor_show;
if active then (p.last_cr <- cr; p.last_max_r <- max_r)
let render_id_complete p prefix candidates =
Expand Down
2 changes: 2 additions & 0 deletions src/down_std.ml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ module Tty = struct
let cursor_forward n =
if n = 0 then "" else String.concat "" ["\x1B["; string_of_int n; "C"]

let cursor_hide = "\x1B[?25l"
let cursor_show = "\x1B[?25h"
let cursor_origin = "\x1B[H"
let clear_screen = "\x1B[2J"

Expand Down
6 changes: 6 additions & 0 deletions src/down_std.mli
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ module Tty : sig
val cursor_forward : int -> string
(** [cursor_forward n] moves cursor by [n] columns. *)

val cursor_hide : string
(** [cursor_hide] hides the cursor. *)

val cursor_show : string
(** [cursor_show] shows the cursor. *)

val cursor_origin : string
(** [cursor_origin] moves cursor to the top-left origin. *)

Expand Down

0 comments on commit ac35a9b

Please sign in to comment.