Class: Slk::Formatters::Output
- Inherits:
-
Object
- Object
- Slk::Formatters::Output
- Defined in:
- lib/slk/formatters/output.rb
Overview
Terminal output with ANSI color support
Constant Summary collapse
- COLORS =
{ red: "\e[0;31m", green: "\e[0;32m", yellow: "\e[0;33m", blue: "\e[0;34m", magenta: "\e[0;35m", cyan: "\e[0;36m", gray: "\e[0;90m", bold: "\e[1m", reset: "\e[0m" }.freeze
Instance Attribute Summary collapse
-
#quiet ⇒ Object
readonly
Returns the value of attribute quiet.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #blue(text) ⇒ Object
- #bold(text) ⇒ Object
- #cyan(text) ⇒ Object
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #gray(text) ⇒ Object
- #green(text) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(io: $stdout, err: $stderr, color: nil, verbose: false, quiet: false) ⇒ Output
constructor
A new instance of Output.
- #magenta(text) ⇒ Object
- #print(message) ⇒ Object
- #puts(message = '') ⇒ Object
-
#red(text) ⇒ Object
Color helpers.
- #success(message) ⇒ Object
- #warn(message) ⇒ Object
- #with_quiet(value) ⇒ Object
- #with_verbose(value) ⇒ Object
- #yellow(text) ⇒ Object
Constructor Details
#initialize(io: $stdout, err: $stderr, color: nil, verbose: false, quiet: false) ⇒ Output
Returns a new instance of Output.
21 22 23 24 25 26 27 |
# File 'lib/slk/formatters/output.rb', line 21 def initialize(io: $stdout, err: $stderr, color: nil, verbose: false, quiet: false) @io = io @err = err @color = color.nil? ? io.tty? : color @verbose = verbose @quiet = quiet end |
Instance Attribute Details
#quiet ⇒ Object (readonly)
Returns the value of attribute quiet.
19 20 21 |
# File 'lib/slk/formatters/output.rb', line 19 def quiet @quiet end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
19 20 21 |
# File 'lib/slk/formatters/output.rb', line 19 def verbose @verbose end |
Instance Method Details
#blue(text) ⇒ Object
63 |
# File 'lib/slk/formatters/output.rb', line 63 def blue(text) = wrap(:blue, text) |
#bold(text) ⇒ Object
67 |
# File 'lib/slk/formatters/output.rb', line 67 def bold(text) = wrap(:bold, text) |
#cyan(text) ⇒ Object
65 |
# File 'lib/slk/formatters/output.rb', line 65 def cyan(text) = wrap(:cyan, text) |
#debug(message) ⇒ Object
53 54 55 56 57 |
# File 'lib/slk/formatters/output.rb', line 53 def debug() return unless @verbose @err.puts(colorize("#{gray('[debug]')} #{}")) end |
#error(message) ⇒ Object
37 38 39 |
# File 'lib/slk/formatters/output.rb', line 37 def error() @err.puts(colorize("#{red('Error:')} #{}")) end |
#gray(text) ⇒ Object
66 |
# File 'lib/slk/formatters/output.rb', line 66 def gray(text) = wrap(:gray, text) |
#green(text) ⇒ Object
61 |
# File 'lib/slk/formatters/output.rb', line 61 def green(text) = wrap(:green, text) |
#info(message) ⇒ Object
49 50 51 |
# File 'lib/slk/formatters/output.rb', line 49 def info() puts(colorize()) end |
#magenta(text) ⇒ Object
64 |
# File 'lib/slk/formatters/output.rb', line 64 def magenta(text) = wrap(:magenta, text) |
#print(message) ⇒ Object
33 34 35 |
# File 'lib/slk/formatters/output.rb', line 33 def print() @io.print() unless @quiet end |
#puts(message = '') ⇒ Object
29 30 31 |
# File 'lib/slk/formatters/output.rb', line 29 def puts( = '') @io.puts() unless @quiet end |
#red(text) ⇒ Object
Color helpers
60 |
# File 'lib/slk/formatters/output.rb', line 60 def red(text) = wrap(:red, text) |
#success(message) ⇒ Object
45 46 47 |
# File 'lib/slk/formatters/output.rb', line 45 def success() puts(colorize("#{green('✓')} #{}")) end |
#warn(message) ⇒ Object
41 42 43 |
# File 'lib/slk/formatters/output.rb', line 41 def warn() @err.puts(colorize("#{yellow('Warning:')} #{}")) unless @quiet end |
#with_quiet(value) ⇒ Object
73 74 75 |
# File 'lib/slk/formatters/output.rb', line 73 def with_quiet(value) self.class.new(io: @io, err: @err, color: @color, verbose: @verbose, quiet: value) end |
#with_verbose(value) ⇒ Object
69 70 71 |
# File 'lib/slk/formatters/output.rb', line 69 def with_verbose(value) self.class.new(io: @io, err: @err, color: @color, verbose: value, quiet: @quiet) end |
#yellow(text) ⇒ Object
62 |
# File 'lib/slk/formatters/output.rb', line 62 def yellow(text) = wrap(:yellow, text) |