Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering bug of nomultiline prompt #730

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading