Skip to content

Commit 21c795e

Browse files
committed
Calc width including escape sequences and padding with spaces correctly
1 parent 9b812d5 commit 21c795e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/reline/line_editor.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ def add_dialog_proc(name, p, context = nil)
651651
bg_color = '46'
652652
end
653653
end
654-
@output.write "\e[#{bg_color}m%-#{dialog.width}s\e[49m" % Reline::Unicode.take_range(item, 0, dialog.width)
654+
str = Reline::Unicode.take_range(item, 0, dialog.width)
655+
str += ' ' * (dialog.width - calculate_width(str, true))
656+
@output.write "\e[#{bg_color}m#{str}\e[49m"
655657
Reline::IOGate.move_cursor_column(dialog.column)
656658
move_cursor_down(1) if i < (dialog.contents.size - 1)
657659
end

0 commit comments

Comments
 (0)