Class: RubyRich::ProgressBar::MultiProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/progress_bar.rb

Overview

多进度条管理器

Instance Method Summary collapse

Constructor Details

#initializeMultiProgress

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, **options)
  bar = ProgressBar.new(total, title: title, **options)
  @bars << bar
  bar
end

#finish_allObject



164
165
166
167
# File 'lib/ruby_rich/progress_bar.rb', line 164

def finish_all
  @active = false
  puts
end

#render_allObject



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 |bar, index|
    bar_output = render_bar_line(bar)
    puts "\e[K#{bar_output}"
  end
  
  $stdout.flush
end

#startObject



146
147
148
149
# File 'lib/ruby_rich/progress_bar.rb', line 146

def start
  @active = true
  render_all
end