infobar 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/Gemfile +2 -0
- data/VERSION +1 -1
- data/infobar.gemspec +4 -4
- data/lib/infobar.rb +12 -11
- data/lib/infobar/counter.rb +6 -1
- data/lib/infobar/display.rb +49 -20
- data/lib/infobar/message.rb +6 -2
- data/lib/infobar/version.rb +1 -1
- data/spec/config/infobar.yml +4 -1
- data/spec/infobar/config_spec.rb +4 -1
- data/spec/infobar/display_spec.rb +32 -3
- data/spec/infobar_spec.rb +17 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 224e1a27bb2395439832350f0f9ae226d70d6dc7
|
4
|
+
data.tar.gz: 27de3a8fe8fa615dff727dfe647bf23224258093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09038c7c40c1860f68d719eb7cc4e76e5fc701edce4aaeb8ba564e0da5dbf91e34a1b9dff18bf11750fe6314de5ed49f38ce27ab2038aac519ea1576919e675b'
|
7
|
+
data.tar.gz: 48af752e245e7d9930a972b813b233c6069e48f250a2a3f4e4386b398228beb904ad24cb6750ade8ed3e349d10743cec8750257ba6bbd35cfb38c2e2a5e84650
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/infobar.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: infobar 0.0
|
2
|
+
# stub: infobar 0.1.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "infobar".freeze
|
6
|
-
s.version = "0.0
|
6
|
+
s.version = "0.1.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2017-04-
|
11
|
+
s.date = "2017-04-24"
|
12
12
|
s.description = "This gem displays progress of computations and additional information to the terminal.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze]
|
15
|
-
s.files = [".gitignore".freeze, ".rspec".freeze, ".utilsrc".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "infobar.gemspec".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze, "spec/config/infobar.yml".freeze, "spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/fifo_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/rate_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar/trend_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
15
|
+
s.files = [".gitignore".freeze, ".rspec".freeze, ".travis.yml".freeze, ".utilsrc".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "infobar.gemspec".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze, "spec/config/infobar.yml".freeze, "spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/fifo_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/rate_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar/trend_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
16
16
|
s.homepage = "http://flori.github.com/infobar".freeze
|
17
17
|
s.rdoc_options = ["--title".freeze, "Infobar".freeze, "--main".freeze, "README.md".freeze]
|
18
18
|
s.required_ruby_version = Gem::Requirement.new(">= 2.3".freeze)
|
data/lib/infobar.rb
CHANGED
@@ -51,6 +51,8 @@ class Infobar
|
|
51
51
|
|
52
52
|
delegate :style=, to: :display
|
53
53
|
|
54
|
+
delegate :as_styles=, to: :display
|
55
|
+
|
54
56
|
def call(
|
55
57
|
total:,
|
56
58
|
current: 0,
|
@@ -60,19 +62,18 @@ class Infobar
|
|
60
62
|
style: cc.infobar?&.style?&.to_h,
|
61
63
|
frequency: cc.infobar?&.frequency?,
|
62
64
|
update: false,
|
63
|
-
finish: nil
|
65
|
+
finish: nil,
|
66
|
+
as_styles: nil
|
64
67
|
)
|
65
68
|
self.label = label
|
66
69
|
counter.reset(total: total, current: current)
|
70
|
+
display.reset
|
67
71
|
@message = convert_to_message(message)
|
68
72
|
show.nil? or self.show = show
|
69
|
-
if update
|
70
|
-
update(message: @message, force: true)
|
71
|
-
else
|
72
|
-
display.reset
|
73
|
-
end
|
74
73
|
frequency.nil? or display.frequency = frequency
|
75
74
|
style.nil? or self.style = style
|
75
|
+
self.as_styles = as_styles
|
76
|
+
update and update(message: @message, force: true)
|
76
77
|
self
|
77
78
|
end
|
78
79
|
|
@@ -105,14 +106,14 @@ class Infobar
|
|
105
106
|
|
106
107
|
def update(message: nil, force: true)
|
107
108
|
@message = convert_to_message(message)
|
108
|
-
display.update(message: @message,
|
109
|
+
display.update(message: @message, counter: counter, force: force)
|
109
110
|
self
|
110
111
|
end
|
111
112
|
|
112
|
-
def progress(by: 1, message: nil, finish: true, force: false)
|
113
|
-
counter.progress(by: by)
|
113
|
+
def progress(by: 1, as: nil, message: nil, finish: true, force: false)
|
114
|
+
counter.progress(by: by, as: as)
|
114
115
|
@message = convert_to_message(message)
|
115
|
-
display.update(message: @message, force: force,
|
116
|
+
display.update(message: @message, force: force, counter: counter)
|
116
117
|
finish && counter.done? and finish(message: finish)
|
117
118
|
self
|
118
119
|
end
|
@@ -120,7 +121,7 @@ class Infobar
|
|
120
121
|
def finish(message: nil)
|
121
122
|
counter.finish
|
122
123
|
@message = convert_to_message(message)
|
123
|
-
display.update(message: @message, force: true,
|
124
|
+
display.update(message: @message, force: true, counter: counter)
|
124
125
|
self
|
125
126
|
end
|
126
127
|
|
data/lib/infobar/counter.rb
CHANGED
@@ -13,12 +13,16 @@ class Infobar::Counter
|
|
13
13
|
|
14
14
|
attr_reader :total
|
15
15
|
|
16
|
+
attr_reader :as
|
17
|
+
|
16
18
|
def reset(total: 0, current: 0)
|
17
19
|
@current = current
|
20
|
+
@as = Hash.new(0).update(nil => current)
|
18
21
|
@total = total
|
19
22
|
@start = nil
|
20
23
|
@finished = false
|
21
24
|
@timer = Infobar::Timer.new
|
25
|
+
self
|
22
26
|
end
|
23
27
|
|
24
28
|
delegate :rate, to: :@timer
|
@@ -40,12 +44,13 @@ class Infobar::Counter
|
|
40
44
|
self
|
41
45
|
end
|
42
46
|
|
43
|
-
def progress(by: 1)
|
47
|
+
def progress(by: 1, as: nil)
|
44
48
|
if !finished? && by >= 1
|
45
49
|
now = Time.now
|
46
50
|
@start ||= now
|
47
51
|
@timer.add(now, by)
|
48
52
|
@current += by
|
53
|
+
@as[as] += 1
|
49
54
|
end
|
50
55
|
self
|
51
56
|
end
|
data/lib/infobar/display.rb
CHANGED
@@ -24,7 +24,7 @@ class Infobar::Display
|
|
24
24
|
self.input = $stdin
|
25
25
|
self.frequency = 0.05
|
26
26
|
@show = true
|
27
|
-
|
27
|
+
@style = self.class.default_style.dup
|
28
28
|
end
|
29
29
|
|
30
30
|
def frequency=(duration)
|
@@ -62,34 +62,63 @@ class Infobar::Display
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
self.class.default_style.each_key.each_with_object({}) do |attribute, h|
|
67
|
-
h[attribute] = instance_variable_get "@#{attribute}"
|
68
|
-
end
|
69
|
-
end
|
65
|
+
attr_reader :style
|
70
66
|
|
71
67
|
def style=(new_style)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
@style.update(new_style)
|
69
|
+
end
|
70
|
+
|
71
|
+
def as_styles
|
72
|
+
defined? @as_styles or self.as_styles = {}
|
73
|
+
@as_styles
|
78
74
|
end
|
79
75
|
|
80
|
-
def
|
76
|
+
def as_styles=(styles)
|
77
|
+
@as_styles = styles.to_h.dup
|
78
|
+
@as_styles.default_proc = proc { style.subhash(/\Adone_/) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def update(message:, counter:, force: false, **options)
|
81
82
|
force and @frequency.reset
|
82
83
|
@frequency.call do
|
83
84
|
message = Infobar.convert_to_message(message)
|
84
85
|
carriage_return
|
85
86
|
self.style = options
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
layout_bar(message, counter)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private\
|
92
|
+
def layout_bar(message, counter)
|
93
|
+
cols = columns
|
94
|
+
todo = message.to_str.center cols, replace_character
|
95
|
+
|
96
|
+
if counter.total > 0
|
97
|
+
max_done_length = counter.progressed * cols
|
98
|
+
|
99
|
+
total_done = 0
|
100
|
+
counter.as.each_with_index do |(name, count), i|
|
101
|
+
done_fill = as_styles[name].fetch(:done_fill) { @style[:done_fill] }
|
102
|
+
done_fg_color = as_styles[name].fetch(:done_fg_color) { @style[:done_fg_color] }
|
103
|
+
done_bg_color = as_styles[name].fetch(:done_bg_color) { @style[:done_bg_color] }
|
104
|
+
|
105
|
+
as_progressed = count / counter.total.to_f
|
106
|
+
as_done = as_progressed * cols
|
107
|
+
total_done += as_done
|
108
|
+
if counter.done? && i == counter.as.size - 1 && total_done <= max_done_length
|
109
|
+
done = todo.dup
|
110
|
+
todo = ''
|
111
|
+
else
|
112
|
+
done = todo.slice!(0, as_done)
|
113
|
+
end
|
114
|
+
done.gsub!(replace_character, done_fill[0])
|
115
|
+
output << color(done_fg_color, on_color(done_bg_color, done))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if todo.present?
|
120
|
+
todo.gsub!(replace_character, @style[:todo_fill][0])
|
121
|
+
output << color(@style[:todo_fg_color], on_color(@style[:todo_bg_color], todo))
|
93
122
|
end
|
94
123
|
end
|
95
124
|
|
data/lib/infobar/message.rb
CHANGED
@@ -124,9 +124,13 @@ class Infobar::Message
|
|
124
124
|
|
125
125
|
attr_reader :opts
|
126
126
|
|
127
|
-
|
127
|
+
def directives
|
128
|
+
self.class.directives
|
129
|
+
end
|
128
130
|
|
129
|
-
|
131
|
+
def directive_default_options
|
132
|
+
self.class.directive_default_options
|
133
|
+
end
|
130
134
|
|
131
135
|
def opts_for(directive)
|
132
136
|
@opts.fetch(directive, directive_default_options[directive])
|
data/lib/infobar/version.rb
CHANGED
data/spec/config/infobar.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
default: &default
|
3
3
|
label: Progress
|
4
4
|
message:
|
5
5
|
format: ' %l %c/%t (%P%%) in %te with %r, ETA %e @%E %s '
|
@@ -18,3 +18,6 @@ development:
|
|
18
18
|
todo_fg_color: 124
|
19
19
|
todo_bg_color: 214
|
20
20
|
show: <%= STDIN.tty? %>
|
21
|
+
|
22
|
+
development: *default
|
23
|
+
test: *default
|
data/spec/infobar/config_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'Infobar config' do
|
4
4
|
before do
|
5
5
|
ComplexConfig::Provider.config_dir =
|
6
|
-
Pathname.new(__FILE__).
|
6
|
+
Pathname.new(__FILE__).join('../../config')
|
7
7
|
extend ComplexConfig::Provider::Shortcuts
|
8
8
|
ComplexConfig::Provider.reload
|
9
9
|
end
|
@@ -20,6 +20,9 @@ describe 'Infobar config' do
|
|
20
20
|
it 'configures default infobar' do
|
21
21
|
Infobar(total: 23)
|
22
22
|
expect(infobar.display.output).to receive(:<<).with(?\r)
|
23
|
+
expect(infobar.display.output).to receive(:<<).with(
|
24
|
+
"\e[38;5;22m\e[48;5;40m\e[0m\e[0m"
|
25
|
+
)
|
23
26
|
expect(infobar.display.output).to receive(:<<).with(%r(Progress 0/23.*⣽))
|
24
27
|
infobar.update
|
25
28
|
expect(infobar).to be_show
|
@@ -9,20 +9,24 @@ describe Infobar::Display do
|
|
9
9
|
described_class.new
|
10
10
|
end
|
11
11
|
|
12
|
+
let :counter do
|
13
|
+
Infobar::Counter.new.reset(total: 2, current: 1)
|
14
|
+
end
|
15
|
+
|
12
16
|
before do
|
13
17
|
display.output = output
|
14
18
|
allow(display).to receive(:columns).and_return 40
|
15
19
|
end
|
16
20
|
|
17
21
|
it 'can be updated' do
|
18
|
-
display.update message: 'test',
|
22
|
+
display.update message: 'test', counter: counter
|
19
23
|
expect(output.tap(&:rewind).read).to eq\
|
20
24
|
"\r\e[38;5;22m\e[48;5;40m░░░░░░░░░░░░░░░░░░te\e[0m\e[0m\e[38;5;40m\e[48;5;22mst \e[0m\e[0m"
|
21
25
|
end
|
22
26
|
|
23
27
|
it 'update returns carriage first' do
|
24
28
|
expect(display).to receive(:carriage_return).and_call_original
|
25
|
-
display.update message: 'test',
|
29
|
+
display.update message: 'test', counter: counter
|
26
30
|
expect(output.tap(&:rewind).read).to start_with ?\r
|
27
31
|
end
|
28
32
|
|
@@ -47,12 +51,37 @@ describe Infobar::Display do
|
|
47
51
|
todo_bg_color: 8
|
48
52
|
}
|
49
53
|
display.style = test_style
|
50
|
-
display.update message: 'test',
|
54
|
+
display.update message: 'test', counter: counter
|
51
55
|
expect(output.tap(&:rewind).read).to eq\
|
52
56
|
"\r\e[38;5;1m\e[48;5;9mXXXXXXXXXXXXXXXXXXte\e[0m\e[0m\e[38;5;0m\e[48;5;8mstOOOOOOOOOOOOOOOOOO\e[0m\e[0m"
|
53
57
|
expect(display.style).to eq(test_style)
|
54
58
|
end
|
55
59
|
|
60
|
+
it 'styles are different as kinds differ' do
|
61
|
+
counter = Infobar::Counter.new.reset(total: 7, current: 5)
|
62
|
+
allow(counter).to receive(:as).and_return(
|
63
|
+
foo: 3,
|
64
|
+
bar: 2
|
65
|
+
)
|
66
|
+
allow(display).to receive(:as_styles).and_return(
|
67
|
+
{
|
68
|
+
foo: {
|
69
|
+
done_fill: ?X,
|
70
|
+
done_fg_color: 1,
|
71
|
+
done_bg_color: 9,
|
72
|
+
},
|
73
|
+
bar: {
|
74
|
+
done_fill: ?*,
|
75
|
+
done_fg_color: 0,
|
76
|
+
done_bg_color: 10,
|
77
|
+
}
|
78
|
+
}
|
79
|
+
)
|
80
|
+
display.update message: 'test', counter: counter
|
81
|
+
expect(output.tap(&:rewind).read).to eq\
|
82
|
+
"\r\e[38;5;1m\e[48;5;9mXXXXXXXXXXXXXXXXX\e[0m\e[0m\e[38;5;0m\e[48;5;10m*test******\e[0m\e[0m\e[38;5;40m\e[48;5;22m \e[0m\e[0m"
|
83
|
+
end
|
84
|
+
|
56
85
|
it 'can output newline' do
|
57
86
|
expect(display.output).to receive(:<<).with($/)
|
58
87
|
display.newline
|
data/spec/infobar_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe Infobar do
|
|
29
29
|
expect(infobar.display).to receive(:update).
|
30
30
|
with(
|
31
31
|
message: anything,
|
32
|
-
|
32
|
+
counter: anything,
|
33
33
|
force: true
|
34
34
|
).and_call_original
|
35
35
|
infobar.update
|
@@ -72,6 +72,20 @@ describe Infobar do
|
|
72
72
|
expect(infobar.counter.current).to eq 7
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'can progress as some kind' do
|
76
|
+
Infobar(total: 10)
|
77
|
+
expect(infobar.counter.current).to eq 0
|
78
|
+
expect(infobar.progress).to eq infobar
|
79
|
+
expect(infobar.progress(as: :foo)).to eq infobar
|
80
|
+
expect(infobar.progress(as: :bar)).to eq infobar
|
81
|
+
expect(infobar.progress(as: :foo)).to eq infobar
|
82
|
+
expect(infobar.counter.as).to eq(
|
83
|
+
nil => 1,
|
84
|
+
foo: 2,
|
85
|
+
bar: 1
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
75
89
|
it 'can be progressing with <<' do
|
76
90
|
Infobar(total: 10)
|
77
91
|
expect(infobar.counter.current).to eq 0
|
@@ -123,7 +137,7 @@ describe Infobar do
|
|
123
137
|
expect(infobar.display).to receive(:update).with(
|
124
138
|
message: message,
|
125
139
|
force: true,
|
126
|
-
|
140
|
+
counter: anything
|
127
141
|
).and_call_original
|
128
142
|
infobar.finish message: message
|
129
143
|
expect(infobar).to be_finished
|
@@ -144,6 +158,7 @@ describe Infobar do
|
|
144
158
|
Infobar(total: 10, style: { done_fill: ?X })
|
145
159
|
output = ''
|
146
160
|
infobar.display.output = output
|
161
|
+
allow(Tins::Terminal).to receive(:columns).and_return 80
|
147
162
|
infobar.progress(force: true)
|
148
163
|
expect(output).to include 'X'
|
149
164
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infobar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -153,6 +153,7 @@ extra_rdoc_files:
|
|
153
153
|
files:
|
154
154
|
- ".gitignore"
|
155
155
|
- ".rspec"
|
156
|
+
- ".travis.yml"
|
156
157
|
- ".utilsrc"
|
157
158
|
- Gemfile
|
158
159
|
- README.md
|