Class: TTY::Command::Printers::Pretty
- Defined in:
- lib/tty/command/printers/pretty.rb
Constant Summary collapse
- TIME_FORMAT =
"%5.3f %s".freeze
Instance Attribute Summary
Attributes inherited from Abstract
#err_data, #options, #out_data, #output
Instance Method Summary collapse
-
#initialize ⇒ Pretty
constructor
A new instance of Pretty.
- #print_command_err_data(cmd, *args) ⇒ Object
- #print_command_exit(cmd, status, runtime, *args) ⇒ Object
- #print_command_out_data(cmd, *args) ⇒ Object
- #print_command_start(cmd, *args) ⇒ Object
-
#write(cmd, message, data = nil) ⇒ Object
private
Write message out to output.
Constructor Details
#initialize ⇒ Pretty
Returns a new instance of Pretty.
14 15 16 17 |
# File 'lib/tty/command/printers/pretty.rb', line 14 def initialize(*) super @uuid = .fetch(:uuid) { true } end |
Instance Method Details
#print_command_err_data(cmd, *args) ⇒ Object
30 31 32 33 |
# File 'lib/tty/command/printers/pretty.rb', line 30 def print_command_err_data(cmd, *args) = args.map(&:chomp).join(' ') write(cmd, "\t" + decorate(, :red), err_data) end |
#print_command_exit(cmd, status, runtime, *args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tty/command/printers/pretty.rb', line 35 def print_command_exit(cmd, status, runtime, *args) if cmd.only_output_on_error && !status.zero? output << out_data output << err_data end runtime = TIME_FORMAT % [runtime, pluralize(runtime, 'second')] = ["Finished in #{runtime}"] << " with exit status #{status}" if status << " (#{success_or_failure(status)})" write(cmd, .join) end |
#print_command_out_data(cmd, *args) ⇒ Object
25 26 27 28 |
# File 'lib/tty/command/printers/pretty.rb', line 25 def print_command_out_data(cmd, *args) = args.map(&:chomp).join(' ') write(cmd, "\t#{message}", out_data) end |
#print_command_start(cmd, *args) ⇒ Object
19 20 21 22 23 |
# File 'lib/tty/command/printers/pretty.rb', line 19 def print_command_start(cmd, *args) = ["Running #{decorate(cmd.to_command, :yellow, :bold)}"] << args.map(&:chomp).join(' ') unless args.empty? write(cmd, .join) end |
#write(cmd, message, data = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write message out to output
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tty/command/printers/pretty.rb', line 51 def write(cmd, , data = nil) cmd_set_uuid = cmd..fetch(:uuid, true) uuid_needed = cmd.[:uuid].nil? ? @uuid : cmd_set_uuid out = [] if uuid_needed out << "[#{decorate(cmd.uuid, :green)}] " unless cmd.uuid.nil? end out << "#{message}\n" target = (cmd.only_output_on_error && !data.nil?) ? data : output target << out.join end |