diff options
| author | aycabta <aycabta@gmail.com> | 2019-05-27 05:01:04 +0900 |
|---|---|---|
| committer | aycabta <aycabta@gmail.com> | 2019-05-27 05:01:18 +0900 |
| commit | 64dc21830aa60dc757df48c715a73f704eed43e0 (patch) | |
| tree | 75f745c97776a4748fd43026e08cc375c26568ab | |
| parent | c6b7cad5c903fa957c274d233c15fdcb3e4a9623 (diff) | |
Remove \1 and \2 that escape CSI before render
| -rw-r--r-- | lib/reline/line_editor.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index af634da650..f4e012688e 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -81,6 +81,7 @@ class Reline::LineEditor MenuInfo = Struct.new('MenuInfo', :target, :list) CSI_REGEXP = /\e\[(?:\d+;?)*[ABCDEFGHJKSTfminsuhl]/ + NON_PRINTING_ESCAPES = "\1\2" def initialize(config) @config = config @@ -164,6 +165,8 @@ class Reline::LineEditor 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? @@ -803,6 +806,7 @@ class Reline::LineEditor 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) |
