Skip to content

Commit

Permalink
Remove \1 and \2 that escape CSI before render
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed May 26, 2019
1 parent c6b7cad commit 64dc218
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/reline/line_editor.rb
Expand Up @@ -81,6 +81,7 @@ module CompletionState
MenuInfo = Struct.new('MenuInfo', :target, :list)

CSI_REGEXP = /\e\[(?:\d+;?)*[ABCDEFGHJKSTfminsuhl]/
NON_PRINTING_ESCAPES = "\1\2"

def initialize(config)
@config = config
Expand Down Expand Up @@ -164,6 +165,8 @@ def multiline_off
lines = [String.new(encoding: @encoding)]
height = 1
width = 0
prompt = prompt.tr(NON_PRINTING_ESCAPES, '')
str = str.tr(NON_PRINTING_ESCAPES, '')
rest = "#{prompt}#{str}".encode(Encoding::UTF_8)
loop do
break if rest.empty?
Expand Down Expand Up @@ -803,6 +806,7 @@ def finish
private def calculate_width(str, allow_csi = false)
if allow_csi
str = str.gsub(CSI_REGEXP, '')
str = str.tr(NON_PRINTING_ESCAPES, '')
end
str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |width, gc|
width + Reline::Unicode.get_mbchar_width(gc)
Expand Down

0 comments on commit 64dc218

Please sign in to comment.