summaryrefslogtreecommitdiff
path: root/lib/reline
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-09-12 01:51:26 +0900
committeraycabta <aycabta@gmail.com>2020-09-12 08:35:52 +0900
commitf36dc2b6de54ec6b82766d2134a782d12628a2b9 (patch)
tree8c5f992aeaaeaf0fc47ea4159d49f98f42817bc9 /lib/reline
parentce389ade45f412351d7c91db60eaa5e19fcd8c5f (diff)
[ruby/reline] Treat prompt correctly when Reline.prompt_proc isn't set
https://github.com/ruby/reline/commit/9c9ba0eff3
Diffstat (limited to 'lib/reline')
-rw-r--r--lib/reline/line_editor.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index edea2fa3d7..9bdccae9c9 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -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)