Skip to content

Commit

Permalink
Avoid using reset constant directly
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Mar 25, 2024
1 parent a5214c8 commit 978f779
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
6 changes: 6 additions & 0 deletions lib/reline/io.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

module Reline
class IO
RESET_COLOR = "\e[0m"

def self.decide_io_gate
if ENV['TERM'] == 'dumb'
Reline::Dumb.new
Expand Down Expand Up @@ -33,6 +35,10 @@ def dumb?
def win?
false
end

def reset_color_sequence
self.class::RESET_COLOR
end
end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/reline/io/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions lib/reline/io/dumb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def encoding
end
end

def win?
false
end

def set_default_key_bindings(_)
end

Expand Down
2 changes: 0 additions & 2 deletions lib/reline/io/windows.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'fiddle/import'

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

def initialize
@input_buf = []
@output_buf = []
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 @@ -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
Expand Down
4 changes: 1 addition & 3 deletions test/reline/test_line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 978f779

Please sign in to comment.