diff options
author | tomoya ishida <[email protected]> | 2023-03-26 00:01:30 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-03-25 15:01:35 +0000 |
commit | 60ca800d4fc410ea9d49ef24dfb80577d4183f15 (patch) | |
tree | 7e68200a425aa23565fdc1478ccd51eeed887a5a /lib/reline/unicode.rb | |
parent | 9bc2dbd33cd25281fe14d01bbe5b460176db1010 (diff) |
[ruby/reline] Fix split_by_width to retain color sequences
(https://github.com/ruby/reline/pull/490)
* Fix split_by_width to retain color sequences
* Add OSC escape sequence testcase of Reline::Unicode.split_by_width
Diffstat (limited to 'lib/reline/unicode.rb')
-rw-r--r-- | lib/reline/unicode.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb index 6000c9f82a..de22d08581 100644 --- a/lib/reline/unicode.rb +++ b/lib/reline/unicode.rb @@ -160,16 +160,21 @@ class Reline::Unicode width = 0 rest = str.encode(Encoding::UTF_8) in_zero_width = false + seq = String.new(encoding: encoding) rest.scan(WIDTH_SCANNER) do |gc| case when gc[NON_PRINTING_START_INDEX] in_zero_width = true + lines.last << NON_PRINTING_START when gc[NON_PRINTING_END_INDEX] in_zero_width = false + lines.last << NON_PRINTING_END when gc[CSI_REGEXP_INDEX] lines.last << gc[CSI_REGEXP_INDEX] + seq << gc[CSI_REGEXP_INDEX] when gc[OSC_REGEXP_INDEX] lines.last << gc[OSC_REGEXP_INDEX] + seq << gc[OSC_REGEXP_INDEX] when gc[GRAPHEME_CLUSTER_INDEX] gc = gc[GRAPHEME_CLUSTER_INDEX] unless in_zero_width @@ -177,7 +182,7 @@ class Reline::Unicode if (width += mbchar_width) > max_width width = mbchar_width lines << nil - lines << String.new(encoding: encoding) + lines << seq.dup height += 1 end end |