Module: Coveralls::Output

Extended by:
Output
Included in:
Output
Defined in:
lib/coveralls/output.rb

Overview

Public: Methods for formatting strings with Term::ANSIColor. Does not utilize monkey-patching and should play nicely when included with other libraries.

All methods are module methods and should be called on the Coveralls::Output module.

Examples

Coveralls::Output.format("Hello World", :color => "cyan")
# => "\e[36mHello World\e[0m"

Coveralls::Output.print("Hello World")
# Hello World => nil

Coveralls::Output.puts("Hello World", :color => "underline")
# Hello World
# => nil

To silence output completely:

Coveralls::Output.silent = true

or set this environment variable:

COVERALLS_SILENT

To disable color completely:

Coveralls::Output.no_color = true

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#no_colorObject

Returns the value of attribute no_color.



35
36
37
# File 'lib/coveralls/output.rb', line 35

def no_color
  @no_color
end

#outputObject



39
40
41
# File 'lib/coveralls/output.rb', line 39

def output
  (defined?(@output) && @output) || $stdout
end

#silentObject

Returns the value of attribute silent.



35
36
37
# File 'lib/coveralls/output.rb', line 35

def silent
  @silent
end

Instance Method Details

#format(string, options = {}) ⇒ Object

Public: Formats the given string with the specified color through Term::ANSIColor

string - the text to be formatted options - The hash of options used for formatting the text:

:color - The color to be passed as a method to
         Term::ANSIColor

Examples

Coveralls::Output.format("Hello World!", :color => "cyan")
# => "\e[36mHello World\e[0m"

Returns the formatted string.



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/coveralls/output.rb', line 61

def format(string, options = {})
  unless no_color?
    require 'term/ansicolor'
    if options[:color]
      options[:color].split(/\s/).reverse_each do |color|
        if Term::ANSIColor.respond_to?(color.to_sym)
          string = Term::ANSIColor.send(color.to_sym, string)
        end
      end
    end
  end
  string
end

#no_color?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/coveralls/output.rb', line 43

def no_color?
  (defined?(@no_color)) && @no_color
end

Public: Passes .format to Kernel#print

string - the text to be formatted options - The hash of options used for formatting the text:

:color - The color to be passed as a method to
         Term::ANSIColor

Example

Coveralls::Output.print("Hello World!", :color => "underline")

Returns nil.



105
106
107
108
# File 'lib/coveralls/output.rb', line 105

def print(string, options = {})
  return if silent?
  (options[:output] || output).print self.format(string, options)
end

#puts(string, options = {}) ⇒ Object

Public: Passes .format to Kernel#puts

string - the text to be formatted options - The hash of options used for formatting the text:

:color - The color to be passed as a method to
         Term::ANSIColor

Example

Coveralls::Output.puts("Hello World", :color => "cyan")

Returns nil.



88
89
90
91
# File 'lib/coveralls/output.rb', line 88

def puts(string, options = {})
  return if silent?
  (options[:output] || output).puts self.format(string, options)
end

#silent?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/coveralls/output.rb', line 110

def silent?
  ENV["COVERALLS_SILENT"] || (defined?(@silent) && @silent)
end