From 978f77926b5f499389b9dcb5ebafe02d2624289e Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Mon, 25 Mar 2024 13:05:08 +0000 Subject: [PATCH] Avoid using reset constant directly --- lib/reline/io.rb | 6 ++++++ lib/reline/io/ansi.rb | 2 -- lib/reline/io/dumb.rb | 4 ---- lib/reline/io/windows.rb | 2 -- lib/reline/line_editor.rb | 4 ++-- test/reline/test_line_editor.rb | 4 +--- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/reline/io.rb b/lib/reline/io.rb index d6e269066a..7fca0c338a 100644 --- a/lib/reline/io.rb +++ b/lib/reline/io.rb @@ -1,6 +1,8 @@ module Reline class IO + RESET_COLOR = "\e[0m" + def self.decide_io_gate if ENV['TERM'] == 'dumb' Reline::Dumb.new @@ -33,6 +35,10 @@ def dumb? def win? false end + + def reset_color_sequence + self.class::RESET_COLOR + end end end diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb index 8cb4999e6b..396189a144 100644 --- a/lib/reline/io/ansi.rb +++ b/lib/reline/io/ansi.rb @@ -2,8 +2,6 @@ require 'io/wait' class Reline::ANSI < Reline::IO - RESET_COLOR = "\e[0m" - CAPNAME_KEY_BINDINGS = { 'khome' => :ed_move_to_beg, 'kend' => :ed_move_to_end, diff --git a/lib/reline/io/dumb.rb b/lib/reline/io/dumb.rb index 396c1371f8..abc347aff8 100644 --- a/lib/reline/io/dumb.rb +++ b/lib/reline/io/dumb.rb @@ -25,10 +25,6 @@ def encoding end end - def win? - false - end - def set_default_key_bindings(_) end diff --git a/lib/reline/io/windows.rb b/lib/reline/io/windows.rb index a8fe84f2cc..09fd580182 100644 --- a/lib/reline/io/windows.rb +++ b/lib/reline/io/windows.rb @@ -1,8 +1,6 @@ require 'fiddle/import' class Reline::Windows < Reline::IO - RESET_COLOR = "\e[0m" - def initialize @input_buf = [] @output_buf = [] diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 875a9fb630..53a4a3397a 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -370,12 +370,12 @@ def render_line_differential(old_items, new_items) # do nothing elsif level == :blank Reline::IOGate.move_cursor_column base_x - @output.write "#{Reline::IOGate.class::RESET_COLOR}#{' ' * width}" + @output.write "#{Reline::IOGate.reset_color_sequence}#{' ' * 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 "#{Reline::IOGate.class::RESET_COLOR}#{content}#{Reline::IOGate.class::RESET_COLOR}" + @output.write "#{Reline::IOGate.reset_color_sequence}#{content}#{Reline::IOGate.reset_color_sequence}" end base_x += width end diff --git a/test/reline/test_line_editor.rb b/test/reline/test_line_editor.rb index a34af9a906..2cfab7943f 100644 --- a/test/reline/test_line_editor.rb +++ b/test/reline/test_line_editor.rb @@ -4,9 +4,7 @@ class Reline::LineEditor class RenderLineDifferentialTest < Reline::TestCase - class TestIO - RESET_COLOR = "\e[0m" - + class TestIO < Reline::IO def move_cursor_column(col) @output << "[COL_#{col}]" end