mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 23:16:42 +02:00
[ruby/reline] Do not send color reset sequence when GeneralIO is
used
(https://github.com/ruby/reline/pull/661)
3719702808
This commit is contained in:
parent
f46b77596d
commit
3adaba0e81
5 changed files with 21 additions and 9 deletions
|
@ -3,6 +3,8 @@ require 'io/wait'
|
||||||
require_relative 'terminfo'
|
require_relative 'terminfo'
|
||||||
|
|
||||||
class Reline::ANSI
|
class Reline::ANSI
|
||||||
|
RESET_COLOR = "\e[0m"
|
||||||
|
|
||||||
CAPNAME_KEY_BINDINGS = {
|
CAPNAME_KEY_BINDINGS = {
|
||||||
'khome' => :ed_move_to_beg,
|
'khome' => :ed_move_to_beg,
|
||||||
'kend' => :ed_move_to_end,
|
'kend' => :ed_move_to_end,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'io/wait'
|
require 'io/wait'
|
||||||
|
|
||||||
class Reline::GeneralIO
|
class Reline::GeneralIO
|
||||||
|
RESET_COLOR = '' # Do not send color reset sequence
|
||||||
|
|
||||||
def self.reset(encoding: nil)
|
def self.reset(encoding: nil)
|
||||||
@@pasting = false
|
@@pasting = false
|
||||||
if encoding
|
if encoding
|
||||||
|
|
|
@ -372,12 +372,12 @@ class Reline::LineEditor
|
||||||
# do nothing
|
# do nothing
|
||||||
elsif level == :blank
|
elsif level == :blank
|
||||||
Reline::IOGate.move_cursor_column base_x
|
Reline::IOGate.move_cursor_column base_x
|
||||||
@output.write "\e[0m#{' ' * width}"
|
@output.write "#{Reline::IOGate::RESET_COLOR}#{' ' * width}"
|
||||||
else
|
else
|
||||||
x, w, content = new_items[level]
|
x, w, content = new_items[level]
|
||||||
content = Reline::Unicode.take_range(content, base_x - x, width) unless x == base_x && w == width
|
content = Reline::Unicode.take_range(content, base_x - x, width) unless x == base_x && w == width
|
||||||
Reline::IOGate.move_cursor_column base_x
|
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
|
end
|
||||||
base_x += width
|
base_x += width
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'fiddle/import'
|
require 'fiddle/import'
|
||||||
|
|
||||||
class Reline::Windows
|
class Reline::Windows
|
||||||
|
RESET_COLOR = "\e[0m"
|
||||||
|
|
||||||
def self.encoding
|
def self.encoding
|
||||||
Encoding::UTF_8
|
Encoding::UTF_8
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,18 @@ require 'stringio'
|
||||||
|
|
||||||
class Reline::LineEditor
|
class Reline::LineEditor
|
||||||
class RenderLineDifferentialTest < Reline::TestCase
|
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
|
def setup
|
||||||
verbose, $VERBOSE = $VERBOSE, nil
|
verbose, $VERBOSE = $VERBOSE, nil
|
||||||
@line_editor = Reline::LineEditor.new(nil, Encoding::UTF_8)
|
@line_editor = Reline::LineEditor.new(nil, Encoding::UTF_8)
|
||||||
|
@ -12,14 +24,8 @@ class Reline::LineEditor
|
||||||
@line_editor.instance_variable_set(:@screen_size, [24, 80])
|
@line_editor.instance_variable_set(:@screen_size, [24, 80])
|
||||||
@line_editor.instance_variable_set(:@output, @output)
|
@line_editor.instance_variable_set(:@output, @output)
|
||||||
Reline.send(:remove_const, :IOGate)
|
Reline.send(:remove_const, :IOGate)
|
||||||
Reline.const_set(:IOGate, Object.new)
|
Reline.const_set(:IOGate, TestIO)
|
||||||
Reline::IOGate.instance_variable_set(:@output, @output)
|
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
|
ensure
|
||||||
$VERBOSE = verbose
|
$VERBOSE = verbose
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue