Skip to content

Commit

Permalink
Fix rendering bug of ^D
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed May 27, 2019
1 parent 9c136f3 commit 1d301ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/reline.rb
Expand Up @@ -254,6 +254,10 @@ def retrieve_completion_block(line, byte_pointer)
[preposing, block, postposing]
end

def eof?
@@line_editor.eof?
end

def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
unless confirm_multiline_termination
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
Expand Down
44 changes: 31 additions & 13 deletions lib/reline/line_editor.rb
Expand Up @@ -104,6 +104,10 @@ def finalize
Signal.trap('SIGINT', @old_trap)
end

def eof?
@eof
end

def reset_variables(prompt = '', encoding = Encoding.default_external)
@prompt = prompt
@encoding = encoding
Expand All @@ -125,6 +129,7 @@ def reset_variables(prompt = '', encoding = Encoding.default_external)
@first_prompt = true
@searching_prompt = nil
@first_char = true
@eof = false
reset_line
end

Expand Down Expand Up @@ -389,17 +394,21 @@ def rerender # TODO: support physical and logical lines
@rerender_all = false
end
line = modify_lines(whole_lines)[@line_index]
if !@is_multiline
render_partial(prompt, prompt_width, line)
scroll_down(1)
Reline::IOGate.move_cursor_column(0)
Reline::IOGate.erase_after_cursor
elsif !finished?
render_partial(prompt, prompt_width, line)
if @is_multiline
if finished?
scroll_down(1)
Reline::IOGate.move_cursor_column(0)
Reline::IOGate.erase_after_cursor
else
render_partial(prompt, prompt_width, line)
end
else
scroll_down(1) unless whole_lines.last.empty?
Reline::IOGate.move_cursor_column(0)
Reline::IOGate.erase_after_cursor
render_partial(prompt, prompt_width, line)
if finished?
scroll_down(1)
Reline::IOGate.move_cursor_column(0)
Reline::IOGate.erase_after_cursor
end
end
end

Expand Down Expand Up @@ -1194,8 +1203,11 @@ def finish
private def em_delete_or_list(key)
if @line.empty?
@line = nil
scroll_down(@highest_in_all - @first_line_started_from)
if @buffer_of_lines.size > 1
scroll_down(@highest_in_all - @first_line_started_from)
end
Reline::IOGate.move_cursor_column(0)
@eof = true
finish
elsif @byte_pointer < @line.bytesize
splitted_last = @line.byteslice(@byte_pointer, @line.bytesize)
Expand Down Expand Up @@ -1488,17 +1500,23 @@ def finish
private def vi_end_of_transmission(key)
if @line.empty?
@line = nil
scroll_down(@highest_in_all - @first_line_started_from)
if @buffer_of_lines.size > 1
scroll_down(@highest_in_all - @first_line_started_from)
end
Reline::IOGate.move_cursor_column(0)
@eof = true
finish
end
end

private def vi_list_or_eof(key)
if @line.empty?
@line = nil
scroll_down(@highest_in_all - @first_line_started_from)
if @buffer_of_lines.size > 1
scroll_down(@highest_in_all - @first_line_started_from)
end
Reline::IOGate.move_cursor_column(0)
@eof = true
finish
else
# TODO: list
Expand Down

0 comments on commit 1d301ac

Please sign in to comment.