[ruby/reline] Improve OSC sequence regexp. OSC sequence can end with
ST(ESC\) and it should not to include \a and \e inside. (https://github.com/ruby/reline/pull/527) https://github.com/ruby/reline/commit/a88052adec
This commit is contained in:
parent
8c8d068016
commit
e26908dc4b
@ -38,7 +38,7 @@ class Reline::Unicode
|
||||
NON_PRINTING_START = "\1"
|
||||
NON_PRINTING_END = "\2"
|
||||
CSI_REGEXP = /\e\[[\d;]*[ABCDEFGHJKSTfminsuhl]/
|
||||
OSC_REGEXP = /\e\]\d+(?:;[^;]+)*\a/
|
||||
OSC_REGEXP = /\e\]\d+(?:;[^;\a\e]+)*(?:\a|\e\\)/
|
||||
WIDTH_SCANNER = /\G(?:(#{NON_PRINTING_START})|(#{NON_PRINTING_END})|(#{CSI_REGEXP})|(#{OSC_REGEXP})|(\X))/o
|
||||
|
||||
def self.get_mbchar_byte_size_by_first_char(c)
|
||||
|
@ -18,6 +18,17 @@ class Reline::Unicode::Test < Reline::TestCase
|
||||
assert_equal 2, Reline::Unicode.calculate_width('√', true)
|
||||
end
|
||||
|
||||
def test_csi_regexp
|
||||
csi_sequences = ["\e[m", "\e[1m", "\e[12;34m", "\e[12;34H"]
|
||||
assert_equal(csi_sequences, "text#{csi_sequences.join('text')}text".scan(Reline::Unicode::CSI_REGEXP))
|
||||
end
|
||||
|
||||
def test_osc_regexp
|
||||
osc_sequences = ["\e]1\a", "\e]0;OSC\a", "\e]1\e\\", "\e]0;OSC\e\\"]
|
||||
separator = "text\atext"
|
||||
assert_equal(osc_sequences, "#{separator}#{osc_sequences.join(separator)}#{separator}".scan(Reline::Unicode::OSC_REGEXP))
|
||||
end
|
||||
|
||||
def test_split_by_width
|
||||
assert_equal [['abc', nil, 'de'], 2], Reline::Unicode.split_by_width('abcde', 3)
|
||||
assert_equal [['abc', nil, 'def', nil, ''], 3], Reline::Unicode.split_by_width('abcdef', 3)
|
||||
|
Loading…
x
Reference in New Issue
Block a user