1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Calculate prompt width correctly

This commit is contained in:
aycabta 2019-10-17 02:19:01 +09:00
parent e26c6d4ab8
commit db84123600

View file

@ -64,11 +64,13 @@ class Reline::LineEditor
if @prompt_proc
prompt_list = @prompt_proc.(buffer)
prompt_list[@line_index] = special_prompt if special_prompt
prompt_list.map!{ special_prompt } if @searching_prompt
prompt = prompt_list[@line_index]
prompt_width = calculate_width(prompt, true)
[prompt, prompt_list]
[prompt, prompt_width, prompt_list]
else
[prompt, nil]
prompt_width = calculate_width(prompt, true)
[prompt, prompt_width, nil]
end
end
@ -103,7 +105,7 @@ class Reline::LineEditor
end
back = 0
new_buffer = whole_lines
prompt, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt)
prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt)
new_buffer.each_with_index do |line, index|
prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc
width = prompt_width + calculate_width(line)
@ -335,7 +337,7 @@ class Reline::LineEditor
Reline::IOGate.clear_screen
@cleared = false
back = 0
prompt, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt)
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt)
modify_lines(whole_lines).each_with_index do |line, index|
if @prompt_proc
pr = prompt_list[index]
@ -361,7 +363,7 @@ class Reline::LineEditor
else
new_lines = whole_lines
end
prompt, prompt_list = check_multiline_prompt(new_lines, prompt, special_prompt)
prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt, special_prompt)
all_height = new_lines.inject(0) { |result, line|
result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list
}
@ -425,7 +427,7 @@ class Reline::LineEditor
Reline::IOGate.move_cursor_column(0)
back = 0
new_buffer = whole_lines
prompt, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt)
prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer, prompt, special_prompt)
new_buffer.each_with_index do |line, index|
prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc
width = prompt_width + calculate_width(line)
@ -477,7 +479,7 @@ class Reline::LineEditor
end
line = modify_lines(whole_lines)[@line_index]
if @is_multiline
prompt, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt)
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt, special_prompt)
if finished?
# Always rerender on finish because output_modifier_proc may return a different output.
render_partial(prompt, prompt_width, line)