Class: SuperDiff::Csi::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/super_diff/csi/color.rb

Direct Known Subclasses

EightBitColor, FourBitColor, TwentyFourBitColor

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/super_diff/csi/color.rb', line 4

def self.exists?(name)
  FourBitColor.exists?(name)
end

.resolve(value, layer:) ⇒ Object



8
9
10
11
12
13
14
# 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) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Method Details

#background?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/super_diff/csi/color.rb', line 38

def background?
  layer == :background
end

#foreground?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/super_diff/csi/color.rb', line 34

def foreground?
  layer == :foreground
end

#to_foregroundObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/super_diff/csi/color.rb', line 42

def to_foreground
  raise NotImplementedError
end

#to_sObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/super_diff/csi/color.rb', line 30

def to_s
  raise NotImplementedError
end