Sha256: ba008daa438f33de28f9adfc8799abc412843dbb2e59bec50c26ffc2236b956e

Contents?: true

Size: 805 Bytes

Versions: 16

Compression:

Stored size: 805 Bytes

Contents

module Overcommit
  # Encapsulates all communication to an output source.
  class Logger
    # Helper for creating a logger which outputs nothing.
    def self.silent
      new(File.open('/dev/null', 'w'))
    end

    def initialize(out)
      @out = out
    end

    def partial(*args)
      @out.print(*args)
    end

    def log(*args)
      @out.puts(*args)
    end

    def bold(str)
      color('1;37', str)
    end

    def error(str)
      color(31, str)
    end

    def bold_error(str)
      color('1;31', str)
    end

    def success(str)
      color(32, str)
    end

    def warning(str)
      color(33, str)
    end

    def bold_warning(str)
      color('1;33', str)
    end

  private

    def color(code, str)
      log(@out.tty? ? "\033[#{code}m#{str}\033[0m" : str)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
overcommit-0.16.0 lib/overcommit/logger.rb
overcommit-0.15.0 lib/overcommit/logger.rb
overcommit-0.14.1 lib/overcommit/logger.rb
overcommit-0.14.0 lib/overcommit/logger.rb
overcommit-0.13.0 lib/overcommit/logger.rb
overcommit-0.12.0 lib/overcommit/logger.rb
overcommit-0.11.1 lib/overcommit/logger.rb
overcommit-0.11.0 lib/overcommit/logger.rb
overcommit-0.10.0 lib/overcommit/logger.rb
overcommit-0.9.0 lib/overcommit/logger.rb
overcommit-0.8.0 lib/overcommit/logger.rb
overcommit-0.7.0 lib/overcommit/logger.rb
overcommit-0.6.3 lib/overcommit/logger.rb
overcommit-0.6.2 lib/overcommit/logger.rb
overcommit-0.6.1 lib/overcommit/logger.rb
overcommit-0.6.0 lib/overcommit/logger.rb