powerbar 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/powerbar-demo +10 -11
- data/lib/powerbar.rb +20 -10
- data/lib/powerbar/version.rb +1 -1
- data/powerbar.gemspec +0 -1
- metadata +62 -35
data/bin/powerbar-demo
CHANGED
@@ -76,8 +76,8 @@ def demo_4
|
|
76
76
|
p.settings.tty.finite.template.main = \
|
77
77
|
"${<msg>} ${<bar> }\e[0m${<rate>/s} \e[33;1m${<percent>%} " +
|
78
78
|
"\e[36;1m${<elapsed>}\e[31;1m${ ETA: <eta>}"
|
79
|
-
p.settings.tty.finite.template.padchar = "\e[30;1m
|
80
|
-
p.settings.tty.finite.template.barchar = "\e[34;1m
|
79
|
+
p.settings.tty.finite.template.padchar = "\e[30;1m#{p.settings.tty.finite.template.padchar}"
|
80
|
+
p.settings.tty.finite.template.barchar = "\e[34;1m#{p.settings.tty.finite.template.barchar}"
|
81
81
|
p.settings.tty.finite.template.exit = "\e[?25h\e[0m" # clean up after us
|
82
82
|
p.settings.tty.finite.template.close = "\e[?25h\e[0m\n" # clean up after us
|
83
83
|
p.settings.tty.finite.output = Proc.new{ |s|
|
@@ -209,8 +209,8 @@ def demo_10
|
|
209
209
|
step = 1000
|
210
210
|
text = " " * 30 + "DEMO 10 - OMGWTFBBQ!"
|
211
211
|
p = PowerBar.new
|
212
|
-
p.settings.tty.finite.template.padchar = "\e[30;1m
|
213
|
-
p.settings.tty.finite.template.barchar = "\e[34;1m
|
212
|
+
p.settings.tty.finite.template.padchar = "\e[30;1m#{p.settings.tty.finite.template.padchar}"
|
213
|
+
p.settings.tty.finite.template.barchar = "\e[34;1m#{p.settings.tty.finite.template.barchar}"
|
214
214
|
p.settings.tty.finite.output = Proc.new{ |s| $stderr.print s }
|
215
215
|
j = 0
|
216
216
|
total = 300000000
|
@@ -221,10 +221,10 @@ def demo_10
|
|
221
221
|
|
222
222
|
(0..total).step(step).each do |i|
|
223
223
|
p.send(:state).scope = nil # omghax, don't try this at home!
|
224
|
-
|
225
|
-
|
224
|
+
wtf_range = (j % text.length)..((j % text.length) + 25)
|
225
|
+
wtf = sprintf('%-26s', text[wtf_range])
|
226
|
+
wtf.gsub!(/./) { |char| rand(2).zero? ? char.downcase : char.upcase }
|
226
227
|
p.show(
|
227
|
-
{
|
228
228
|
:msg => wtf,
|
229
229
|
:done => i,
|
230
230
|
:total => total,
|
@@ -232,8 +232,8 @@ def demo_10
|
|
232
232
|
:tty => {
|
233
233
|
:finite => {
|
234
234
|
:template => {
|
235
|
-
:barchar => "\e[36;1m
|
236
|
-
:padchar => "\e[0;34m
|
235
|
+
:barchar => "\e[36;1m#{spin[j%spin.length..j%spin.length]}",
|
236
|
+
:padchar => "\e[0;34m#{spun[j%spun.length..j%spun.length]}",
|
237
237
|
:main => "\e[#{rand(1)};3#{rand(7)}m${<msg>}\e[0m "+
|
238
238
|
"\e[0m${<bar> }\e[0m${<rate>/s} "+
|
239
239
|
"\e[33;1m${<percent>%} " +
|
@@ -243,8 +243,7 @@ def demo_10
|
|
243
243
|
}
|
244
244
|
}
|
245
245
|
}
|
246
|
-
}
|
247
|
-
}
|
246
|
+
}
|
248
247
|
)
|
249
248
|
j += 1
|
250
249
|
sleep 0.1
|
data/lib/powerbar.rb
CHANGED
@@ -29,6 +29,7 @@ require 'hashie/mash'
|
|
29
29
|
#
|
30
30
|
class PowerBar
|
31
31
|
STRIP_ANSI = Regexp.compile '\e\[(\d+)(;\d+)?(;\d+)?[m|K]', nil
|
32
|
+
RUBY18 = RUBY_VERSION[0..2] == "1.8"
|
32
33
|
|
33
34
|
def initialize(opts={})
|
34
35
|
@@exit_hooked = false
|
@@ -71,8 +72,8 @@ class PowerBar
|
|
71
72
|
:wipe => "\e[0m\e[1000D\e[K", # printed when 'wipe' is called
|
72
73
|
:close => "\e[?25h\n", # printed when 'close' is called
|
73
74
|
:exit => "\e[?25h", # printed if the process exits unexpectedly
|
74
|
-
:barchar => "\u2588",
|
75
|
-
:padchar => "\u2022"
|
75
|
+
:barchar => RUBY18 ? '#' : "\u2588", # fill-char for the progress-bar
|
76
|
+
:padchar => RUBY18 ? '.' : "\u2022" # padding-char for the progress-bar
|
76
77
|
},
|
77
78
|
},
|
78
79
|
:infinite => { # <== Settings for an infinite progress "bar" (when total is :unknown)
|
@@ -86,8 +87,8 @@ class PowerBar
|
|
86
87
|
:wipe => "\e[0m\e[1000D\e[K",
|
87
88
|
:close => "\e[?25h\n",
|
88
89
|
:exit => "\e[?25h",
|
89
|
-
:barchar => "\u2588",
|
90
|
-
:padchar => "\u2022"
|
90
|
+
:barchar => RUBY18 ? '#' : "\u2588",
|
91
|
+
:padchar => RUBY18 ? '.' : "\u2022"
|
91
92
|
},
|
92
93
|
}
|
93
94
|
},
|
@@ -288,7 +289,7 @@ class PowerBar
|
|
288
289
|
end
|
289
290
|
|
290
291
|
def h_rate
|
291
|
-
humanize_quantity(
|
292
|
+
humanize_quantity(round(rate, 1))
|
292
293
|
end
|
293
294
|
|
294
295
|
def total
|
@@ -316,6 +317,15 @@ class PowerBar
|
|
316
317
|
@state
|
317
318
|
end
|
318
319
|
|
320
|
+
def round(number, digit)
|
321
|
+
if number.zero? or number.nan?
|
322
|
+
number
|
323
|
+
else
|
324
|
+
factor = 10.0 ** digit
|
325
|
+
(number * factor).round / factor
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
319
329
|
# Cap'n Hook
|
320
330
|
def exit!
|
321
331
|
return if state.closed
|
@@ -327,17 +337,17 @@ class PowerBar
|
|
327
337
|
skip.each do |s|
|
328
338
|
tpl = tpl.gsub(/\$\{([^<]*)<#{s}>([^}]*)\}/, '\1\2')
|
329
339
|
end
|
330
|
-
tpl.gsub(
|
340
|
+
tpl.gsub(/\$\{[^\}]+\}/) do |var|
|
331
341
|
sub = nil
|
332
342
|
r = var.gsub(/<[^>]+>/) do |t|
|
333
343
|
t = t[1..-2]
|
334
344
|
begin
|
335
|
-
sub =
|
345
|
+
sub = send "h_#{t}"
|
336
346
|
rescue NoMethodError
|
337
347
|
raise NameError, "Invalid token '#{t}' in template '#{tplid}'"
|
338
348
|
end
|
339
|
-
end
|
340
|
-
sub.nil? ? '' : r
|
349
|
+
end
|
350
|
+
sub.nil? ? '' : r[2..-2]
|
341
351
|
end
|
342
352
|
end
|
343
353
|
|
@@ -355,7 +365,7 @@ class PowerBar
|
|
355
365
|
number /= kilo ** exponent
|
356
366
|
|
357
367
|
unit = HQ_UNITS[exponent]
|
358
|
-
return format.gsub(/%n/,
|
368
|
+
return format.gsub(/%n/, round(number, 1).to_s).gsub(/%u/, unit)
|
359
369
|
end
|
360
370
|
|
361
371
|
def humanize_interval(s)
|
data/lib/powerbar/version.rb
CHANGED
data/powerbar.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/busyloop/powerbar"
|
11
11
|
s.summary = %q{The last progressbar-library you'll ever need}
|
12
12
|
s.description = %q{The last progressbar-library you'll ever need}
|
13
|
-
s.required_ruby_version = ">= 1.9.2"
|
14
13
|
s.license = "MIT"
|
15
14
|
|
16
15
|
s.add_dependency "ansi", "~> 1.4.0"
|
metadata
CHANGED
@@ -1,46 +1,64 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: powerbar
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 10
|
10
|
+
version: 1.0.10
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Moe
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-10-11 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: ansi
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 0
|
21
33
|
version: 1.4.0
|
22
34
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
26
37
|
name: hashie
|
27
|
-
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
40
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 19
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 1
|
48
|
+
- 0
|
32
49
|
version: 1.1.0
|
33
50
|
type: :runtime
|
34
|
-
|
35
|
-
version_requirements: *15379620
|
51
|
+
version_requirements: *id002
|
36
52
|
description: The last progressbar-library you'll ever need
|
37
|
-
email:
|
53
|
+
email:
|
38
54
|
- moe@busyloop.net
|
39
|
-
executables:
|
55
|
+
executables:
|
40
56
|
- powerbar-demo
|
41
57
|
extensions: []
|
58
|
+
|
42
59
|
extra_rdoc_files: []
|
43
|
-
|
60
|
+
|
61
|
+
files:
|
44
62
|
- .gitignore
|
45
63
|
- Gemfile
|
46
64
|
- README.rdoc
|
@@ -51,29 +69,38 @@ files:
|
|
51
69
|
- lib/powerbar/version.rb
|
52
70
|
- powerbar.gemspec
|
53
71
|
homepage: https://github.com/busyloop/powerbar
|
54
|
-
licenses:
|
72
|
+
licenses:
|
55
73
|
- MIT
|
56
74
|
post_install_message:
|
57
75
|
rdoc_options: []
|
58
|
-
|
76
|
+
|
77
|
+
require_paths:
|
59
78
|
- lib
|
60
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
80
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
89
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
72
97
|
requirements: []
|
98
|
+
|
73
99
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.24
|
75
101
|
signing_key:
|
76
102
|
specification_version: 3
|
77
103
|
summary: The last progressbar-library you'll ever need
|
78
104
|
test_files: []
|
105
|
+
|
79
106
|
has_rdoc:
|