mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Remove \1 and \2 that escape CSI before render
This commit is contained in:
parent
c6b7cad5c9
commit
64dc21830a
1 changed files with 4 additions and 0 deletions
|
@ -81,6 +81,7 @@ class Reline::LineEditor
|
||||||
MenuInfo = Struct.new('MenuInfo', :target, :list)
|
MenuInfo = Struct.new('MenuInfo', :target, :list)
|
||||||
|
|
||||||
CSI_REGEXP = /\e\[(?:\d+;?)*[ABCDEFGHJKSTfminsuhl]/
|
CSI_REGEXP = /\e\[(?:\d+;?)*[ABCDEFGHJKSTfminsuhl]/
|
||||||
|
NON_PRINTING_ESCAPES = "\1\2"
|
||||||
|
|
||||||
def initialize(config)
|
def initialize(config)
|
||||||
@config = config
|
@config = config
|
||||||
|
@ -164,6 +165,8 @@ class Reline::LineEditor
|
||||||
lines = [String.new(encoding: @encoding)]
|
lines = [String.new(encoding: @encoding)]
|
||||||
height = 1
|
height = 1
|
||||||
width = 0
|
width = 0
|
||||||
|
prompt = prompt.tr(NON_PRINTING_ESCAPES, '')
|
||||||
|
str = str.tr(NON_PRINTING_ESCAPES, '')
|
||||||
rest = "#{prompt}#{str}".encode(Encoding::UTF_8)
|
rest = "#{prompt}#{str}".encode(Encoding::UTF_8)
|
||||||
loop do
|
loop do
|
||||||
break if rest.empty?
|
break if rest.empty?
|
||||||
|
@ -803,6 +806,7 @@ class Reline::LineEditor
|
||||||
private def calculate_width(str, allow_csi = false)
|
private def calculate_width(str, allow_csi = false)
|
||||||
if allow_csi
|
if allow_csi
|
||||||
str = str.gsub(CSI_REGEXP, '')
|
str = str.gsub(CSI_REGEXP, '')
|
||||||
|
str = str.tr(NON_PRINTING_ESCAPES, '')
|
||||||
end
|
end
|
||||||
str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |width, gc|
|
str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |width, gc|
|
||||||
width + Reline::Unicode.get_mbchar_width(gc)
|
width + Reline::Unicode.get_mbchar_width(gc)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue