Class: LowFrame
- Inherits:
-
Object
- Object
- LowFrame
- Defined in:
- lib/support/low_frame.rb
Instance Attribute Summary collapse
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#screen_size ⇒ Object
readonly
Returns the value of attribute screen_size.
Instance Method Summary collapse
- #exit ⇒ Object
-
#initialize(renderer:, fps: 30, show_output: true) ⇒ LowFrame
constructor
A new instance of LowFrame.
- #render ⇒ Object
- #reset ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(renderer:, fps: 30, show_output: true) ⇒ LowFrame
Returns a new instance of LowFrame.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/support/low_frame.rb', line 8 def initialize(renderer:, fps: 30, show_output: true) @renderer = renderer @show_output = show_output # Millisecond duration of each frame. We lose a small amount of precision dropping the decimal. @frame_time = ((1.0 / fps) * 1000).to_i row_count, column_count = IO.console.winsize @screen_size = { row_count:, column_count: } @last_frame = nil setup if renderer && show_output end |
Instance Attribute Details
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
6 7 8 |
# File 'lib/support/low_frame.rb', line 6 def renderer @renderer end |
#screen_size ⇒ Object (readonly)
Returns the value of attribute screen_size.
6 7 8 |
# File 'lib/support/low_frame.rb', line 6 def screen_size @screen_size end |
Instance Method Details
#exit ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/support/low_frame.rb', line 41 def exit trap('INT') { reset system 'clear' exit } end |
#render ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/support/low_frame.rb', line 23 def render if @last_frame.nil? || ( - @last_frame) >= @frame_time system 'clear' if @show_output @last_frame = @renderer.render(screen_size: @screen_size) end end |
#reset ⇒ Object
37 38 39 |
# File 'lib/support/low_frame.rb', line 37 def reset print "\e[?25h\e[0m" # Show cursor and reset colors. end |
#setup ⇒ Object
32 33 34 35 |
# File 'lib/support/low_frame.rb', line 32 def setup print "\e[?25l" # Hide cursor. system 'clear' end |