diff options
author | aycabta <aycabta@gmail.com> | 2021-09-01 18:00:44 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-09-01 18:05:30 +0900 |
commit | acf11b94d2e70d5195ae7391f009a3040e6f0e24 (patch) | |
tree | d73228b01ad698a8239eeca55292a125b09d7fb0 /lib | |
parent | a669b9661eaf9623160e2f2010f24b0b9fd5f01a (diff) |
[ruby/reline] Cut out a method that calcs width including the escape sequence and padding with spaces
https://github.com/ruby/reline/commit/46c9d944e5
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/line_editor.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 9df04f14f4..0c23e67ebd 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -582,6 +582,10 @@ class Reline::LineEditor 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 @@ -651,8 +655,7 @@ class Reline::LineEditor 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) @@ -789,8 +792,7 @@ class Reline::LineEditor 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) |