diff options
| author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-03-24 08:00:18 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-03-23 23:00:21 +0000 |
| commit | 3adaba0e81c1df4827dce86c19643b48d288a56b (patch) | |
| tree | 2b38b878f9a6832b9c7c1cf90ac34256a94482e7 | |
| parent | f46b77596d9b88e603765c0980667a86c62e2b04 (diff) | |
[ruby/reline] Do not send color reset sequence when GeneralIO is
used
(https://github.com/ruby/reline/pull/661)
https://github.com/ruby/reline/commit/3719702808
| -rw-r--r-- | lib/reline/ansi.rb | 2 | ||||
| -rw-r--r-- | lib/reline/general_io.rb | 2 | ||||
| -rw-r--r-- | lib/reline/line_editor.rb | 4 | ||||
| -rw-r--r-- | lib/reline/windows.rb | 2 | ||||
| -rw-r--r-- | test/reline/test_line_editor.rb | 20 |
5 files changed, 21 insertions, 9 deletions
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index c2e5075ea8..2d7c759ea2 100644 --- a/lib/reline/ansi.rb +++ b/lib/reline/ansi.rb @@ -3,6 +3,8 @@ require 'io/wait' require_relative 'terminfo' class Reline::ANSI + RESET_COLOR = "\e[0m" + CAPNAME_KEY_BINDINGS = { 'khome' => :ed_move_to_beg, 'kend' => :ed_move_to_end, diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb index b830eb39a0..8fb0f25a34 100644 --- a/lib/reline/general_io.rb +++ b/lib/reline/general_io.rb @@ -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 diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index c6360e56b0..5a04e5650f 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -372,12 +372,12 @@ class Reline::LineEditor # 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 diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index a22331fae5..28f28e15cc 100644 --- a/lib/reline/windows.rb +++ b/lib/reline/windows.rb @@ -1,6 +1,8 @@ require 'fiddle/import' class Reline::Windows + RESET_COLOR = "\e[0m" + def self.encoding Encoding::UTF_8 end diff --git a/test/reline/test_line_editor.rb b/test/reline/test_line_editor.rb index c552787dc7..0963d2c8fe 100644 --- a/test/reline/test_line_editor.rb +++ b/test/reline/test_line_editor.rb @@ -4,6 +4,18 @@ require 'stringio' 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) @@ -12,14 +24,8 @@ class Reline::LineEditor @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 |
