class Console

ANSI console

Constants

BOLD
COLORS
COLOR_BG
COLOR_FG
CSI
RESET
SGR
STYLES

Public Class Methods

new() click to toggle source
# File lib/console.rb, line 36
def initialize
  @sgr = []
end

Public Instance Methods

method_missing(method, *args) click to toggle source
# File lib/console.rb, line 45
def method_missing(method, *args)
  if STYLES.key?(method)
    @sgr << STYLES[method]
  elsif COLORS.key?(method)
    @sgr << COLORS[method] + COLOR_FG
  elsif method.to_s.start_with?('on_')
    color = method.to_s[3..-1].to_sym
    @sgr << COLORS[color] + COLOR_BG if COLORS.key?(color)
  end

  return self if args.empty?

  out = String.new
  out << CSI + @sgr.join(';') + SGR unless @sgr.empty?
  out << args.join
  out << CSI + STYLES[:reset].to_s + SGR unless @sgr.empty?
  @sgr.clear
  out
end
respond_to_missing?(method) click to toggle source
# File lib/console.rb, line 40
def respond_to_missing?(method)
  m = method.to_s.start_with?('on_') ? method.to_s[3..-1].to_sym : method
  STYLES.include?(m) || COLORS.include?(m)
end