Class: EscapeCode::Code
- Inherits:
-
Object
- Object
- EscapeCode::Code
- Defined in:
- lib/escape_code/code.rb
Constant Summary collapse
- REGEX =
/\e\[([0-9;]*)([a-zA-Z])/- SGR =
'm'
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
TODO: Support other types of escape codes, like private sequences and non-alphanumeric mode characters.
-
#sgr_commands ⇒ Object
readonly
TODO: Support other types of escape codes, like private sequences and non-alphanumeric mode characters.
-
#type ⇒ Object
readonly
TODO: Support other types of escape codes, like private sequences and non-alphanumeric mode characters.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, args) ⇒ Code
constructor
A new instance of Code.
- #sgr? ⇒ Boolean
Constructor Details
#initialize(type, args) ⇒ Code
Returns a new instance of Code.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/escape_code/code.rb', line 10 def initialize(type, args) @type = type @args = args if sgr? @sgr_commands ||= begin if args == [] # SGR without an argument is equvalent to reset [EscapeCode::SgrCommand.new(SgrCommand::RESET)] else args.map do |arg| EscapeCode::SgrCommand.new(arg) end end end end end |
Instance Attribute Details
#args ⇒ Object (readonly)
TODO: Support other types of escape codes, like private sequences and non-alphanumeric mode characters
8 9 10 |
# File 'lib/escape_code/code.rb', line 8 def args @args end |
#sgr_commands ⇒ Object (readonly)
TODO: Support other types of escape codes, like private sequences and non-alphanumeric mode characters
8 9 10 |
# File 'lib/escape_code/code.rb', line 8 def sgr_commands @sgr_commands end |
#type ⇒ Object (readonly)
TODO: Support other types of escape codes, like private sequences and non-alphanumeric mode characters
8 9 10 |
# File 'lib/escape_code/code.rb', line 8 def type @type end |
Class Method Details
.parse(code) ⇒ Object
28 29 30 31 |
# File 'lib/escape_code/code.rb', line 28 def self.parse(code) raise 'not a valid escape sequence' unless code =~ REGEX new($~[2], $~[1].split(';')) end |