Skip to content

Commit

Permalink
Cut out a method that calcs width including the escape sequence and p…
Browse files Browse the repository at this point in the history
…adding with spaces
  • Loading branch information
aycabta committed Sep 1, 2021
1 parent 21c795e commit 46c9d94
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,10 @@ def add_dialog_proc(name, p, context = nil)
end
end

private def padding_space_with_escape_sequences(str, width)
str + (' ' * (width - calculate_width(str, true)))
end

private def render_each_dialog(dialog, cursor_column)
if @in_pasting
dialog.contents = nil
Expand Down Expand Up @@ -651,8 +655,7 @@ def add_dialog_proc(name, p, context = nil)
bg_color = '46'
end
end
str = Reline::Unicode.take_range(item, 0, dialog.width)
str += ' ' * (dialog.width - calculate_width(str, true))
str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, dialog.width), dialog.width)
@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)
Expand Down Expand Up @@ -789,8 +792,7 @@ def add_dialog_proc(name, p, context = nil)
dialog_vertical_size.times do |i|
if i < visual_lines_under_dialog.size
Reline::IOGate.move_cursor_column(0)
width = calculate_width(visual_lines_under_dialog[i], true)
str = visual_lines_under_dialog[i] + (' ' * (dialog.width - width))
str = padding_space_with_escape_sequences(visual_lines_under_dialog[i], dialog.width)
@output.write "\e[39m\e[49m#{str}\e[39m\e[49m"
else
Reline::IOGate.move_cursor_column(dialog.column)
Expand Down

0 comments on commit 46c9d94

Please sign in to comment.