diff options
author | tomoya ishida <[email protected]> | 2024-10-25 01:36:35 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-10-24 16:36:39 +0000 |
commit | 979e447d7e27a5ee58f5756253a6783efb0b375b (patch) | |
tree | eca968cc63cec5bed323a68b74742195cc062ca4 /lib | |
parent | 1634280e1cd7cbe1f4523681b3dc4036c077256a (diff) |
[ruby/reline] nonprinting_start and nonprinting_end should be
removed
(https://github.com/ruby/reline/pull/771)
https://github.com/ruby/reline/commit/e36441652a
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/line_editor.rb | 4 | ||||
-rw-r--r-- | lib/reline/unicode.rb | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 96a6296ead..4d0eb393e9 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -464,7 +464,7 @@ class Reline::LineEditor def render_finished render_differential([], 0, 0) lines = @buffer_of_lines.size.times.map do |i| - line = prompt_list[i] + modified_lines[i] + line = Reline::Unicode.strip_non_printing_start_end(prompt_list[i]) + modified_lines[i] wrapped_lines, = split_by_width(line, screen_width) wrapped_lines.last.empty? ? "#{line} " : line end @@ -473,7 +473,7 @@ class Reline::LineEditor def print_nomultiline_prompt # Readline's test `TestRelineAsReadline#test_readline` requires first output to be prompt, not cursor reset escape sequence. - @output.write @prompt if @prompt && !@is_multiline + @output.write Reline::Unicode.strip_non_printing_start_end(@prompt) if @prompt && !@is_multiline end def render diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb index 0ec815aeea..642f4d7e36 100644 --- a/lib/reline/unicode.rb +++ b/lib/reline/unicode.rb @@ -132,10 +132,8 @@ class Reline::Unicode case when non_printing_start in_zero_width = true - lines.last << NON_PRINTING_START when non_printing_end in_zero_width = false - lines.last << NON_PRINTING_END when csi lines.last << csi unless in_zero_width @@ -147,7 +145,7 @@ class Reline::Unicode end when osc lines.last << osc - seq << osc + seq << osc unless in_zero_width when gc unless in_zero_width mbchar_width = get_mbchar_width(gc) @@ -170,6 +168,10 @@ class Reline::Unicode [lines, height] end + def self.strip_non_printing_start_end(prompt) + prompt.gsub(/\x01([^\x02]*)(?:\x02|\z)/) { $1 } + end + # Take a chunk of a String cut by width with escape sequences. def self.take_range(str, start_col, max_width) take_mbchar_range(str, start_col, max_width).first @@ -189,10 +191,8 @@ class Reline::Unicode case when non_printing_start in_zero_width = true - chunk << NON_PRINTING_START when non_printing_end in_zero_width = false - chunk << NON_PRINTING_END when csi has_csi = true chunk << csi |