Class: RubyRich::Live
- Inherits:
-
Object
- Object
- RubyRich::Live
- Defined in:
- lib/ruby_rich/live.rb
Constant Summary collapse
- RESIZE_POLL_INTERVAL =
0.25
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
- #refresh ⇒ Object
- #run(proc = nil) ⇒ Object
- #shutdown ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(layout, refresh_rate) ⇒ Live
Returns a new instance of Live.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ruby_rich/live.rb', line 98 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 @wake_mutex = Mutex.new @wake_condition = ConditionVariable.new @dirty = true @last_terminal_size = 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.
68 69 70 |
# File 'lib/ruby_rich/live.rb', line 68 def app @app end |
#layout ⇒ Object
Returns the value of attribute layout.
68 69 70 |
# File 'lib/ruby_rich/live.rb', line 68 def layout @layout end |
#listening ⇒ Object
Returns the value of attribute listening.
68 69 70 |
# File 'lib/ruby_rich/live.rb', line 68 def listening @listening end |
#mouse ⇒ Object
Returns the value of attribute mouse.
96 97 98 |
# File 'lib/ruby_rich/live.rb', line 96 def mouse @mouse end |
#params ⇒ Object
Returns the value of attribute params.
68 69 70 |
# File 'lib/ruby_rich/live.rb', line 68 def params @params end |
Class Method Details
.start(layout, refresh_rate: 30, mouse: false, alt_screen: false, autowrap: false, &proc) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ruby_rich/live.rb', line 70 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
173 174 175 |
# File 'lib/ruby_rich/live.rb', line 173 def find_layout(name) @layout[name] end |
#find_panel(name) ⇒ Object
177 178 179 |
# File 'lib/ruby_rich/live.rb', line 177 def find_panel(name) @layout[name].content end |
#move_cursor(x, y) ⇒ Object
169 170 171 |
# File 'lib/ruby_rich/live.rb', line 169 def move_cursor(x,y) print @cursor.move_to(x, y) end |
#post(&block) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/ruby_rich/live.rb', line 138 def post(&block) return false unless block return false unless @running @action_queue << block wake true end |
#refresh ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/ruby_rich/live.rb', line 147 def refresh return false unless @running mark_dirty wake true end |
#run(proc = nil) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ruby_rich/live.rb', line 121 def run(proc = nil) start_event_thread if @listening while @running action_processed = drain_action_queue break unless @running event_processed = @listening ? drain_event_queue : false if consume_dirty || action_processed || event_processed || terminal_size_changed? render_frame else wait_for_activity end end rescue Interrupt @running = false end |
#shutdown ⇒ Object
162 163 164 165 166 167 |
# File 'lib/ruby_rich/live.rb', line 162 def shutdown if @event_thread&.alive? @event_thread.kill @event_thread = nil end end |