tty-progressbar 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +7 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -3
- data/README.md +27 -13
- data/lib/tty/progressbar.rb +37 -22
- data/lib/tty/progressbar/version.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/advance_spec.rb +1 -1
- data/spec/unit/clear_spec.rb +0 -2
- data/spec/unit/complete_spec.rb +2 -4
- data/spec/unit/converter/to_bytes_spec.rb +2 -4
- data/spec/unit/converter/to_seconds_spec.rb +2 -4
- data/spec/unit/converter/to_time_spec.rb +2 -4
- data/spec/unit/custom_formatter_spec.rb +1 -1
- data/spec/unit/custom_token_spec.rb +1 -1
- data/spec/unit/finish_spec.rb +2 -4
- data/spec/unit/formatter/bar_spec.rb +1 -3
- data/spec/unit/formatter/byte_rate_spec.rb +2 -4
- data/spec/unit/formatter/current_byte_spec.rb +2 -4
- data/spec/unit/formatter/current_spec.rb +2 -4
- data/spec/unit/formatter/elapsed_spec.rb +1 -3
- data/spec/unit/formatter/estimated_spec.rb +2 -4
- data/spec/unit/formatter/mean_byte_spec.rb +2 -4
- data/spec/unit/formatter/mean_rate_spec.rb +2 -4
- data/spec/unit/formatter/percent_spec.rb +2 -4
- data/spec/unit/formatter/rate_spec.rb +2 -4
- data/spec/unit/formatter/total_byte_spec.rb +2 -4
- data/spec/unit/formatter/total_spec.rb +2 -4
- data/spec/unit/frequency_spec.rb +0 -2
- data/spec/unit/hide_cursor_spec.rb +1 -3
- data/spec/unit/inspect_spec.rb +13 -0
- data/spec/unit/log_spec.rb +1 -3
- data/spec/unit/meter_spec.rb +1 -1
- data/spec/unit/new_spec.rb +1 -3
- data/spec/unit/pipeline_spec.rb +1 -3
- data/spec/unit/ratio_spec.rb +1 -1
- data/spec/unit/reset_spec.rb +1 -3
- data/spec/unit/resize_spec.rb +3 -5
- data/spec/unit/set_current_spec.rb +1 -3
- data/spec/unit/start_spec.rb +1 -3
- data/spec/unit/width_spec.rb +1 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e137d51b66bb2d42c3b21390f09323b7a7cc31b
|
4
|
+
data.tar.gz: 90374c2957298fe9f02ec5de90a06fa9b5371956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37c1713fde3ec813436bd8ea3b190f66670a15477a1020bcb7256999477b4eb50aa7781a3520b4eb31545fab121f569dc72b6541b2b5dd059fc86e5c1750ff32
|
7
|
+
data.tar.gz: 99efdc1a6d78fa7a52692102fea4969e558de445076ea66b07913076583a628bd82980cb3329f632270f96829c1b0f47278b5c95baca5b5c22c4b219a99714d8
|
data/.codeclimate.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.8.1] - 2016-02-27
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add progress bar #inspect
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
* Fix the progressbar resizing call, help from @squarism
|
10
|
+
|
3
11
|
## [v0.8.0] - 2016-02-07
|
4
12
|
|
5
13
|
### Changed
|
@@ -69,6 +77,7 @@
|
|
69
77
|
|
70
78
|
* Initial implementation and release
|
71
79
|
|
80
|
+
[v0.8.1]: https://github.com/peter-murach/tty-progressbar/compare/v0.8.0...v0.8.1
|
72
81
|
[v0.8.0]: https://github.com/peter-murach/tty-progressbar/compare/v0.7.0...v0.8.0
|
73
82
|
[v0.7.0]: https://github.com/peter-murach/tty-progressbar/compare/v0.6.0...v0.7.0
|
74
83
|
[v0.6.0]: https://github.com/peter-murach/tty-progressbar/compare/v0.5.1...v0.6.0
|
data/Gemfile
CHANGED
@@ -2,15 +2,15 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
group :
|
5
|
+
group :test do
|
6
6
|
gem 'rspec', '~> 3.4.0'
|
7
7
|
gem 'yard', '~> 0.8.7'
|
8
8
|
gem 'timecop', '~> 0.7.1'
|
9
9
|
gem 'pastel', '~> 0.6.0'
|
10
|
+
gem 'codeclimate-test-reporter'
|
11
|
+
gem 'simplecov', '~> 0.11.2'
|
10
12
|
end
|
11
13
|
|
12
14
|
group :metrics do
|
13
|
-
gem 'coveralls', '~> 0.8.10'
|
14
|
-
gem 'simplecov', '~> 0.11.2'
|
15
15
|
gem 'yardstick', '~> 0.9.9'
|
16
16
|
end
|
data/README.md
CHANGED
@@ -2,13 +2,12 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/tty-progressbar.svg)][gem]
|
3
3
|
[![Build Status](https://secure.travis-ci.org/peter-murach/tty-progressbar.svg?branch=master)][travis]
|
4
4
|
[![Code Climate](https://codeclimate.com/github/peter-murach/tty-progressbar/badges/gpa.svg)][codeclimate]
|
5
|
-
[![Coverage Status](https://
|
5
|
+
[![Coverage Status](https://codeclimate.com/github/peter-murach/tty-progressbar/badges/coverage.svg)][codeclimate]
|
6
6
|
[![Inline docs](http://inch-ci.org/github/peter-murach/tty-progressbar.svg?branch=master)][inchpages]
|
7
7
|
|
8
8
|
[gem]: http://badge.fury.io/rb/tty-progressbar
|
9
9
|
[travis]: http://travis-ci.org/peter-murach/tty-progressbar
|
10
10
|
[codeclimate]: https://codeclimate.com/github/peter-murach/tty-progressbar
|
11
|
-
[coverage]: https://coveralls.io/r/peter-murach/tty-progressbar
|
12
11
|
[inchpages]: http://inch-ci.org/github/peter-murach/tty-progressbar
|
13
12
|
|
14
13
|
> A flexible progress bars drawing in terminal emulators.
|
@@ -44,11 +43,12 @@ Or install it yourself as:
|
|
44
43
|
* [1.1 advance](#11-advance)
|
45
44
|
* [1.2 current=](#12-current)
|
46
45
|
* [1.3 ratio=](#13-ratio)
|
47
|
-
* [1.4
|
48
|
-
* [1.5
|
49
|
-
* [1.6
|
50
|
-
* [1.7
|
51
|
-
* [1.8
|
46
|
+
* [1.4 width=](#14-width)
|
47
|
+
* [1.5 start](#15-start)
|
48
|
+
* [1.6 finish](#16-finish)
|
49
|
+
* [1.7 complete?](#17-complete)
|
50
|
+
* [1.8 reset](#18-reset)
|
51
|
+
* [1.9 resize](#19-resize)
|
52
52
|
* [2. Configuration](#2-configuration)
|
53
53
|
* [2.1 Frequency](#21-frequency)
|
54
54
|
* [2.2 Interval](#22-interval)
|
@@ -112,7 +112,21 @@ In order to update overall completion of a progress bar as an exact percentage u
|
|
112
112
|
bar.ratio = 0.5
|
113
113
|
```
|
114
114
|
|
115
|
-
### 1.4
|
115
|
+
### 1.4 width=
|
116
|
+
|
117
|
+
You can set how many terminal columns will the `:bar` actually span excluding any other tokens and/or text. For example if you need the bar to be always 20 columns wwide do:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
bar.width = 20
|
121
|
+
```
|
122
|
+
|
123
|
+
or with configuration options:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
bar = TTY::ProgressBar.new("[:bar]", width: 20)
|
127
|
+
```
|
128
|
+
|
129
|
+
### 1.5 start
|
116
130
|
|
117
131
|
By default the timer for internal time esitamation is started automatically when the `advance` method is called. However, if you require control on when the progression timer is started use `start` call:
|
118
132
|
|
@@ -120,7 +134,7 @@ By default the timer for internal time esitamation is started automatically when
|
|
120
134
|
bar.start # => sets timer and draws initial progress bar
|
121
135
|
```
|
122
136
|
|
123
|
-
### 1.
|
137
|
+
### 1.6 finish
|
124
138
|
|
125
139
|
In order to immediately stop and finish the progress call `finish`. This will finish drawing the progress and return to new line.
|
126
140
|
|
@@ -128,7 +142,7 @@ In order to immediately stop and finish the progress call `finish`. This will fi
|
|
128
142
|
bar.finish
|
129
143
|
```
|
130
144
|
|
131
|
-
### 1.
|
145
|
+
### 1.7 complete?
|
132
146
|
|
133
147
|
During progresion you can check if bar is finished or not by calling `complete?`.
|
134
148
|
|
@@ -136,7 +150,7 @@ During progresion you can check if bar is finished or not by calling `complete?`
|
|
136
150
|
bar.complete? # => false
|
137
151
|
```
|
138
152
|
|
139
|
-
### 1.
|
153
|
+
### 1.8 reset
|
140
154
|
|
141
155
|
In order to reset currently running or finished progress bar to its original configuration and initial position use `reset` like so:
|
142
156
|
|
@@ -144,7 +158,7 @@ In order to reset currently running or finished progress bar to its original con
|
|
144
158
|
bar.reset
|
145
159
|
```
|
146
160
|
|
147
|
-
### 1.
|
161
|
+
### 1.9 resize
|
148
162
|
|
149
163
|
If you wish for a progress bar to change it's current width, you can use `resize` by passing in a new desired length:
|
150
164
|
|
@@ -157,7 +171,7 @@ bar.resize(50) # => will resize bar proportionately from this point onwards
|
|
157
171
|
There are number of configuration options that can be provided:
|
158
172
|
|
159
173
|
* `total` total number of steps to completion
|
160
|
-
* `width`
|
174
|
+
* `width` of the bars display in terminal columns excluding formatting options. Defaults to total steps
|
161
175
|
* `complete` completion character by default `=`
|
162
176
|
* `incomplete` incomplete character by default single space
|
163
177
|
* `output` the output stream defaulting to `stderr`
|
data/lib/tty/progressbar.rb
CHANGED
@@ -24,7 +24,7 @@ module TTY
|
|
24
24
|
|
25
25
|
def_delegators :@configuration, :total, :width, :no_width,
|
26
26
|
:complete, :incomplete, :hide_cursor, :clear,
|
27
|
-
:output, :frequency
|
27
|
+
:output, :frequency, :interval, :width=
|
28
28
|
|
29
29
|
def_delegators :@meter, :rate, :mean_rate
|
30
30
|
|
@@ -74,7 +74,7 @@ module TTY
|
|
74
74
|
@meter = Meter.new(options.fetch(:interval, 1))
|
75
75
|
|
76
76
|
@formatter.load
|
77
|
-
|
77
|
+
register_signals
|
78
78
|
end
|
79
79
|
|
80
80
|
# Start progression by drawing bar and setting time
|
@@ -94,6 +94,7 @@ module TTY
|
|
94
94
|
#
|
95
95
|
# @api public
|
96
96
|
def advance(progress = 1, tokens = {})
|
97
|
+
#handle_signals
|
97
98
|
return if @done
|
98
99
|
|
99
100
|
if progress.respond_to?(:to_hash)
|
@@ -179,19 +180,16 @@ module TTY
|
|
179
180
|
|
180
181
|
# Resize progress bar with new configuration
|
181
182
|
#
|
183
|
+
# @param [Integer] new_width
|
184
|
+
# the new width for the bar display
|
185
|
+
#
|
182
186
|
# @api public
|
183
|
-
def resize(new_width)
|
187
|
+
def resize(new_width = nil)
|
184
188
|
fail 'Cannot resize finished progress bar' if @done
|
185
|
-
|
189
|
+
clear_line
|
186
190
|
if new_width
|
187
|
-
|
188
|
-
@configuration.width = new_width
|
189
|
-
else
|
190
|
-
@configuration.no_width = true
|
191
|
-
@configuration.width = 0
|
191
|
+
self.width = new_width
|
192
192
|
end
|
193
|
-
|
194
|
-
advance(0) # rerender with new configuration
|
195
193
|
end
|
196
194
|
|
197
195
|
# End the progress
|
@@ -266,6 +264,31 @@ module TTY
|
|
266
264
|
TTY::Screen.width
|
267
265
|
end
|
268
266
|
|
267
|
+
# Show bar format
|
268
|
+
#
|
269
|
+
# @return [String]
|
270
|
+
#
|
271
|
+
# @api public
|
272
|
+
def to_s
|
273
|
+
@format.to_s
|
274
|
+
end
|
275
|
+
|
276
|
+
# Inspect bar properties
|
277
|
+
#
|
278
|
+
# @return [String]
|
279
|
+
#
|
280
|
+
# @api public
|
281
|
+
def inspect
|
282
|
+
output = "#<#{self.class.name} "
|
283
|
+
output << "@format=\"#{format}\", "
|
284
|
+
output << "@current=\"#{@current}\", "
|
285
|
+
output << "@total=\"#{total}\", "
|
286
|
+
output << "@width=\"#{width}\", "
|
287
|
+
output << "@complete=\"#{complete}\", "
|
288
|
+
output << "@incomplete=\"#{incomplete}\", "
|
289
|
+
output << "@interval=\"#{interval}\">"
|
290
|
+
end
|
291
|
+
|
269
292
|
private
|
270
293
|
|
271
294
|
# Pad message out with spaces
|
@@ -279,21 +302,13 @@ module TTY
|
|
279
302
|
message
|
280
303
|
end
|
281
304
|
|
282
|
-
EXIT_SIGS = [:QUIT, :TERM, :INT]
|
283
|
-
|
284
305
|
# Handle resize and kill signals
|
285
306
|
#
|
286
307
|
# @api private
|
287
|
-
def
|
288
|
-
|
289
|
-
adjusted_width = width < max_columns ? width : max_columns
|
290
|
-
send(:resize, adjusted_width)
|
291
|
-
end
|
292
|
-
Signal.trap('WINCH', &callback)
|
308
|
+
def register_signals
|
309
|
+
trap(:WINCH) { resize }
|
293
310
|
|
294
|
-
|
295
|
-
Signal.trap(sig) { finish && fail(Interrupt) }
|
296
|
-
end
|
311
|
+
trap(:INT) { exit! }
|
297
312
|
end
|
298
313
|
end # ProgressBar
|
299
314
|
end # TTY
|
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
|
4
4
|
require 'simplecov'
|
5
|
-
require '
|
5
|
+
require 'codeclimate-test-reporter'
|
6
6
|
|
7
7
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
8
|
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
|
9
|
+
CodeClimate::TestReporter::Formatter
|
10
10
|
]
|
11
11
|
|
12
12
|
SimpleCov.start do
|
data/spec/unit/advance_spec.rb
CHANGED
data/spec/unit/clear_spec.rb
CHANGED
data/spec/unit/complete_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::ProgressBar::Converter, '.to_bytes' do
|
3
|
+
RSpec.describe TTY::ProgressBar::Converter, '#to_bytes' do
|
6
4
|
subject(:converter) { described_class.new }
|
7
5
|
|
8
6
|
it "converts 1000 to bytes" do
|
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::ProgressBar::Converter, '.to_seconds' do
|
3
|
+
RSpec.describe TTY::ProgressBar::Converter, '#to_seconds' do
|
6
4
|
subject(:converter) { described_class.new }
|
7
5
|
|
8
6
|
it "ensure 5 digit precision for < 1" do
|
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::ProgressBar::Converter, '.to_time' do
|
3
|
+
RSpec.describe TTY::ProgressBar::Converter, '#to_time' do
|
6
4
|
subject(:converter) { described_class.new }
|
7
5
|
|
8
6
|
it "converts seconds to seconds" do
|
data/spec/unit/finish_spec.rb
CHANGED
data/spec/unit/frequency_spec.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
RSpec.describe TTY::ProgressBar, '#inspect' do
|
4
|
+
it "inspects bar properties" do
|
5
|
+
bar = described_class.new("downloading [:bar] :total", total: 30)
|
6
|
+
expect(bar.inspect).to eq(%q{#<TTY::ProgressBar @format="downloading [:bar] :total", @current="0", @total="30", @width="30", @complete="=", @incomplete=" ", @interval="">})
|
7
|
+
end
|
8
|
+
|
9
|
+
it "prints string format" do
|
10
|
+
bar = described_class.new("downloading [:bar] :total", total: 30)
|
11
|
+
expect(bar.to_s).to eq("downloading [:bar] :total")
|
12
|
+
end
|
13
|
+
end
|
data/spec/unit/log_spec.rb
CHANGED
data/spec/unit/meter_spec.rb
CHANGED
data/spec/unit/new_spec.rb
CHANGED
data/spec/unit/pipeline_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::ProgressBar::Pipeline, '.decorate' do
|
3
|
+
RSpec.describe TTY::ProgressBar::Pipeline, '#decorate' do
|
6
4
|
subject(:pipeline) { described_class.new }
|
7
5
|
|
8
6
|
it "decorates tokenized string with pipeline formatters" do
|
data/spec/unit/ratio_spec.rb
CHANGED
data/spec/unit/reset_spec.rb
CHANGED
data/spec/unit/resize_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
RSpec.describe TTY::ProgressBar, '.resize' do
|
3
|
+
RSpec.describe TTY::ProgressBar, '#resize' do
|
6
4
|
let(:output) { StringIO.new('', 'w+') }
|
7
5
|
|
8
6
|
it "resizes output down by x2" do
|
@@ -14,7 +12,7 @@ RSpec.describe TTY::ProgressBar, '.resize' do
|
|
14
12
|
expect(output.read).to eq([
|
15
13
|
"\e[1G[== ]",
|
16
14
|
"\e[1G[==== ]",
|
17
|
-
"\e[
|
15
|
+
"\e[0m\e[1000D\e[K",
|
18
16
|
"\e[1G[=== ]",
|
19
17
|
"\e[1G[==== ]",
|
20
18
|
"\e[1G[=====]\n"
|
@@ -30,7 +28,7 @@ RSpec.describe TTY::ProgressBar, '.resize' do
|
|
30
28
|
expect(output.read).to eq([
|
31
29
|
"\e[1G[== ]",
|
32
30
|
"\e[1G[==== ]",
|
33
|
-
"\e[
|
31
|
+
"\e[0m\e[1000D\e[K",
|
34
32
|
"\e[1G[============ ]",
|
35
33
|
"\e[1G[================ ]",
|
36
34
|
"\e[1G[====================]\n"
|
data/spec/unit/start_spec.rb
CHANGED
data/spec/unit/width_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-progressbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-screen
|
@@ -65,6 +65,7 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
+
- .codeclimate.yml
|
68
69
|
- .gitignore
|
69
70
|
- .rspec
|
70
71
|
- .travis.yml
|
@@ -121,6 +122,7 @@ files:
|
|
121
122
|
- spec/unit/formatter/total_spec.rb
|
122
123
|
- spec/unit/frequency_spec.rb
|
123
124
|
- spec/unit/hide_cursor_spec.rb
|
125
|
+
- spec/unit/inspect_spec.rb
|
124
126
|
- spec/unit/log_spec.rb
|
125
127
|
- spec/unit/meter_spec.rb
|
126
128
|
- spec/unit/new_spec.rb
|
@@ -184,6 +186,7 @@ test_files:
|
|
184
186
|
- spec/unit/formatter/total_spec.rb
|
185
187
|
- spec/unit/frequency_spec.rb
|
186
188
|
- spec/unit/hide_cursor_spec.rb
|
189
|
+
- spec/unit/inspect_spec.rb
|
187
190
|
- spec/unit/log_spec.rb
|
188
191
|
- spec/unit/meter_spec.rb
|
189
192
|
- spec/unit/new_spec.rb
|