Class: EscapeCode::SgrCommand

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#typeObject (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/escape_code/sgr_command.rb', line 35

def background_color?
  type =~ /^4[0-7]/
end

#bold?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/escape_code/sgr_command.rb', line 27

def bold?
  type == BOLD
end

#colorObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/escape_code/sgr_command.rb', line 31

def foreground_color?
  type =~ /^3[0-7]$/
end

#reset?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/escape_code/sgr_command.rb', line 23

def reset?
  type == RESET
end