Skip to content

Commit

Permalink
Fix rendering bug of nomultiline prompt (#730)
Browse files Browse the repository at this point in the history
Fix bug of `print('a'*10); Reline.readline('>')` wrong rendering
  • Loading branch information
tompng authored Jul 12, 2024
1 parent be45660 commit c0469a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def readline(prompt = '', add_hist = false)
end
end

line_editor.print_nomultiline_prompt(prompt)
line_editor.print_nomultiline_prompt
line_editor.update_dialogs
line_editor.rerender

Expand Down
8 changes: 2 additions & 6 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,9 @@ def render_full_content
@output.puts lines.map { |l| "#{l}\r\n" }.join
end

def print_nomultiline_prompt(prompt)
return unless prompt && !@is_multiline

def print_nomultiline_prompt
# Readline's test `TestRelineAsReadline#test_readline` requires first output to be prompt, not cursor reset escape sequence.
@rendered_screen.lines = [[[0, Reline::Unicode.calculate_width(prompt, true), prompt]]]
@rendered_screen.cursor_y = 0
@output.write prompt
@output.write @prompt if @prompt && !@is_multiline
end

def render_differential
Expand Down
18 changes: 18 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,24 @@ def test_exit_with_ctrl_d
EOC
end

def test_print_before_readline
code = <<~RUBY
puts 'Multiline REPL.'
2.times do
print 'a' * 10
Reline.readline '>'
end
RUBY
start_terminal(6, 30, ['ruby', "-I#{@pwd}/lib", '-rreline', '-e', code], startup_message: 'Multiline REPL.')
write "x\n"
close
assert_screen(<<~EOC)
Multiline REPL.
>x
>
EOC
end

def test_thread_safe
start_terminal(6, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
write("[Thread.new{Reline.readline'>'},Thread.new{Reline.readmultiline('>'){true}}].map(&:join).size\n")
Expand Down

0 comments on commit c0469a1

Please sign in to comment.