Class: SuperDiff::Csi::FourBitColor
- Inherits:
-
Object
- Object
- SuperDiff::Csi::FourBitColor
- Defined in:
- lib/super_diff/csi/four_bit_color.rb
Constant Summary collapse
- VALID_TYPES =
[:fg, :bg].freeze
- VALID_CODES_BY_NAME =
{ black: { fg: 30, bg: 40 }, red: { fg: 31, bg: 41 }, green: { fg: 32, bg: 42 }, yellow: { fg: 33, bg: 43 }, blue: { fg: 34, bg: 44 }, magenta: { fg: 35, bg: 45 }, cyan: { fg: 36, bg: 46 }, white: { fg: 37, bg: 47 }, bright_black: { fg: 90, bg: 100 }, bright_red: { fg: 91, bg: 101 }, bright_green: { fg: 92, bg: 102 }, bright_yellow: { fg: 93, bg: 103 }, bright_blue: { fg: 94, bg: 104 }, bright_magenta: { fg: 95, bg: 105 }, bright_cyan: { fg: 96, bg: 106 }, bright_white: { fg: 97, bg: 107 }, }.freeze
- NAMES_BY_CODE =
VALID_CODES_BY_NAME.reduce({}) do |hash, (key, value)| hash.merge(value[:fg] => key, value[:bg] => key) end
- VALID_NAMES =
VALID_CODES_BY_NAME.keys
- VALID_CODE_RANGES =
[30..37, 40..47, 90..97, 100..107].freeze
Instance Method Summary collapse
-
#initialize(value) ⇒ FourBitColor
constructor
A new instance of FourBitColor.
- #sequence_for(layer) ⇒ Object
Constructor Details
#initialize(value) ⇒ FourBitColor
Returns a new instance of FourBitColor.
29 30 31 32 33 34 35 36 |
# File 'lib/super_diff/csi/four_bit_color.rb', line 29 def initialize(value) @name = if value.is_a?(Symbol) interpret_name!(value) else interpret_code!(value) end end |
Instance Method Details
#sequence_for(layer) ⇒ Object
38 39 40 41 |
# File 'lib/super_diff/csi/four_bit_color.rb', line 38 def sequence_for(layer) code = VALID_CODES_BY_NAME.fetch(name).fetch(layer) "\e[#{code}m" end |