Skip to content

Commit

Permalink
Hide cursor only when updating screen. Frequent hide&show makes curso…
Browse files Browse the repository at this point in the history
…r flickering.
  • Loading branch information
tompng committed Jan 4, 2024
1 parent 835c45e commit 0b421c5
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def reset(prompt = '', encoding:)
def resize
return unless @resized

Reline::IOGate.hide_cursor
@screen_size = Reline::IOGate.get_screen_size
@resized = false
scroll_into_view
Expand All @@ -154,18 +153,15 @@ def resize
@cursor_y = 0
@rendered_screen_cache = nil
render_differential
Reline::IOGate.show_cursor
end

def set_signal_handlers
@old_trap = Signal.trap('INT') {
Reline::IOGate.hide_cursor
clear_dialogs
scrolldown = render_differential
Reline::IOGate.scroll_down scrolldown
Reline::IOGate.move_cursor_column 0
@rendered_screen_cache = nil
Reline::IOGate.show_cursor
case @old_trap
when 'DEFAULT', 'SYSTEM_DEFAULT'
raise Interrupt
Expand Down Expand Up @@ -488,23 +484,27 @@ def render_differential
end
end

num_lines = [[new_lines.size, rendered_lines.size].max, screen_height].min
scroll_down(num_lines - 1 - @cursor_y) if (num_lines - 1 - @cursor_y) > 0
@cursor_y = num_lines - 1
num_lines.times do |i|
rendered_line = rendered_lines[i] || []
line_to_render = new_lines[i] || []
next if rendered_line == line_to_render

Reline::IOGate.move_cursor_down i - @cursor_y
@cursor_y = i
unless rendered_lines[i]
Reline::IOGate.move_cursor_column 0
Reline::IOGate.erase_after_cursor
if new_lines != rendered_lines
Reline::IOGate.hide_cursor
num_lines = [[new_lines.size, rendered_lines.size].max, screen_height].min
scroll_down(num_lines - 1 - @cursor_y) if (num_lines - 1 - @cursor_y) > 0
@cursor_y = num_lines - 1
num_lines.times do |i|
rendered_line = rendered_lines[i] || []
line_to_render = new_lines[i] || []
next if rendered_line == line_to_render

Reline::IOGate.move_cursor_down i - @cursor_y
@cursor_y = i
unless rendered_lines[i]
Reline::IOGate.move_cursor_column 0
Reline::IOGate.erase_after_cursor
end
render_line_differential(rendered_line, line_to_render)
end
render_line_differential(rendered_line, line_to_render)
@rendered_screen_cache = new_lines
Reline::IOGate.show_cursor
end
@rendered_screen_cache = new_lines
y = editor_cursor_y - screen_scroll_top
Reline::IOGate.move_cursor_column editor_cursor_x
Reline::IOGate.move_cursor_down y - @cursor_y
Expand All @@ -525,11 +525,9 @@ def rest_height
end

def rerender_all
Reline::IOGate.hide_cursor
process_insert(force: true)
handle_cleared
render_differential unless @in_pasting
Reline::IOGate.show_cursor
end

def handle_cleared
Expand All @@ -546,7 +544,6 @@ def handle_cleared
end

def rerender
Reline::IOGate.hide_cursor
finished = finished?
handle_cleared
if finished
Expand All @@ -555,7 +552,6 @@ def rerender
elsif !@in_pasting
render_differential
end
Reline::IOGate.show_cursor
end

class DialogProcScope
Expand Down

0 comments on commit 0b421c5

Please sign in to comment.