Skip to content

Commit 3719702

Browse files
authored
Do not send color reset sequence when GeneralIO is used (#661)
1 parent cccb985 commit 3719702

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎lib/reline/ansi.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require_relative 'terminfo'
44

55
class Reline::ANSI
6+
RESET_COLOR = "\e[0m"
7+
68
CAPNAME_KEY_BINDINGS = {
79
'khome' => :ed_move_to_beg,
810
'kend' => :ed_move_to_end,

‎lib/reline/general_io.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'io/wait'
22

33
class Reline::GeneralIO
4+
RESET_COLOR = '' # Do not send color reset sequence
5+
46
def self.reset(encoding: nil)
57
@@pasting = false
68
if encoding

‎lib/reline/line_editor.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,12 @@ def render_line_differential(old_items, new_items)
372372
# do nothing
373373
elsif level == :blank
374374
Reline::IOGate.move_cursor_column base_x
375-
@output.write "\e[0m#{' ' * width}"
375+
@output.write "#{Reline::IOGate::RESET_COLOR}#{' ' * width}"
376376
else
377377
x, w, content = new_items[level]
378378
content = Reline::Unicode.take_range(content, base_x - x, width) unless x == base_x && w == width
379379
Reline::IOGate.move_cursor_column base_x
380-
@output.write "\e[0m#{content}\e[0m"
380+
@output.write "#{Reline::IOGate::RESET_COLOR}#{content}#{Reline::IOGate::RESET_COLOR}"
381381
end
382382
base_x += width
383383
end

‎lib/reline/windows.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'fiddle/import'
22

33
class Reline::Windows
4+
RESET_COLOR = "\e[0m"
5+
46
def self.encoding
57
Encoding::UTF_8
68
end

‎test/reline/test_line_editor.rb‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
class Reline::LineEditor
66
class RenderLineDifferentialTest < Reline::TestCase
7+
module TestIO
8+
RESET_COLOR = "\e[0m"
9+
10+
def self.move_cursor_column(col)
11+
@output << "[COL_#{col}]"
12+
end
13+
14+
def self.erase_after_cursor
15+
@output << '[ERASE]'
16+
end
17+
end
18+
719
def setup
820
verbose, $VERBOSE = $VERBOSE, nil
921
@line_editor = Reline::LineEditor.new(nil, Encoding::UTF_8)
@@ -12,14 +24,8 @@ def setup
1224
@line_editor.instance_variable_set(:@screen_size, [24, 80])
1325
@line_editor.instance_variable_set(:@output, @output)
1426
Reline.send(:remove_const, :IOGate)
15-
Reline.const_set(:IOGate, Object.new)
27+
Reline.const_set(:IOGate, TestIO)
1628
Reline::IOGate.instance_variable_set(:@output, @output)
17-
def (Reline::IOGate).move_cursor_column(col)
18-
@output << "[COL_#{col}]"
19-
end
20-
def (Reline::IOGate).erase_after_cursor
21-
@output << '[ERASE]'
22-
end
2329
ensure
2430
$VERBOSE = verbose
2531
end

0 commit comments

Comments
 (0)