Class: SuperDiff::Csi::TwentyFourBitColor
- Defined in:
- lib/super_diff/csi/twenty_four_bit_color.rb
Defined Under Namespace
Classes: Triplet
Constant Summary collapse
- VALID_COMPONENT_RANGE =
(0..255)
- LEADING_CODES_BY_LAYER =
{ foreground: 38, background: 48 }.freeze
- LAYERS_BY_LEADING_CODE =
LEADING_CODES_BY_LAYER.invert.freeze
- SERIAL_CODE =
2
- OPENING_REGEX =
/\e\[(\d+);#{SERIAL_CODE};(\d+);(\d+);(\d+)m/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value = nil, layer: nil, red: nil, green: nil, blue: nil) ⇒ TwentyFourBitColor
constructor
A new instance of TwentyFourBitColor.
- #to_foreground ⇒ Object
- #to_s ⇒ Object
Methods inherited from Color
#background?, exists?, #foreground?, resolve, sub_colorized_areas_in
Constructor Details
#initialize(value = nil, layer: nil, red: nil, green: nil, blue: nil) ⇒ TwentyFourBitColor
Returns a new instance of TwentyFourBitColor.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/super_diff/csi/twenty_four_bit_color.rb', line 16 def initialize(value = nil, layer: nil, red: nil, green: nil, blue: nil) super() if value pair = interpret_sequence!(value) @triplet = pair.fetch(:triplet) @layer = pair.fetch(:layer) else @triplet = interpret_triplet!(red: red, green: green, blue: blue) @layer = interpret_layer!(layer) end end |
Class Method Details
.opening_regex ⇒ Object
12 13 14 |
# File 'lib/super_diff/csi/twenty_four_bit_color.rb', line 12 def self.opening_regex OPENING_REGEX end |
Instance Method Details
#to_foreground ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/super_diff/csi/twenty_four_bit_color.rb', line 38 def to_foreground self.class.new( red: triplet.red, green: triplet.green, blue: triplet.blue, layer: :foreground ) end |
#to_s ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/super_diff/csi/twenty_four_bit_color.rb', line 28 def to_s [ # rubocop:disable Style/StringConcatenation "\e[#{leading_code}", SERIAL_CODE, triplet.red, triplet.blue, triplet.green ].join(';') + 'm' end |