Sha256: 347406ce87c8fd123b1192ca952bef3064034d84cdefa93105872dc7a70f8af5

Contents?: true

Size: 1 KB

Versions: 19

Compression:

Stored size: 1 KB

Contents

class Printer
  attr_reader :stdout
  attr_reader :stderr
  attr_reader :stdin

  def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
    @stdout, @stderr, @stdin = stdout, stderr, stdin
  end

  def highline
    @highline ||= begin
      require 'highline'
      HighLine.new
    end
  end

  # Prints a message to stdout. Aliased as +info+ for compatibility with
  # the logger API.
  def msg(message)
    stdout.puts message
    stdout.flush
  end

  alias :info :msg

  # Print a warning message
  def warn(message)
    msg("#{color('WARNING:', :yellow, :bold)} #{message}")
  end

  # Print an error message
  def error(message)
    msg("#{color('ERROR:', :red, :bold)} #{message}")
  end

  # Print a message describing a fatal error.
  def fatal(message)
    msg("#{color('FATAL:', :red, :bold)} #{message}")
  end

  def color(string, *colors)
    if color?
      highline.color(string, *colors)
    else
      string
    end
  end

  # Should colored output be used? Only on TTY
  def color?
    true
  end

end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
ebm-0.0.2 lib/printer.rb
zzdeploy-0.1.13 lib/printer.rb
zzdeploy-0.1.12 lib/printer.rb
zzdeploy-0.1.11 lib/printer.rb
zzdeploy-0.1.10 lib/printer.rb
zzdeploy-0.1.9 lib/printer.rb
zzdeploy-0.1.8 lib/printer.rb
zzdeploy-0.1.7 lib/printer.rb
zzdeploy-0.1.6 lib/printer.rb
zzdeploy-0.1.5 lib/printer.rb
zzdeploy-0.1.4 lib/printer.rb
zzdeploy-0.1.3 lib/printer.rb
zzdeploy-0.1.2 lib/printer.rb
zzdeploy-0.1.0 lib/printer.rb
zzdeploy-0.0.9 lib/printer.rb
zzdeploy-0.0.8 lib/printer.rb
zzdeploy-0.0.7 lib/printer.rb
zzdeploy-0.0.6 lib/printer.rb
zzdeploy-0.0.5 lib/printer.rb