Skip to content

Commit

Permalink
Do not send color reset sequence when GeneralIO is used
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Mar 23, 2024
1 parent 9685db5 commit 6d450df
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require_relative 'terminfo'

class Reline::ANSI
RESET_COLOR = "\e[0m"

CAPNAME_KEY_BINDINGS = {
'khome' => :ed_move_to_beg,
'kend' => :ed_move_to_end,
Expand Down
2 changes: 2 additions & 0 deletions lib/reline/general_io.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'io/wait'

class Reline::GeneralIO
RESET_COLOR = '' # Do not send color reset sequence

def self.reset(encoding: nil)
@@pasting = false
if encoding
Expand Down
4 changes: 2 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ def render_line_differential(old_items, new_items)
# do nothing
elsif level == :blank
Reline::IOGate.move_cursor_column base_x
@output.write "\e[0m#{' ' * width}"
@output.write "#{Reline::IOGate::RESET_COLOR}#{' ' * width}"
else
x, w, content = new_items[level]
content = Reline::Unicode.take_range(content, base_x - x, width) unless x == base_x && w == width
Reline::IOGate.move_cursor_column base_x
@output.write "\e[0m#{content}\e[0m"
@output.write "#{Reline::IOGate::RESET_COLOR}#{content}#{Reline::IOGate::RESET_COLOR}"
end
base_x += width
end
Expand Down
2 changes: 2 additions & 0 deletions lib/reline/windows.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'fiddle/import'

class Reline::Windows
RESET_COLOR = "\e[0m"

def self.encoding
Encoding::UTF_8
end
Expand Down
20 changes: 13 additions & 7 deletions test/reline/test_line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

class Reline::LineEditor
class RenderLineDifferentialTest < Reline::TestCase
module TestIO
RESET_COLOR = "\e[0m"

def self.move_cursor_column(col)
@output << "[COL_#{col}]"
end

def self.erase_after_cursor
@output << '[ERASE]'
end
end

def setup
verbose, $VERBOSE = $VERBOSE, nil
@line_editor = Reline::LineEditor.new(nil, Encoding::UTF_8)
Expand All @@ -12,14 +24,8 @@ def setup
@line_editor.instance_variable_set(:@screen_size, [24, 80])
@line_editor.instance_variable_set(:@output, @output)
Reline.send(:remove_const, :IOGate)
Reline.const_set(:IOGate, Object.new)
Reline.const_set(:IOGate, TestIO)
Reline::IOGate.instance_variable_set(:@output, @output)
def (Reline::IOGate).move_cursor_column(col)
@output << "[COL_#{col}]"
end
def (Reline::IOGate).erase_after_cursor
@output << '[ERASE]'
end
ensure
$VERBOSE = verbose
end
Expand Down

0 comments on commit 6d450df

Please sign in to comment.