Class: Plywood::FancyLogger

Inherits:
IOHandler show all
Defined in:
lib/plywood/fancy_logger.rb,
lib/plywood/fancy_logger/frame.rb,
lib/plywood/fancy_logger/fancy_log.rb

Defined Under Namespace

Classes: FancyLog, Frame

Constant Summary collapse

CSI =
"\e[".freeze
FPS =

frames per second

20
STOP_DELAY =

seconds

0.6

Instance Method Summary collapse

Constructor Details

#initialize(ios) ⇒ FancyLogger

Returns a new instance of FancyLogger.



12
13
14
15
16
17
18
19
# File 'lib/plywood/fancy_logger.rb', line 12

def initialize(ios)
  super
  @names = ios.map(&:name).uniq
  @logs = @names
    .map { |name, _index| [name, FancyLog.new(name)] }
    .to_h
  Color.enable($stdout)
end

Instance Method Details

#handle_exit_statuses!(statuses, commands) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/plywood/fancy_logger.rb', line 54

def handle_exit_statuses!(statuses, commands)
  statuses.each do |pid, status|
    command = commands.detect { |item| item.pid == pid }
    @logs[command.name].exit_status = status
  end
  self
end

#handle_io!Object



46
47
48
49
50
51
52
# File 'lib/plywood/fancy_logger.rb', line 46

def handle_io!
  loop do
    readers, _writers = IO.select(@ios)
    readers.each { |stream| copy_stream(stream) }
  end
  self
end

#startObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/plywood/fancy_logger.rb', line 21

def start
  @initial_console_mode = $stdout.console_mode
  IO.console.raw!
  hide_cursor
  use_alternate_screen_buffer
  @render_thread = Thread.new do
    loop do
      render
      sleep(1.0 / FPS)
    end
  end
  self
end

#stopObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/plywood/fancy_logger.rb', line 35

def stop
  sleep STOP_DELAY
  Thread.kill(@render_thread) unless @render_thread.nil?
  # IO.console.cooked!
  $stdout.console_mode = @initial_console_mode
  use_main_screen_buffer
  show_cursor
  render_report
  self
end