Class: Gitlab::Ci::Ansi2json::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/ansi2json/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fg: nil, bg: nil, mask: 0) ⇒ Style

Returns a new instance of Style.


9
10
11
12
13
14
15
# File 'lib/gitlab/ci/ansi2json/style.rb', line 9

def initialize(fg: nil, bg: nil, mask: 0)
  @fg = fg
  @bg = bg
  @mask = mask

  update_formats
end

Instance Attribute Details

#bgObject (readonly)

Returns the value of attribute bg


7
8
9
# File 'lib/gitlab/ci/ansi2json/style.rb', line 7

def bg
  @bg
end

#fgObject (readonly)

Returns the value of attribute fg


7
8
9
# File 'lib/gitlab/ci/ansi2json/style.rb', line 7

def fg
  @fg
end

#maskObject (readonly)

Returns the value of attribute mask


7
8
9
# File 'lib/gitlab/ci/ansi2json/style.rb', line 7

def mask
  @mask
end

Instance Method Details

#==(other) ⇒ Object


35
36
37
# File 'lib/gitlab/ci/ansi2json/style.rb', line 35

def ==(other)
  self.to_h == other.to_h
end

#reset!Object


28
29
30
31
32
33
# File 'lib/gitlab/ci/ansi2json/style.rb', line 28

def reset!
  @fg = nil
  @bg = nil
  @mask = 0
  @formats = []
end

#set?Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/gitlab/ci/ansi2json/style.rb', line 24

def set?
  @fg || @bg || @formats.any?
end

#to_hObject


43
44
45
# File 'lib/gitlab/ci/ansi2json/style.rb', line 43

def to_h
  { fg: @fg, bg: @bg, mask: @mask }
end

#to_sObject


39
40
41
# File 'lib/gitlab/ci/ansi2json/style.rb', line 39

def to_s
  [@fg, @bg, @formats].flatten.compact.join(' ')
end

#update(ansi_commands) ⇒ Object


17
18
19
20
21
22
# File 'lib/gitlab/ci/ansi2json/style.rb', line 17

def update(ansi_commands)
  # treat e\[m as \e[0m
  ansi_commands = ['0'] if ansi_commands.empty?

  evaluate_stack_command(ansi_commands)
end