[ruby/reline] Fix prompt width calculation bug. Test with colored

prompt
(https://github.com/ruby/reline/pull/695)

24aab01cbc
This commit is contained in:
tomoya ishida 2024-05-02 15:06:27 +09:00 committed by git
parent ed5a7a59c0
commit eb82ea6218
2 changed files with 3 additions and 3 deletions

View file

@ -387,7 +387,7 @@ class Reline::LineEditor
next cached next cached
end end
*wrapped_prompts, code_line_prompt = split_by_width(prompt, width).first.compact *wrapped_prompts, code_line_prompt = split_by_width(prompt, width).first.compact
wrapped_lines = split_by_width(line, width, offset: calculate_width(code_line_prompt)).first.compact wrapped_lines = split_by_width(line, width, offset: calculate_width(code_line_prompt, true)).first.compact
wrapped_prompts.map { |p| [p, ''] } + [[code_line_prompt, wrapped_lines.first]] + wrapped_lines.drop(1).map { |c| ['', c] } wrapped_prompts.map { |p| [p, ''] } + [[code_line_prompt, wrapped_lines.first]] + wrapped_lines.drop(1).map { |c| ['', c] }
end end
end end

View file

@ -12,7 +12,7 @@ opt = OptionParser.new
opt.on('--dynamic-prompt') { opt.on('--dynamic-prompt') {
Reline.prompt_proc = proc { |lines| Reline.prompt_proc = proc { |lines|
lines.each_with_index.map { |l, i| lines.each_with_index.map { |l, i|
'[%04d]> ' % i "\e[1m[%04d]>\e[m " % i
} }
} }
} }
@ -222,7 +222,7 @@ rescue
end end
begin begin
prompt = ENV['RELINE_TEST_PROMPT'] || 'prompt> ' prompt = ENV['RELINE_TEST_PROMPT'] || "\e[1mprompt>\e[m "
puts 'Multiline REPL.' puts 'Multiline REPL.'
while code = Reline.readmultiline(prompt, true) { |code| TerminationChecker.terminated?(code) } while code = Reline.readmultiline(prompt, true) { |code| TerminationChecker.terminated?(code) }
case code.chomp case code.chomp