Class: Txray::WatchCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/txray/watch_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(path:, threshold_ms:, io: $stdout, from_start: false) ⇒ WatchCommand

Returns a new instance of WatchCommand.



5
6
7
8
9
10
11
# File 'lib/txray/watch_command.rb', line 5

def initialize(path:, threshold_ms:, io: $stdout, from_start: false)
  @path = path
  @io = io
  @monitor = Monitor.new(threshold_ms: threshold_ms)
  @tail = Tail.new(path, from_start: from_start)
  @view = Reporters::Live.new(io: io, path: path, threshold_ms: threshold_ms)
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/txray/watch_command.rb', line 13

def run
  return stream unless @io.tty?

  @view.open
  @view.draw(@monitor)
  @tail.each_batch do |lines|
    next if lines.empty?

    lines.each { |line| @monitor.absorb(line) }
    @view.draw(@monitor)
  end
rescue Interrupt
  nil
ensure
  @view.close(@monitor) if @io.tty?
end