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
-
#initialize(renderer:, fps: 10, show_output: true) ⇒ LowFrame
constructor
A new instance of LowFrame.
- #render ⇒ Object
- #resize ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(renderer:, fps: 10, show_output: true) ⇒ LowFrame
Returns a new instance of LowFrame.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/support/low_frame.rb', line 8 def initialize(renderer:, fps: 10, 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 @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
#render ⇒ Object
19 20 21 22 23 24 |
# File 'lib/support/low_frame.rb', line 19 def render return unless @last_frame.nil? || ( - @last_frame) >= @frame_time @last_frame = @renderer.render(screen_size: @screen_size) end |
#resize ⇒ Object
43 44 45 46 |
# File 'lib/support/low_frame.rb', line 43 def resize row_count, column_count = IO.console.winsize @screen_size = { row_count:, column_count: } end |
#setup ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/support/low_frame.rb', line 26 def setup print "\e[?25l" # Hide cursor. system 'clear' resize Signal.trap('WINCH') do resize end Signal.trap('INT') do print "\e[?25h\e[0m" # Show cursor and reset colors. system 'clear' exit end end |