class SuperDiff::Csi::Color

Attributes

layer[R]

Public Class Methods

exists?(name) click to toggle source
# File lib/super_diff/csi/color.rb, line 4
def self.exists?(name)
  FourBitColor.exists?(name)
end
resolve(value, layer:) click to toggle source
# File lib/super_diff/csi/color.rb, line 8
def self.resolve(value, layer:)
  if value.is_a?(Symbol)
    FourBitColor.new(value, layer: layer)
  else
    TwentyFourBitColor.new(value, layer: layer)
  end
end
sub_colorized_areas_in(text) { |match, new(match)| ... } click to toggle source
# File lib/super_diff/csi/color.rb, line 16
def self.sub_colorized_areas_in(text)
  regex = /(#{opening_regex.source.gsub(/\((.+?)\)/, '\1')})(.+?)\e\[0m/

  text.gsub(regex) do
    match = Regexp.last_match

    if match[1] == "\e[0m"
      match[0]
    else
      yield match[2], new(match[1])
    end
  end
end

Public Instance Methods

background?() click to toggle source
# File lib/super_diff/csi/color.rb, line 38
def background?
  layer == :background
end
foreground?() click to toggle source
# File lib/super_diff/csi/color.rb, line 34
def foreground?
  layer == :foreground
end
to_foreground() click to toggle source
# File lib/super_diff/csi/color.rb, line 42
def to_foreground
  raise NotImplementedError
end
to_s() click to toggle source
# File lib/super_diff/csi/color.rb, line 30
def to_s
  raise NotImplementedError
end

Protected Instance Methods

interpret_layer!(layer) click to toggle source
# File lib/super_diff/csi/color.rb, line 50
def interpret_layer!(layer)
  if [:foreground, :background].include?(layer)
    layer
  else
    raise ArgumentError.new(
      "Invalid layer #{layer.inspect}. " +
      "Layer must be :foreground or :background.",
    )
  end
end