From eb82ea62186fb9c9b2941b04ee12d0dcba112607 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Thu, 2 May 2024 15:06:27 +0900 Subject: [PATCH] [ruby/reline] Fix prompt width calculation bug. Test with colored prompt (https://github.com/ruby/reline/pull/695) https://github.com/ruby/reline/commit/24aab01cbc --- lib/reline/line_editor.rb | 2 +- test/reline/yamatanooroti/multiline_repl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 123dca0aac..07a9cc6af0 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -387,7 +387,7 @@ class Reline::LineEditor next cached end *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] } end end diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl index eba410f6dd..8b82be60f4 100755 --- a/test/reline/yamatanooroti/multiline_repl +++ b/test/reline/yamatanooroti/multiline_repl @@ -12,7 +12,7 @@ opt = OptionParser.new opt.on('--dynamic-prompt') { Reline.prompt_proc = proc { |lines| lines.each_with_index.map { |l, i| - '[%04d]> ' % i + "\e[1m[%04d]>\e[m " % i } } } @@ -222,7 +222,7 @@ rescue end begin - prompt = ENV['RELINE_TEST_PROMPT'] || 'prompt> ' + prompt = ENV['RELINE_TEST_PROMPT'] || "\e[1mprompt>\e[m " puts 'Multiline REPL.' while code = Reline.readmultiline(prompt, true) { |code| TerminationChecker.terminated?(code) } case code.chomp