class Brush

Constants

ALLOWED_ATTRIBUTES
DEFAULT_BG_CODE
DEFAULT_FG_CODE

Attributes

attributes[R]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/asciinema/brush.rb, line 8
def initialize(attributes = {})
  @attributes = attributes.symbolize_keys
end

Public Instance Methods

==(other) click to toggle source
# File lib/asciinema/brush.rb, line 12
def ==(other)
  fg == other.fg &&
    bg == other.bg &&
    bold? == other.bold? &&
    underline? == other.underline? &&
    blink? == other.blink?
end
as_json(*) click to toggle source
# File lib/asciinema/brush.rb, line 48
def as_json(*)
  attributes.slice(*ALLOWED_ATTRIBUTES)
end
bg() click to toggle source
# File lib/asciinema/brush.rb, line 24
def bg
  inverse? ? fg_code || DEFAULT_FG_CODE : bg_code
end
bold?() click to toggle source
# File lib/asciinema/brush.rb, line 28
def bold?
  !!attributes[:bold]
end
default?() click to toggle source
# File lib/asciinema/brush.rb, line 44
def default?
  fg.nil? && bg.nil? && !bold? && !underline? && !inverse? && !blink?
end
fg() click to toggle source
# File lib/asciinema/brush.rb, line 20
def fg
  inverse? ? bg_code || DEFAULT_BG_CODE : fg_code
end
inverse?() click to toggle source
# File lib/asciinema/brush.rb, line 36
def inverse?
  !!attributes[:inverse]
end
underline?() click to toggle source
# File lib/asciinema/brush.rb, line 32
def underline?
  !!attributes[:underline]
end

Private Instance Methods

bg_code() click to toggle source
# File lib/asciinema/brush.rb, line 62
def bg_code
  calculate_code(:bg, blink?)
end
calculate_code(attr_name, strong) click to toggle source
# File lib/asciinema/brush.rb, line 66
def calculate_code(attr_name, strong)
  code = attributes[attr_name]

  if code
    if code < 8 && strong
      code += 8
    end
  end

  code
end
fg_code() click to toggle source
# File lib/asciinema/brush.rb, line 58
def fg_code
  calculate_code(:fg, bold?)
end