Class: RubyRich::Status::Monitor
- Inherits:
-
Object
- Object
- RubyRich::Status::Monitor
- Defined in:
- lib/ruby_rich/status.rb
Overview
实时状态监控
Instance Method Summary collapse
- #add_item(key, label, &block) ⇒ Object
-
#initialize(refresh_rate: 1.0) ⇒ Monitor
constructor
A new instance of Monitor.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(refresh_rate: 1.0) ⇒ Monitor
Returns a new instance of Monitor.
191 192 193 194 195 |
# File 'lib/ruby_rich/status.rb', line 191 def initialize(refresh_rate: 1.0) @refresh_rate = refresh_rate @items = {} @running = false end |
Instance Method Details
#add_item(key, label, &block) ⇒ Object
197 198 199 200 201 202 203 |
# File 'lib/ruby_rich/status.rb', line 197 def add_item(key, label, &block) @items[key] = { label: label, block: block } self end |
#start ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/ruby_rich/status.rb', line 205 def start @running = true Thread.new do while @running system('clear') puts render_status sleep @refresh_rate end end end |
#stop ⇒ Object
217 218 219 |
# File 'lib/ruby_rich/status.rb', line 217 def stop @running = false end |