Module: Coveralls::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
Class Attribute Summary collapse
-
.no_color ⇒ Object
Returns the value of attribute no_color.
- .output ⇒ Object
-
.silent ⇒ Object
Returns the value of attribute silent.
Class Method Summary collapse
-
.format(string, options = {}) ⇒ Object
Public: Formats the given string with the specified color through Term::ANSIColor.
- .no_color? ⇒ Boolean
-
.print(string, options = {}) ⇒ Object
Public: Passes .format to Kernel#print.
-
.puts(string, options = {}) ⇒ Object
Public: Passes .format to Kernel#puts.
- .silent? ⇒ Boolean
Class Attribute Details
.no_color ⇒ Object
Returns the value of attribute no_color.
38 39 40 |
# File 'lib/coveralls/output.rb', line 38 def no_color @no_color end |
.output ⇒ Object
44 45 46 |
# File 'lib/coveralls/output.rb', line 44 def output (defined?(@output) && @output) || $stdout end |
.silent ⇒ Object
Returns the value of attribute silent.
38 39 40 |
# File 'lib/coveralls/output.rb', line 38 def silent @silent end |
Class 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.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/coveralls/output.rb', line 66 def format(string, = {}) unless no_color? require 'term/ansicolor' [:color]&.split(/\s/)&.reverse_each do |color| next unless Term::ANSIColor.respond_to?(color.to_sym) string = Term::ANSIColor.send(color.to_sym, string) end end string end |
.no_color? ⇒ Boolean
48 49 50 |
# File 'lib/coveralls/output.rb', line 48 def no_color? defined?(@no_color) && @no_color end |
.print(string, options = {}) ⇒ Object
109 110 111 112 113 |
# File 'lib/coveralls/output.rb', line 109 def print(string, = {}) return if silent? ([:output] || output).print format(string, ) end |
.puts(string, options = {}) ⇒ Object
91 92 93 94 95 |
# File 'lib/coveralls/output.rb', line 91 def puts(string, = {}) return if silent? ([:output] || output).puts format(string, ) end |
.silent? ⇒ Boolean
115 116 117 |
# File 'lib/coveralls/output.rb', line 115 def silent? ENV['COVERALLS_SILENT'] || (defined?(@silent) && @silent) end |