Class: RubyRich::Live
- Inherits:
-
Object
- Object
- RubyRich::Live
- Defined in:
- lib/ruby_rich/live.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#listening ⇒ Object
Returns the value of attribute listening.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #find_layout(name) ⇒ Object
- #find_panel(name) ⇒ Object
-
#initialize(layout, refresh_rate) ⇒ Live
constructor
A new instance of Live.
- #move_cursor(x, y) ⇒ Object
- #run(proc = nil) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(layout, refresh_rate) ⇒ Live
Returns a new instance of Live.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_rich/live.rb', line 63 def initialize(layout, refresh_rate) @layout = layout @layout.live = self @refresh_rate = refresh_rate @running = true @last_frame = Time.now @cursor = TTY::Cursor @render = CacheRender.new @console = RubyRich::Console.new @params = {} end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
37 38 39 |
# File 'lib/ruby_rich/live.rb', line 37 def app @app end |
#layout ⇒ Object
Returns the value of attribute layout.
37 38 39 |
# File 'lib/ruby_rich/live.rb', line 37 def layout @layout end |
#listening ⇒ Object
Returns the value of attribute listening.
37 38 39 |
# File 'lib/ruby_rich/live.rb', line 37 def listening @listening end |
#params ⇒ Object
Returns the value of attribute params.
37 38 39 |
# File 'lib/ruby_rich/live.rb', line 37 def params @params end |
Class Method Details
.start(layout, refresh_rate: 30, &proc) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_rich/live.rb', line 39 def start(layout, refresh_rate: 30, &proc) setup_terminal live = new(layout, refresh_rate) proc.call(live) if proc live.run(proc) rescue => e puts e. ensure restore_terminal end |
Instance Method Details
#find_layout(name) ⇒ Object
95 96 97 |
# File 'lib/ruby_rich/live.rb', line 95 def find_layout(name) @layout[name] end |
#find_panel(name) ⇒ Object
99 100 101 |
# File 'lib/ruby_rich/live.rb', line 99 def find_panel(name) @layout[name].content end |
#move_cursor(x, y) ⇒ Object
91 92 93 |
# File 'lib/ruby_rich/live.rb', line 91 def move_cursor(x,y) print @cursor.move_to(x, y) end |
#run(proc = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruby_rich/live.rb', line 75 def run(proc = nil) while @running render_frame if @listening event_data = @console.get_key() @layout.notify_listeners(event_data) end sleep 1.0 / @refresh_rate end end |
#stop ⇒ Object
86 87 88 89 |
# File 'lib/ruby_rich/live.rb', line 86 def stop @running = false system("clear") end |