Class: ExtendedLogger::ColorScheme::Value

Inherits:
Struct
  • Object
show all
Defined in:
lib/extended_logger/color_scheme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bgObject

Returns the value of attribute bg

Returns:

  • (Object)

    the current value of bg



79
80
81
# File 'lib/extended_logger/color_scheme.rb', line 79

def bg
  @bg
end

#fgObject

Returns the value of attribute fg

Returns:

  • (Object)

    the current value of fg



79
80
81
# File 'lib/extended_logger/color_scheme.rb', line 79

def fg
  @fg
end

Instance Method Details

#colorize(prose) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/extended_logger/color_scheme.rb', line 80

def colorize prose
  return prose if fg.nil? and bg.nil?

  new_prose = String.new
  new_prose << escape_code
  new_prose << prose
  new_prose << reset
  new_prose
end

#escape_codeObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/extended_logger/color_scheme.rb', line 90

def escape_code
  string = String.new "\e["

  if fg
    brightness, fg_color = fg.divmod 8
    string << brightness.to_s
    string << ';3'
    string << fg_color.to_s
  end

  if bg
    string << ';' if fg

    _, bg_color = bg.divmod 8
    string << '4'
    string << bg_color.to_s
  end

  string << 'm'

  string
end

#resetObject



113
114
115
# File 'lib/extended_logger/color_scheme.rb', line 113

def reset
  "\e[0m"
end