Class: Jossh::OutputHandler

Inherits:
Object
  • Object
show all
Includes:
Colsole
Defined in:
lib/jossh/output_handler.rb

Overview

OutputHandler is responsible for generating the pretty output created by ssh! and ssh_script! commands.

Instance Method Summary collapse

Instance Method Details

#pretty_puts(lines, stream = nil) ⇒ Object

Print indented output while giving special treatment to strings that start with certain markers.

This method is used as the callback function by ssh! and ssh_script!

Params:

lines

A newline delimited string or array to pretty-print

Credits:

This function was inspired by Heroku and based on code from Mina



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jossh/output_handler.rb', line 25

def pretty_puts(lines, stream=nil)
  lines = lines.split("\n") if lines.is_a? String
  lines.each do |line|
    line = line.rstrip.gsub(/\t/, "        ")
    if stream == :stderr
      puts_stderr line
    elsif line =~ /^\-+> (.*?)$/
      puts_status $1
    elsif line =~ /^! (.*?)$/
      puts_error $1
    elsif line =~ /^\$ (.*?)$/
      puts_command $1
    else
      puts_stdout line
    end
  end
end