Class: EscapeCode::SgrCommand
- Inherits:
-
Object
- Object
- EscapeCode::SgrCommand
- Defined in:
- lib/escape_code/sgr_command.rb
Constant Summary collapse
- RESET =
'0'- BOLD =
'1'- COLORS =
{ '0' => :black, '1' => :red, '2' => :green, '3' => :yellow, '4' => :blue, '5' => :purple, '6' => :cyan, '7' => :white }
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #background_color? ⇒ Boolean
- #bold? ⇒ Boolean
- #color ⇒ Object
- #foreground_color? ⇒ Boolean
-
#initialize(type) ⇒ SgrCommand
constructor
A new instance of SgrCommand.
- #reset? ⇒ Boolean
Constructor Details
#initialize(type) ⇒ SgrCommand
Returns a new instance of SgrCommand.
19 20 21 |
# File 'lib/escape_code/sgr_command.rb', line 19 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
17 18 19 |
# File 'lib/escape_code/sgr_command.rb', line 17 def type @type end |
Instance Method Details
#background_color? ⇒ Boolean
35 36 37 |
# File 'lib/escape_code/sgr_command.rb', line 35 def background_color? type =~ /^4[0-7]/ end |
#bold? ⇒ Boolean
27 28 29 |
# File 'lib/escape_code/sgr_command.rb', line 27 def bold? type == BOLD end |
#color ⇒ Object
39 40 41 42 43 |
# File 'lib/escape_code/sgr_command.rb', line 39 def color return nil unless foreground_color? || background_color? EscapeCode::SgrCommand::COLORS[type[1]] end |
#foreground_color? ⇒ Boolean
31 32 33 |
# File 'lib/escape_code/sgr_command.rb', line 31 def foreground_color? type =~ /^3[0-7]$/ end |
#reset? ⇒ Boolean
23 24 25 |
# File 'lib/escape_code/sgr_command.rb', line 23 def reset? type == RESET end |