From a669b9661eaf9623160e2f2010f24b0b9fd5f01a Mon Sep 17 00:00:00 2001 From: aycabta Date: Wed, 1 Sep 2021 17:53:17 +0900 Subject: [PATCH] [ruby/reline] Calc width including escape sequences and padding with spaces correctly https://github.com/ruby/reline/commit/21c795e97f --- lib/reline/line_editor.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 9ea0f0731b..9df04f14f4 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -651,7 +651,9 @@ class Reline::LineEditor bg_color = '46' end end - @output.write "\e[#{bg_color}m%-#{dialog.width}s\e[49m" % Reline::Unicode.take_range(item, 0, dialog.width) + str = Reline::Unicode.take_range(item, 0, dialog.width) + str += ' ' * (dialog.width - calculate_width(str, true)) + @output.write "\e[#{bg_color}m#{str}\e[49m" Reline::IOGate.move_cursor_column(dialog.column) move_cursor_down(1) if i < (dialog.contents.size - 1) end