Class: Sai::ANSI::ColorParser Private
- Inherits:
-
Object
- Object
- Sai::ANSI::ColorParser
- Defined in:
- lib/sai/ansi/color_parser.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Handles parsing of ANSI color codes
Instance Attribute Summary collapse
-
#segment ⇒ Hash
readonly
private
The current segment being processed.
Instance Method Summary collapse
-
#initialize(segment) ⇒ ColorParser
constructor
private
Initialize a new instance of ColorParser.
-
#parse256(codes, index) ⇒ Integer
private
Parse a 256-color code.
-
#parse_24bit(codes, index) ⇒ Integer
private
Parse a 24-bit color code.
-
#parse_basic(code) ⇒ void
private
Parse a basic color code.
Constructor Details
#initialize(segment) ⇒ ColorParser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new instance of ColorParser
33 34 35 |
# File 'lib/sai/ansi/color_parser.rb', line 33 def initialize(segment) @segment = segment end |
Instance Attribute Details
#segment ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The current segment being processed
20 21 22 |
# File 'lib/sai/ansi/color_parser.rb', line 20 def segment @segment end |
Instance Method Details
#parse256(codes, index) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse a 256-color code
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sai/ansi/color_parser.rb', line 49 def parse256(codes, index) base_code = codes[index] color_number = codes[index + 2] if base_code == 38 segment[:foreground] = "38;5;#{color_number}" else segment[:background] = "48;5;#{color_number}" end index + 3 end |
#parse_24bit(codes, index) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse a 24-bit color code
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sai/ansi/color_parser.rb', line 74 def parse_24bit(codes, index) base_code = codes[index] r = codes[index + 2] g = codes[index + 3] b = codes[index + 4] if base_code == 38 segment[:foreground] = "38;2;#{r};#{g};#{b}" else segment[:background] = "48;2;#{r};#{g};#{b}" end index + 5 end |
#parse_basic(code) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Parse a basic color code
100 101 102 103 104 105 106 |
# File 'lib/sai/ansi/color_parser.rb', line 100 def parse_basic(code) if (30..37).cover?(code) segment[:foreground] = code.to_s else # 40..47 segment[:background] = code.to_s end end |