Class: Ubalo::Tailer

Inherits:
Object
  • Object
show all
Defined in:
lib/ubalo/tailer.rb

Direct Known Subclasses

TimedTailer

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Tailer

Returns a new instance of Tailer.



3
4
5
6
# File 'lib/ubalo/tailer.rb', line 3

def initialize(logger)
  @logger = logger
  @output_position = 0
end

Instance Method Details

#tty?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/ubalo/tailer.rb', line 8

def tty?
  @logger.tty?
end

#update(message, output = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ubalo/tailer.rb', line 12

def update(message, output=nil)
  # Erase current line.
  if tty?
    @logger.print "\r"
    @logger.print " " * Integer(Util.columns)
    @logger.print "\r"
  end

  if output
    @logger.print output[@output_position..-1]
    @output_position = output.length
  end

  if tty?
    @logger.print Color.green(wrap(message))
  else
    @logger.puts wrap(message)
  end
end