mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] Treat prompt correctly when Reline.prompt_proc isn't set
https://github.com/ruby/reline/commit/9c9ba0eff3
This commit is contained in:
parent
ce389ade45
commit
f36dc2b6de
2 changed files with 22 additions and 6 deletions
|
@ -133,7 +133,7 @@ class Reline::LineEditor
|
|||
if @line_index.zero?
|
||||
0
|
||||
else
|
||||
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list)
|
||||
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt)
|
||||
end
|
||||
if @prompt_proc
|
||||
prompt = prompt_list[@line_index]
|
||||
|
@ -207,10 +207,10 @@ class Reline::LineEditor
|
|||
@is_multiline = false
|
||||
end
|
||||
|
||||
private def calculate_height_by_lines(lines, prompt_list)
|
||||
private def calculate_height_by_lines(lines, prompt)
|
||||
result = 0
|
||||
prompt_list = prompt.is_a?(Array) ? prompt : nil
|
||||
lines.each_with_index { |line, i|
|
||||
prompt = ''
|
||||
prompt = prompt_list[i] if prompt_list and prompt_list[i]
|
||||
result += calculate_height_by_width(calculate_width(prompt, true) + calculate_width(line))
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ class Reline::LineEditor
|
|||
new_lines = whole_lines
|
||||
end
|
||||
prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt)
|
||||
all_height = calculate_height_by_lines(new_lines, prompt_list)
|
||||
all_height = calculate_height_by_lines(new_lines, prompt_list || prompt)
|
||||
diff = all_height - @highest_in_all
|
||||
move_cursor_down(@highest_in_all - @first_line_started_from - @started_from - 1)
|
||||
if diff > 0
|
||||
|
@ -383,7 +383,7 @@ class Reline::LineEditor
|
|||
if @line_index.zero?
|
||||
0
|
||||
else
|
||||
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list)
|
||||
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt)
|
||||
end
|
||||
if @prompt_proc
|
||||
prompt = prompt_list[@line_index]
|
||||
|
@ -442,7 +442,7 @@ class Reline::LineEditor
|
|||
if @line_index.zero?
|
||||
0
|
||||
else
|
||||
calculate_height_by_lines(new_buffer[0..(@line_index - 1)], prompt_list)
|
||||
calculate_height_by_lines(new_buffer[0..(@line_index - 1)], prompt_list || prompt)
|
||||
end
|
||||
@started_from = calculate_height_by_width(prompt_width + @cursor) - 1
|
||||
move_cursor_down(@first_line_started_from + @started_from)
|
||||
|
|
|
@ -100,6 +100,22 @@ begin
|
|||
EOC
|
||||
end
|
||||
|
||||
def test_finish_autowrapped_line_in_the_middle_of_multilines
|
||||
start_terminal(30, 16, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl})
|
||||
sleep 0.5
|
||||
write("<<~EOM\n ABCDEFG\nEOM\n")
|
||||
close
|
||||
assert_screen(<<~'EOC')
|
||||
Multiline REPL.
|
||||
prompt> <<~EOM
|
||||
prompt> ABCDEF
|
||||
G
|
||||
prompt> EOM
|
||||
=> "ABCDEFG\n"
|
||||
prompt>
|
||||
EOC
|
||||
end
|
||||
|
||||
def test_prompt
|
||||
File.open(@inputrc_file, 'w') do |f|
|
||||
f.write <<~'LINES'
|
||||
|
|
Loading…
Add table
Reference in a new issue