class SCSSLint::Logger

Encapsulates all communication to an output source.

Attributes

color_enabled[RW]

Whether colored output via ANSI escape sequences is enabled. @return [true,false]

Public Class Methods

new(out) click to toggle source

Creates a new {SCSSLint::Logger} instance.

@param out [IO] the output destination.

# File lib/scss_lint/logger.rb, line 17
def initialize(out)
  @out = out
end
silent() click to toggle source

Creates a logger which outputs nothing. @return [SCSSLint::Logger]

# File lib/scss_lint/logger.rb, line 10
def self.silent
  new(File.open('/dev/null', 'w'))
end

Public Instance Methods

bold(output) click to toggle source

Mark the specified output in bold face. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 84
def bold(output)
  color('1', output)
end
bold_error(output, newline = true) click to toggle source

Print the specified output in a bold face and color indicative of error. If output destination is not a TTY, behaves the same as {#log}.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/scss_lint/logger.rb, line 44
def bold_error(output, newline = true)
  log(bold_red(output), newline)
end
bold_red(output) click to toggle source

Mark the specified output in bold red. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 92
def bold_red(output)
  color('1;31', output)
end
cyan(output) click to toggle source

Mark the specified output in cyan. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 132
def cyan(output)
  color(36, output)
end
error(output, newline = true) click to toggle source

Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as {#log}.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/scss_lint/logger.rb, line 35
def error(output, newline = true)
  log(red(output), newline)
end
green(output) click to toggle source

Mark the specified output in green. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 108
def green(output)
  color(32, output)
end
info(output, newline = true) click to toggle source

Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as {#log}.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/scss_lint/logger.rb, line 71
def info(output, newline = true)
  log(cyan(output), newline)
end
log(output, newline = true) click to toggle source

Print the specified output.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/scss_lint/logger.rb, line 25
def log(output, newline = true)
  @out.print(output)
  @out.print("\n") if newline
end
magenta(output) click to toggle source

Mark the specified output in magenta. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 124
def magenta(output)
  color(35, output)
end
newline() click to toggle source

Print a blank line.

# File lib/scss_lint/logger.rb, line 76
def newline
  log('')
end
red(output) click to toggle source

Mark the specified output in red. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 100
def red(output)
  color(31, output)
end
success(output, newline = true) click to toggle source

Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as {#log}.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/scss_lint/logger.rb, line 53
def success(output, newline = true)
  log(green(output), newline)
end
tty?() click to toggle source

Whether this logger is outputting to a TTY.

@return [true,false]

# File lib/scss_lint/logger.rb, line 139
def tty?
  @out.respond_to?(:tty?) && @out.tty?
end
warning(output, newline = true) click to toggle source

Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as {#log}.

@param output [String] the output to send @param newline [true,false] whether to append a newline

# File lib/scss_lint/logger.rb, line 62
def warning(output, newline = true)
  log(yellow(output), newline)
end
yellow(output) click to toggle source

Mark the specified output in yellow. If output destination is not a TTY, this is a noop.

@param output [String] the output to format

# File lib/scss_lint/logger.rb, line 116
def yellow(output)
  color(33, output)
end

Private Instance Methods

color(code, output) click to toggle source
# File lib/scss_lint/logger.rb, line 145
def color(code, output)
  color_enabled ? "\033[#{code}m#{output}\033[0m" : output
end