infobar 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/TODO.md +2 -0
- data/VERSION +1 -1
- data/infobar.gemspec +2 -2
- data/lib/infobar.rb +16 -16
- data/lib/infobar/input_output.rb +10 -6
- data/lib/infobar/version.rb +1 -1
- data/spec/infobar/input_output_spec.rb +20 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b394ca03e7b4a64c6c3aaa730c05727fc33bb4c
|
4
|
+
data.tar.gz: f0d57d7647a4c43decf21a3b001a14fa46fa321b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b575a6725e49e44556b4866fb45985ca19790b51321d10cc5e0581df57f71ce8f55c7b4b598bd7dfd7f3d5cffd76558c5d5da46ac1d7d8cdfeff94644ff36a2
|
7
|
+
data.tar.gz: 1793197d1e8b73ae6a611824d946c634fcc3fb2abce3ccc422de02da00568009b5daec63b19088571f8a5202d3adc39af97a97e5898f1e8940dab1cf94f7ccb0
|
data/README.md
CHANGED
@@ -21,7 +21,11 @@ Display progress of computations and additional information to the terminal.
|
|
21
21
|
|
22
22
|
## Changes
|
23
23
|
|
24
|
+
* 2017-02-08 Release 0.0.1
|
25
|
+
- Allow disabling of delegated output via infobar.show = false
|
26
|
+
|
24
27
|
* 2017-02-08 Release 0.0.0
|
28
|
+
- Initial release
|
25
29
|
|
26
30
|
## Download
|
27
31
|
|
data/TODO.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/infobar.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: infobar 0.0.
|
2
|
+
# stub: infobar 0.0.1 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.0.1"
|
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]
|
data/lib/infobar.rb
CHANGED
@@ -38,17 +38,17 @@ class Infobar
|
|
38
38
|
|
39
39
|
attr_accessor :label
|
40
40
|
|
41
|
-
delegate :started?, to:
|
41
|
+
delegate :started?, to: :counter
|
42
42
|
|
43
|
-
delegate :done?, to:
|
43
|
+
delegate :done?, to: :counter
|
44
44
|
|
45
|
-
delegate :finished?, to:
|
45
|
+
delegate :finished?, to: :counter
|
46
46
|
|
47
|
-
delegate :show?, to:
|
47
|
+
delegate :show?, to: :display
|
48
48
|
|
49
|
-
delegate :show=, to:
|
49
|
+
delegate :show=, to: :display
|
50
50
|
|
51
|
-
delegate :style=, to:
|
51
|
+
delegate :style=, to: :display
|
52
52
|
|
53
53
|
def call(
|
54
54
|
total:,
|
@@ -62,13 +62,13 @@ class Infobar
|
|
62
62
|
finish: nil
|
63
63
|
)
|
64
64
|
self.label = label
|
65
|
-
|
65
|
+
counter.reset(total: total, current: current)
|
66
66
|
@message = convert_to_message(message)
|
67
67
|
show.nil? or self.show = show
|
68
68
|
if update
|
69
69
|
update(message: @message)
|
70
70
|
else
|
71
|
-
|
71
|
+
display.reset
|
72
72
|
end
|
73
73
|
frequency.nil? or display.frequency = frequency
|
74
74
|
style.nil? or self.style = style
|
@@ -77,29 +77,29 @@ class Infobar
|
|
77
77
|
|
78
78
|
def reset
|
79
79
|
@message = convert_to_message('%l %c/%t in %te, ETA %e @%E %s')
|
80
|
-
|
81
|
-
|
80
|
+
counter.reset(total: 0, current: 0)
|
81
|
+
display.reset
|
82
82
|
self
|
83
83
|
end
|
84
84
|
|
85
85
|
def update(message: nil)
|
86
86
|
@message = convert_to_message(message)
|
87
|
-
|
87
|
+
display.update(message: @message, progressed: counter.progressed)
|
88
88
|
self
|
89
89
|
end
|
90
90
|
|
91
91
|
def progress(by: 1, message: nil, finish: true, force: false)
|
92
|
-
|
92
|
+
counter.progress(by: by)
|
93
93
|
@message = convert_to_message(message)
|
94
|
-
|
95
|
-
finish &&
|
94
|
+
display.update(message: @message, force: force, progressed: counter.progressed)
|
95
|
+
finish && counter.done? and finish(message: finish)
|
96
96
|
self
|
97
97
|
end
|
98
98
|
|
99
99
|
def finish(message: nil)
|
100
|
-
|
100
|
+
counter.finish
|
101
101
|
@message = convert_to_message(message)
|
102
|
-
|
102
|
+
display.update(message: @message, force: true, progressed: counter.progressed)
|
103
103
|
self
|
104
104
|
end
|
105
105
|
|
data/lib/infobar/input_output.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
module Infobar::InputOutput
|
2
2
|
def newline
|
3
|
-
|
3
|
+
display.newline
|
4
4
|
self
|
5
5
|
end
|
6
6
|
|
7
7
|
def clear
|
8
|
-
|
8
|
+
display.clear
|
9
9
|
self
|
10
10
|
end
|
11
11
|
|
12
12
|
%i[ print printf putc puts ].each do |method|
|
13
13
|
define_method(method) do |*a, &b|
|
14
|
-
|
15
|
-
|
14
|
+
display.clear
|
15
|
+
if display.output.respond_to?(method)
|
16
|
+
display.output.public_send(method, *a, &b)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
%i[ gets readline readlines ].each do |method|
|
20
22
|
define_method(method) do |*a, &b|
|
21
|
-
|
22
|
-
|
23
|
+
display.clear
|
24
|
+
if display.input.respond_to?(method)
|
25
|
+
display.input.public_send(method, *a, &b)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/infobar/version.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Infobar::InputOutput do
|
4
|
+
io_double = -> {
|
5
|
+
Class.new do
|
6
|
+
def puts(*) end
|
7
|
+
|
8
|
+
def gets(*) end
|
9
|
+
end.new
|
10
|
+
}
|
11
|
+
|
4
12
|
around do |example|
|
5
|
-
infobar.display.output =
|
6
|
-
infobar.display.input =
|
13
|
+
infobar.display.output = io_double.()
|
14
|
+
infobar.display.input = io_double.()
|
7
15
|
example.run
|
8
16
|
infobar.display.output = $stdout
|
9
17
|
infobar.display.input = $stdin
|
@@ -31,4 +39,14 @@ describe Infobar::InputOutput do
|
|
31
39
|
expect(infobar.display).to receive(:clear)
|
32
40
|
infobar.clear
|
33
41
|
end
|
42
|
+
|
43
|
+
it 'does not puts if not showing' do
|
44
|
+
begin
|
45
|
+
expect(infobar.display.output).not_to receive(:puts)
|
46
|
+
infobar.show = false
|
47
|
+
infobar.puts 'hello'
|
48
|
+
rescue
|
49
|
+
infobar.show = true
|
50
|
+
end
|
51
|
+
end
|
34
52
|
end
|