powerbar 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ This is PowerBar - The last progressbar-library you'll ever need.
13
13
 
14
14
  * Fully customizable; all output is template-driven.
15
15
 
16
- * All output is optional. You may use PowerBar to silently collect progress
16
+ * All output is optional. You may set PowerBar to silently collect progress
17
17
  information (percentage-done, throughput, ETA, etc.) and then use the
18
18
  computed values elsewhere in your app.
19
19
 
@@ -50,7 +50,7 @@ Then look at the {source-code}[https://github.com/busyloop/powerbar/blob/master/
50
50
 
51
51
  p = PowerBar.new
52
52
 
53
- # Override some default values to demonstrate how the settings work
53
+ # Override some defaults to demonstrate how the settings work
54
54
  p.settings.tty.finite.template.barchar = '*'
55
55
  p.settings.tty.finite.template.padchar = '.'
56
56
 
@@ -8,11 +8,23 @@ def demo_1
8
8
  step = 1000
9
9
 
10
10
  p = PowerBar.new
11
+
12
+ # This is how you alter the settings.
13
+ # (see the source-code for all available settings)
14
+ p.settings.tty.finite.show_eta = true
15
+
11
16
  (0..total).step(step).each do |i|
12
17
  p.show({:msg => 'DEMO 1 - Ten seconds of progress', :done => i, :total => total})
13
18
  sleep 0.1
14
19
  end
15
- p.close
20
+
21
+ # close(true) will set the bar to 100% before closing.
22
+ # use this when you are sure your operation has finished but
23
+ # for some reason 'done' may still be smaller than 'total'.
24
+ #
25
+ # this is not necessary in this example, and usually a bad idea,
26
+ # but demonstrating here so you know it exists.
27
+ p.close(true)
16
28
  end
17
29
 
18
30
  # DEMO 2
@@ -236,7 +248,7 @@ def demo_10
236
248
  sleep 0.1
237
249
  end
238
250
  p.wipe
239
- p.close
251
+ puts "Thanks for watching! ;-)"
240
252
  end
241
253
 
242
254
  begin
@@ -49,7 +49,8 @@ class PowerBar
49
49
  :finite => { # <== Settings for a finite progress bar (when total != :unknown)
50
50
  # The :output Proc is called to draw on the screen --------------------.
51
51
  :output => Proc.new{ |s| $stderr.print s[0..terminal_width()-1] }, # <-'
52
- :interval => 0.1, # Minimum interval between screen refreshes (in seconds)
52
+ :interval => 0.1, # Minimum interval between screen refreshes (in seconds)
53
+ :show_eta => true, # Set to false if you want to hide the ETA without changing the template
53
54
  :template => { # <== template for a finite progress bar on a tty
54
55
  :pre => "\e[1000D\e[?25l", # printed before the progress-bar
55
56
  #
@@ -77,6 +78,7 @@ class PowerBar
77
78
  :infinite => { # <== Settings for an infinite progress "bar" (when total is :unknown)
78
79
  :output => Proc.new{ |s| $stderr.print s[0..terminal_width()-1] },
79
80
  :interval => 0.1,
81
+ :show_eta => false,
80
82
  :template => {
81
83
  :pre => "\e[1000D\e[?25l",
82
84
  :main => "${<msg>}: ${<done> }${<rate>/s }${<elapsed>}",
@@ -94,6 +96,7 @@ class PowerBar
94
96
  # You may want to hook in your favorite Logger-Library here. ---.
95
97
  :output => Proc.new{ |s| $stderr.print s }, # <----------------'
96
98
  :interval => 1,
99
+ :show_eta => true,
97
100
  :line_width => 78, # Maximum output line width
98
101
  :template => {
99
102
  :pre => '',
@@ -109,6 +112,7 @@ class PowerBar
109
112
  :infinite => {
110
113
  :output => Proc.new{ |s| $stderr.print s },
111
114
  :interval => 1,
115
+ :show_eta => false,
112
116
  :line_width => 78,
113
117
  :template => {
114
118
  :pre => "",
@@ -165,7 +169,19 @@ class PowerBar
165
169
 
166
170
  # Print the close-template and defuse the exit-hook.
167
171
  # Be a good citizen, always close your PowerBars!
168
- def close
172
+ def close(fill=false)
173
+ show(
174
+ {
175
+ :done => fill && !state.total.is_a?(Symbol) ? state.total : state.done,
176
+ :tty => {
177
+ :finite => { :show_eta => false },
178
+ :infinite => { :show_eta => false },
179
+ },
180
+ :notty => {
181
+ :finite => { :show_eta => false },
182
+ :infinite => { :show_eta => false },
183
+ },
184
+ }, true)
169
185
  scope.output.call(scope.template.close) unless scope.template.close.nil?
170
186
  state.closed = true
171
187
  end
@@ -190,8 +206,8 @@ class PowerBar
190
206
 
191
207
  # Output the PowerBar.
192
208
  # Returns true if bar was shown, false otherwise.
193
- def show(opts={})
194
- return false if scope.interval > Time.now - state.time_last_show
209
+ def show(opts={}, force=false)
210
+ return false if scope.interval > Time.now - state.time_last_show and force == false
195
211
 
196
212
  update(opts)
197
213
  hook_exit
@@ -246,6 +262,7 @@ class PowerBar
246
262
 
247
263
  # returns nil when eta is < 1 second
248
264
  def h_eta
265
+ return nil unless scope.show_eta
249
266
  1 < eta ? humanize_interval(eta) : nil
250
267
  end
251
268
 
@@ -1,3 +1,3 @@
1
1
  class Powerbar
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powerbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000Z
12
+ date: 2012-01-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ansi
16
- requirement: &18446200 !ruby/object:Gem::Requirement
16
+ requirement: &17713320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18446200
24
+ version_requirements: *17713320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hashie
27
- requirement: &18432940 !ruby/object:Gem::Requirement
27
+ requirement: &17712340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18432940
35
+ version_requirements: *17712340
36
36
  description: The last progressbar-library you'll ever need
37
37
  email:
38
38
  - moe@busyloop.net