Class: EscapeCode::SgrState

Inherits:
Object
  • Object
show all
Defined in:
lib/escape_code/sgr_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSgrState

Returns a new instance of SgrState.



6
7
8
9
10
# File 'lib/escape_code/sgr_state.rb', line 6

def initialize
  @bold = false
  @foreground = nil
  @background = nil
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



3
4
5
# File 'lib/escape_code/sgr_state.rb', line 3

def background
  @background
end

#boldObject (readonly) Also known as: bold?

Returns the value of attribute bold.



3
4
5
# File 'lib/escape_code/sgr_state.rb', line 3

def bold
  @bold
end

#foregroundObject (readonly)

Returns the value of attribute foreground.



3
4
5
# File 'lib/escape_code/sgr_state.rb', line 3

def foreground
  @foreground
end

Instance Method Details

#ingest(command) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/escape_code/sgr_state.rb', line 12

def ingest(command)
  # convenience thing to allow passing in an entire code instead of individual SGR commands
  if command.is_a?(EscapeCode::Code)
    command.sgr_commands.each { |c| ingest(c) } if command.sgr?
    return
  end

  if command.reset?
    @bold = false
    @foreground = nil
    @background = nil
  elsif command.bold?
    @bold = true
  elsif command.foreground_color?
    @foreground = command.color
  elsif command.background_color?
    @background = command.color
  end
end