Class: Teems::Formatters::Output
- Inherits:
-
Object
- Object
- Teems::Formatters::Output
show all
- Includes:
- OutputColors
- Defined in:
- lib/teems/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
Instance Method Summary
collapse
#blue, #bold, #cyan, #gray, #green, #magenta, #red, #with_quiet, #with_verbose, #yellow
Constructor Details
#initialize(io: $stdout, err: $stderr, color: nil, mode: :normal) ⇒ Output
Returns a new instance of Output.
43
44
45
46
47
48
|
# File 'lib/teems/formatters/output.rb', line 43
def initialize(io: $stdout, err: $stderr, color: nil, mode: :normal)
@io = io
@err = err
@color = [true, false].include?(color) ? color : io.tty?
@mode = mode
end
|
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
41
42
43
|
# File 'lib/teems/formatters/output.rb', line 41
def mode
@mode
end
|
Instance Method Details
#debug(message) ⇒ Object
82
83
84
85
86
|
# File 'lib/teems/formatters/output.rb', line 82
def debug(message)
return unless verbose?
@err.puts(colorize("#{gray('[debug]')} #{message}"))
end
|
#error(message) ⇒ Object
66
67
68
|
# File 'lib/teems/formatters/output.rb', line 66
def error(message)
@err.puts(colorize("#{red('Error:')} #{message}"))
end
|
#flush ⇒ Object
62
63
64
|
# File 'lib/teems/formatters/output.rb', line 62
def flush
@io.flush
end
|
#info(message) ⇒ Object
78
79
80
|
# File 'lib/teems/formatters/output.rb', line 78
def info(message)
puts(colorize(message))
end
|
#print(message) ⇒ Object
58
59
60
|
# File 'lib/teems/formatters/output.rb', line 58
def print(message)
write_unless_quiet { @io.print(message) }
end
|
#puts(message = '') ⇒ Object
54
55
56
|
# File 'lib/teems/formatters/output.rb', line 54
def puts(message = '')
write_unless_quiet { @io.puts(message) }
end
|
#quiet? ⇒ Boolean
51
|
# File 'lib/teems/formatters/output.rb', line 51
def quiet? = @mode == :quiet
|
#success(message) ⇒ Object
74
75
76
|
# File 'lib/teems/formatters/output.rb', line 74
def success(message)
puts(colorize("#{green('✓')} #{message}"))
end
|
#tty? ⇒ Boolean
52
|
# File 'lib/teems/formatters/output.rb', line 52
def tty? = @io.tty?
|
#verbose? ⇒ Boolean
50
|
# File 'lib/teems/formatters/output.rb', line 50
def verbose? = @mode == :verbose
|
#warn(message) ⇒ Object
70
71
72
|
# File 'lib/teems/formatters/output.rb', line 70
def warn(message)
write_unless_quiet { @err.puts(colorize("#{yellow('Warning:')} #{message}")) }
end
|