Module: Commandline::Output
- Included in:
- Docker::Error, Exercise::Instructions, Exercise::RenderMethods
- Defined in:
- lib/utils/commandline/output.rb
Instance Method Summary collapse
- #error(text) ⇒ Object
- #ok(text) ⇒ Object
- #output ⇒ Object
- #prefix(text, prefix) ⇒ Object
- #say(msg) ⇒ Object
Instance Method Details
#error(text) ⇒ Object
15 16 17 |
# File 'lib/utils/commandline/output.rb', line 15 def error(text) prefix(text, '[ERROR] ').red end |
#ok(text) ⇒ Object
11 12 13 |
# File 'lib/utils/commandline/output.rb', line 11 def ok(text) prefix(text, '[OK] ').green end |
#output ⇒ Object
3 4 5 |
# File 'lib/utils/commandline/output.rb', line 3 def output @output ||= STDOUT end |
#prefix(text, prefix) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/utils/commandline/output.rb', line 19 def prefix(text, prefix) lines = text.lines = "#{prefix}#{lines[0].strip}\n" lines[1..-1].each_with_index do |line, index| line = line.strip.chomp line = line.rjust(line.length + prefix.size) << (index.zero? ? line : line.prepend("\n")) end end |
#say(msg) ⇒ Object
7 8 9 |
# File 'lib/utils/commandline/output.rb', line 7 def say(msg) output.puts msg unless ENV['SILENT'] end |