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.
-
#mouse ⇒ Object
Returns the value of attribute mouse.
-
#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
- #post(&block) ⇒ Object
- #run(proc = nil) ⇒ Object
- #shutdown ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(layout, refresh_rate) ⇒ Live
Returns a new instance of Live.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ruby_rich/live.rb', line 78 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 @event_queue = Queue.new @action_queue = Queue.new @event_thread = nil @params = {} if (log_path = ENV["RUBY_RICH_LOG"]).to_s.strip != "" FileUtils.mkdir_p(File.dirname(log_path)) RubyRich.logger = Logger.new(log_path) end end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
48 49 50 |
# File 'lib/ruby_rich/live.rb', line 48 def app @app end |
#layout ⇒ Object
Returns the value of attribute layout.
48 49 50 |
# File 'lib/ruby_rich/live.rb', line 48 def layout @layout end |
#listening ⇒ Object
Returns the value of attribute listening.
48 49 50 |
# File 'lib/ruby_rich/live.rb', line 48 def listening @listening end |
#mouse ⇒ Object
Returns the value of attribute mouse.
76 77 78 |
# File 'lib/ruby_rich/live.rb', line 76 def mouse @mouse end |
#params ⇒ Object
Returns the value of attribute params.
48 49 50 |
# File 'lib/ruby_rich/live.rb', line 48 def params @params end |
Class Method Details
.start(layout, refresh_rate: 30, mouse: false, alt_screen: false, autowrap: false, &proc) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruby_rich/live.rb', line 50 def start(layout, refresh_rate: 30, mouse: false, alt_screen: false, autowrap: false, &proc) setup_terminal(mouse: mouse, alt_screen: alt_screen, autowrap: autowrap) live = new(layout, refresh_rate) live.mouse = mouse proc.call(live) if proc live.run(proc) rescue Interrupt live&.stop rescue => e puts e. ensure live&.shutdown restore_terminal(mouse: mouse, alt_screen: alt_screen) end |
Instance Method Details
#find_layout(name) ⇒ Object
136 137 138 |
# File 'lib/ruby_rich/live.rb', line 136 def find_layout(name) @layout[name] end |
#find_panel(name) ⇒ Object
140 141 142 |
# File 'lib/ruby_rich/live.rb', line 140 def find_panel(name) @layout[name].content end |
#move_cursor(x, y) ⇒ Object
132 133 134 |
# File 'lib/ruby_rich/live.rb', line 132 def move_cursor(x,y) print @cursor.move_to(x, y) end |
#post(&block) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/ruby_rich/live.rb', line 111 def post(&block) return false unless block return false unless @running @action_queue << block true end |
#run(proc = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ruby_rich/live.rb', line 97 def run(proc = nil) start_event_thread if @listening while @running drain_action_queue break unless @running render_frame drain_event_queue if @listening sleep 1.0 / @refresh_rate end rescue Interrupt @running = false end |
#shutdown ⇒ Object
125 126 127 128 129 130 |
# File 'lib/ruby_rich/live.rb', line 125 def shutdown if @event_thread&.alive? @event_thread.kill @event_thread = nil end end |