Class: RubyRich::ProgressBar::MultiProgress
- Inherits:
-
Object
- Object
- RubyRich::ProgressBar::MultiProgress
- Defined in:
- lib/ruby_rich/progress_bar.rb
Overview
多进度条管理器
Instance Method Summary collapse
- #add(title, total, **options) ⇒ Object
- #finish_all ⇒ Object
-
#initialize ⇒ MultiProgress
constructor
A new instance of MultiProgress.
- #render_all ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ MultiProgress
Returns a new instance of MultiProgress.
135 136 137 138 |
# File 'lib/ruby_rich/progress_bar.rb', line 135 def initialize @bars = [] @active = false end |
Instance Method Details
#add(title, total, **options) ⇒ Object
140 141 142 143 144 |
# File 'lib/ruby_rich/progress_bar.rb', line 140 def add(title, total, **) = ProgressBar.new(total, title: title, **) @bars << end |
#finish_all ⇒ Object
164 165 166 167 |
# File 'lib/ruby_rich/progress_bar.rb', line 164 def finish_all @active = false puts end |
#render_all ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ruby_rich/progress_bar.rb', line 151 def render_all return unless @active print "\e[#{@bars.length}A" unless @bars.empty? # 移动光标到顶部 @bars.each_with_index do |, index| = () puts "\e[K#{}" end $stdout.flush end |
#start ⇒ Object
146 147 148 149 |
# File 'lib/ruby_rich/progress_bar.rb', line 146 def start @active = true render_all end |