class Happo::Logger

Used for all CLI output

Public Class Methods

new(out = STDOUT) click to toggle source

@param out [IO] the output destination

# File lib/happo/logger.rb, line 5
def initialize(out = STDOUT)
  @out = out
end

Public Instance Methods

cyan(str) click to toggle source

Mark the string in cyan @param str [String] the str to format

# File lib/happo/logger.rb, line 19
def cyan(str)
  color(36, str)
end
log(str, newline = true) click to toggle source

Print the specified output @param str [String] the output to send @param newline [Boolean] whether to append a newline

# File lib/happo/logger.rb, line 12
def log(str, newline = true)
  @out.print(str)
  @out.print("\n") if newline
end

Private Instance Methods

color(color_code, str) click to toggle source

Mark the string in a color @see ascii-table.com/ansi-escape-sequences.php @param color_code [Number] the ANSI color code @param str [String] the str to format

# File lib/happo/logger.rb, line 36
def color(color_code, str)
  tty? ? str : "\033[#{color_code}m#{str}\033[0m"
end
tty?() click to toggle source

Whether this logger is outputting to a TTY

@return [Boolean]

# File lib/happo/logger.rb, line 28
def tty?
  @out.respond_to?(:tty?) && @out.tty?
end