Skip to content

Commit

Permalink
Simplify rerender call from reline.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 21, 2024
1 parent fcf9e0f commit 3cfc6f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
20 changes: 6 additions & 14 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def initialize
@dialog_proc_list = {}
yield self
@completion_quote_character = nil
@bracketed_paste_finished = false
end

def io_gate
Expand Down Expand Up @@ -346,24 +345,18 @@ def readline(prompt = '', add_hist = false)

begin
line_editor.set_signal_handlers
prev_pasting_state = false
loop do
prev_pasting_state = io_gate.in_pasting?
read_io(config.keyseq_timeout) { |inputs|
line_editor.set_pasting_state(io_gate.in_pasting?)
inputs.each { |c| line_editor.update(c) }
line_editor.rerender
if @bracketed_paste_finished
line_editor.rerender_all
@bracketed_paste_finished = false
end
}
if prev_pasting_state == true and not io_gate.in_pasting? and not line_editor.finished?
line_editor.set_pasting_state(false)
prev_pasting_state = false
line_editor.rerender_all
if line_editor.finished?
line_editor.render_finished
break
else
line_editor.set_pasting_state(io_gate.in_pasting?)
line_editor.rerender
end
break if line_editor.finished?
end
io_gate.move_cursor_column(0)
rescue Errno::EIO
Expand Down Expand Up @@ -398,7 +391,6 @@ def readline(prompt = '', add_hist = false)
c = io_gate.getc(Float::INFINITY)
if c == -1
result = :unmatched
@bracketed_paste_finished = true
else
buffer << c
result = key_stroke.match_status(buffer)
Expand Down
20 changes: 7 additions & 13 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def io_gate
end

def set_pasting_state(in_pasting)
process_insert(force: true) if @in_pasting && !in_pasting
@in_pasting = in_pasting
end

Expand Down Expand Up @@ -422,6 +423,11 @@ def update_dialogs(key = nil)
end
end

def render_finished
clear_rendered_lines
render_full_content
end

def clear_rendered_lines
Reline::IOGate.move_cursor_up @cursor_y
Reline::IOGate.move_cursor_column 0
Expand Down Expand Up @@ -524,12 +530,6 @@ def rest_height
screen_height - @cursor_y - @cursor_base_y - 1
end

def rerender_all
process_insert(force: true)
handle_cleared
render_differential unless @in_pasting
end

def handle_cleared
return unless @cleared

Expand All @@ -544,14 +544,8 @@ def handle_cleared
end

def rerender
finished = finished?
handle_cleared
if finished
clear_rendered_lines
render_full_content
elsif !@in_pasting
render_differential
end
render_differential unless @in_pasting
end

class DialogProcScope
Expand Down

0 comments on commit 3cfc6f5

Please sign in to comment.