Class: Autowow::Executor::BufferingPretty
- Inherits:
-
TTY::Command::Printers::Pretty
- Object
- TTY::Command::Printers::Pretty
- Autowow::Executor::BufferingPretty
- Defined in:
- lib/autowow/executor.rb
Instance Method Summary collapse
- #finished_lines(string) ⇒ Object
-
#initialize ⇒ BufferingPretty
constructor
A new instance of BufferingPretty.
- #multiple_lines?(string) ⇒ Boolean
- #print_command_exit(cmd, status, runtime, *args) ⇒ Object
- #print_command_out_data(cmd, *args) ⇒ Object (also: #print_command_err_data)
- #unfinished_line(string) ⇒ Object
- #write(cmd, message, uuid_needed = true) ⇒ Object
Constructor Details
#initialize ⇒ BufferingPretty
Returns a new instance of BufferingPretty.
23 24 25 26 |
# File 'lib/autowow/executor.rb', line 23 def initialize(*) super @out = "" end |
Instance Method Details
#finished_lines(string) ⇒ Object
49 50 51 |
# File 'lib/autowow/executor.rb', line 49 def finished_lines(string) string.each_line.to_a[0..-2].map(&:chomp) end |
#multiple_lines?(string) ⇒ Boolean
57 58 59 |
# File 'lib/autowow/executor.rb', line 57 def multiple_lines?(string) string.each_line.count > 1 end |
#print_command_exit(cmd, status, runtime, *args) ⇒ Object
36 37 38 39 40 |
# File 'lib/autowow/executor.rb', line 36 def print_command_exit(cmd, status, runtime, *args) @out.each_line.map(&:chomp).each { |line| write(cmd, line) } super write(TTY::Command::Cmd.new("dummy"), "", false) end |
#print_command_out_data(cmd, *args) ⇒ Object Also known as: print_command_err_data
28 29 30 31 32 33 |
# File 'lib/autowow/executor.rb', line 28 def print_command_out_data(cmd, *args) @out << args.join(" ") return unless multiple_lines?(@out) finished_lines(@out).each { |line| write(cmd, line) } @out = unfinished_line(@out) end |
#unfinished_line(string) ⇒ Object
53 54 55 |
# File 'lib/autowow/executor.rb', line 53 def unfinished_line(string) string.each_line.to_a[-1] end |
#write(cmd, message, uuid_needed = true) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/autowow/executor.rb', line 42 def write(cmd, , uuid_needed = true) out = [] out << "[#{decorate(cmd.uuid, :green)}] " if uuid_needed && !cmd.uuid.nil? out << "#{}\n" output << out.join end |