Class: WhirledPeas::Device::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/whirled_peas/device/screen.rb

Instance Method Summary collapse

Constructor Details

#initialize(output: STDOUT) ⇒ Screen

Returns a new instance of Screen.



6
7
8
# File 'lib/whirled_peas/device/screen.rb', line 6

def initialize(output: STDOUT)
  @output = output
end

Instance Method Details

#handle_rendered_frames(rendered_frames) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/whirled_peas/device/screen.rb', line 10

def handle_rendered_frames(rendered_frames)
  next_frame_at = Time.now
  rendered_frames.each do |rendered_frame|
    next_frame_at += rendered_frame.duration
    output.print(rendered_frame.strokes)
    output.flush
    sleep([0, next_frame_at - Time.now].max)
  end
end