Sha256: 4880bcb5d4127285f0b4b634bbcebf0d44dcfc83d2b437d9755e8a8b7af6c63c

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

require 'term/ansicolor'

module SSHKit

  module Formatter

    class Pretty < Abstract

      def write(obj)
        if obj.is_a? SSHKit::Command
          unless obj.started?
            original_output << "[#{c.green(obj.uuid)}] Running #{c.yellow(c.bold(String(obj)))} on #{c.yellow(obj.host.to_s)}\n"
          end
          if obj.complete? && !obj.stdout.empty?
            obj.stdout.lines.each do |line|
              original_output << c.green("\t" + line)
            end
          end
          if obj.complete? && !obj.stderr.empty?
            obj.stderr.lines.each do |line|
              original_output << c.red("\t" + line)
            end
          end
          if obj.finished?
            original_output << "[#{c.green(obj.uuid)}] Finished in #{sprintf('%5.3f seconds', obj.runtime)} command #{c.bold { obj.failure? ? c.red('failed') : c.green('successful') }}.\n"
          end
        else
          original_output << c.black(c.on_yellow("Output formatter doesn't know how to handle #{obj.inspect}\n"))
        end
      end
      alias :<< :write

      private

      def c
        @c ||= Term::ANSIColor
      end

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sshkit-0.0.14 lib/sshkit/formatters/pretty.rb
sshkit-0.0.13 lib/sshkit/formatters/pretty.rb
sshkit-0.0.12 lib/sshkit/formatters/pretty.rb
sshkit-0.0.11 lib/sshkit/formatters/pretty.rb
sshkit-0.0.10 lib/sshkit/formatters/pretty.rb
sshkit-0.0.9 lib/sshkit/formatters/pretty.rb
sshkit-0.0.8 lib/sshkit/formatters/pretty.rb
sshkit-0.0.7 lib/sshkit/formatters/pretty.rb
sshkit-0.0.6 lib/sshkit/formatters/pretty.rb
sshkit-0.0.5 lib/sshkit/formatters/pretty.rb
sshkit-0.0.4 lib/sshkit/formatters/pretty.rb
sshkit-0.0.3 lib/sshkit/formatters/pretty.rb
sshkit-0.0.2 lib/sshkit/formatters/pretty.rb