Class: Foruiman::Plain

Inherits:
Object
  • Object
show all
Defined in:
lib/foruiman/plain.rb

Instance Method Summary collapse

Constructor Details

#initialize(engine, output: $stdout) ⇒ Plain

Returns a new instance of Plain.



4
5
6
7
# File 'lib/foruiman/plain.rb', line 4

def initialize(engine, output: $stdout)
  @engine = engine
  @output = output
end

Instance Method Details

#run ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/foruiman/plain.rb', line 9

def run
  @engine.on_event do |event|
    record = event.record
    next unless record&.complete

    text = record.text.gsub(Foruiman::ANSI::SGR, "")
    @output.puts "#{record.time.strftime('%H:%M:%S')} #{record.name} [#{record.stream}] | #{text}"
    @output.flush
  end
  @engine.run
rescue Errno::EPIPE
  0
end