Skip to content

Commit

Permalink
Fix prompt width calculation bug. Test with colored prompt (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored May 2, 2024
1 parent c8d4802 commit 24aab01
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def wrapped_prompt_and_input_lines
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
Expand Down
4 changes: 2 additions & 2 deletions test/reline/yamatanooroti/multiline_repl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 24aab01

Please sign in to comment.