tty-progressbar 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86f9a4188616553d3453e6f8d5e35d4d3b434e7f
4
- data.tar.gz: 57c8b9d98eca275035f392fa58d4b30b16f5c34d
3
+ metadata.gz: 434eb41ca96e22fc08eec8d921a1e58926bcdc53
4
+ data.tar.gz: b7cc419624722fd02b25a6de8b2bb9ec781df647
5
5
  SHA512:
6
- metadata.gz: e04221654464e622d50a1dd349d65c4d557c957b8d7df1999bd6186eeb087f286221a6c0e13f0102e8af8c93fe5b7227a550e0cd790aff4c4b5d6a69d5111ea7
7
- data.tar.gz: 4997afe3c9e855bcb433dc9209a8d41e6a9df9b560797cca911d5a066557ff5ad2fa542412a4e63c83197a9052bf26c8728275b3f59f4547897bde7088f62ee9
6
+ metadata.gz: ae0c2edda8fc6eac3577a1a4c74a55b3e5cd01759e13a5978786a5777c4ebb4292bb89daa62da7e2043932d352cdb1af28eef579f0f4eae8025a5c433e5bd16c
7
+ data.tar.gz: 9b3bf8f4bae6156ff201ea8f1382c6097d2ba033cd8378832081018efe0c57d90913a77c6053b423460bc961b9f071a4f217990a8441a51e354553d01a36fecd
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ bundler_args: --without yard benchmarks
3
+ script: "bundle exec rake ci"
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - ruby-head
9
+ matrix:
10
+ include:
11
+ - rvm: jruby-19mode
12
+ - rvm: jruby-20mode
13
+ - rvm: jruby-21mode
14
+ - rvm: jruby-head
15
+ - rvm: rbx-2
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ - rvm: jruby-head
19
+ - rvm: jruby-19mode
20
+ - rvm: jruby-20mode
21
+ - rvm: jruby-21mode
22
+ fast_finish: true
23
+ branches:
24
+ only: master
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ 0.2.0 (November 9, 2014)
2
+
3
+ * Add estimated time formatter.
4
+ * Add frequency option to limit repainting of progress.
5
+ * Add log method for printing out during progress rendering.
6
+ * Add complete? for checking progress bar state
7
+ * Fix bug with hide_cursor option
8
+ * Increase test coverage
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ group :development do
7
7
  gem 'rspec', '~> 3.1.0'
8
8
  gem 'yard', '~> 0.8.7'
9
9
  gem 'timecop', '~> 0.7.1'
10
+ gem 'pastel', '~> 0.3.0'
10
11
  end
11
12
 
12
13
  group :metrics do
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
- # TTY::Progressbar
1
+ # TTY::ProgressBar
2
2
  [![Gem Version](https://badge.fury.io/rb/tty-progressbar.png)][gem]
3
3
  [![Build Status](https://secure.travis-ci.org/peter-murach/tty-progressbar.png?branch=master)][travis]
4
4
  [![Code Climate](https://codeclimate.com/github/peter-murach/tty-progressbar.png)][codeclimate]
5
+ [![Coverage Status](https://coveralls.io/repos/peter-murach/tty-progressbar/badge.png)][coverage]
5
6
 
6
7
  [gem]: http://badge.fury.io/rb/tty-progressbar
7
8
  [travis]: http://travis-ci.org/peter-murach/tty-progressbar
8
9
  [codeclimate]: https://codeclimate.com/github/peter-murach/tty-progressbar
10
+ [coverage]: https://coveralls.io/r/peter-murach/tty-progressbar
9
11
 
10
12
  A flexible progress bars drawing in terminal emulators.
11
13
 
14
+ **TTY::ProgressBar** provides independent progress bars component for [TTY](https://github.com/peter-murach/tty) toolkit.
15
+
12
16
  ## Features
13
17
 
14
18
  * Extremly flexible progress display formatting
@@ -35,11 +39,15 @@ Or install it yourself as:
35
39
 
36
40
  * [1. Usage](#1-usage)
37
41
  * [1.1 advance](#11-advance)
38
- * [1.1 finish](#12-finish)
42
+ * [1.2 finish](#12-finish)
43
+ * [1.3 complete?](#13-complete)
39
44
  * [2. Configuration](#2-configuration)
45
+ * [2.1 Frequency](#21-frequency)
40
46
  * [3. Formatting](#3-formatting)
41
47
  * [3.1 Tokens](#31-tokens)
42
- * [3.2 Custom Formatter](#31-custom-formatter)
48
+ * [3.2 Custom Formatters](#31-custom-formatters)
49
+ * [4. Logging](#4-logging)
50
+ * [5. Examples](#5-examples)
43
51
 
44
52
  ## 1. Usage
45
53
 
@@ -53,7 +61,7 @@ bar = TTY::ProgressBar.new("downloading [:bar]", total: 30)
53
61
  end
54
62
  ```
55
63
 
56
- This would produce anmiation in your terminal:
64
+ This would produce animation in your terminal:
57
65
 
58
66
  ```ruby
59
67
  downloading [======================= ]
@@ -67,14 +75,30 @@ Once you have **ProgressBar** instance, you can progress the display by calling
67
75
  bar.advance(1000)
68
76
  ```
69
77
 
78
+ You can also pass negative steps if you wish to backtrack the progress:
79
+
80
+ ```ruby
81
+ bar.advance(-1)
82
+ ```
83
+
84
+ Note: If a progress bar has already finished then negative steps will not set it back to desired value.
85
+
70
86
  ### 1.2 finish
71
87
 
72
- In order to immediately stop and finish the bar call `finish`. This will finish drawing the progress and return to new line.
88
+ In order to immediately stop and finish the progress call `finish`. This will finish drawing the progress and return to new line.
73
89
 
74
90
  ```ruby
75
91
  bar.finish
76
92
  ```
77
93
 
94
+ ### 1.3 complete?
95
+
96
+ During progresion you can check if bar is finished or not by calling `complete?`.
97
+
98
+ ```ruby
99
+ bar.complete? # => false
100
+ ```
101
+
78
102
  ## 2. Configuration
79
103
 
80
104
  There are number of configuration options that can be provided:
@@ -84,9 +108,19 @@ There are number of configuration options that can be provided:
84
108
  * `complete` completion character by default `=`
85
109
  * `incomplete` incomplete character by default single space
86
110
  * `output` the output stream defaulting to `stderr`
87
- * `frequency` used to throttle the output, by default `false`
111
+ * `frequency` used to throttle the output, by default `0` (see [Frequency](#21-frequency))
88
112
  * `hide_cursor` to hide display cursor defaulting to `false`
89
113
 
114
+ ### 2.1 Frequency
115
+
116
+ Each time the `advance` is called it causes the progress bar to repaint. In cases when there is a huge number of updates per second, you may need to limit the rendering process by using the `frequency` option.
117
+
118
+ The `frequency` option accepts `integer` representing number of `Hz` units, for instance, frequency of 2 will mean that the progress will be updated maximum 2 times per second.
119
+
120
+ ```ruby
121
+ TTY::ProgressBar.new("[:bar]", total: 30, frequency: 10) # 10 Hz
122
+ ```
123
+
90
124
  ## 3. Formatting
91
125
 
92
126
  Every **TTY::ProgressBar** instance requires a format string, which apart from regular characters accepts special tokens to display dynamic information. For instance, a format to measure download progress could be:
@@ -104,14 +138,15 @@ These are the tokens that are currently supported:
104
138
  * `:total` the total progress number
105
139
  * `:percent` the completion percentage
106
140
  * `:elapsed` the elapsed time in seconds
141
+ * `:eta` the esitmated time to completion in seconds
107
142
 
108
- ### 3.2 Custom formatter
143
+ ### 3.2 Custom Formatters
109
144
 
110
- If the provided tokens do not meet your needs, you can instrument formatting pipeline to use a custome formatter.
145
+ If the provided tokens do not meet your needs, you can write your own formatter and instrument formatting pipeline to use a formatter you prefer.
111
146
 
112
147
  For example, begin by creating custom formatter called `TimeFormatter` that will dynamicly update `:time` token in format string as follows:
113
148
 
114
- ```
149
+ ```ruby
115
150
  class TimeFormatter
116
151
  def initialize(progress)
117
152
  @progress = progress
@@ -144,6 +179,57 @@ Then add `TimeFormatter` to the pipeline like so:
144
179
  bar.use TimeFormatter
145
180
  ```
146
181
 
182
+ ## 4. Logging
183
+
184
+ If you want to print messages out to terminal along with the progress bar use the `log` method. The messages will appear above the progress bar and will continue scrolling up as more are logged out.
185
+
186
+ ```ruby
187
+ bar.log('Piotrrrrr')
188
+ bar.advance
189
+ ```
190
+
191
+ will result in:
192
+
193
+ ```ruby
194
+ Piotrrrrr
195
+ downloading [======================= ]
196
+ ```
197
+
198
+ ## 5. Examples
199
+
200
+ This section demonstrates some of the possible uses for the **TTY::ProgressBar**, for more please see examples folder in the source directory.
201
+
202
+ ### 5.1 Colors
203
+
204
+ Creating a progress bar that displays in color is as simple as coloring the `:complete` and `:incomplete` character options. In order to help with coloring you can use [pastel](https://github.com/peter-murach/pastel) library like so:
205
+
206
+ ```ruby
207
+ require 'pastel'
208
+
209
+ pastel = Pastel.new
210
+ green = pastel.on_green(" ")
211
+ red = pastel.on_red(" ")
212
+ ```
213
+
214
+ And then pass in the colored strings as options to **TTY::ProgressBar**:
215
+
216
+ ```ruby
217
+ bar = TTY::ProgressBar.new("|:bar|",
218
+ total: 30,
219
+ complete: green,
220
+ incomplete: red
221
+ )
222
+ ```
223
+
224
+ To see how a progress bar is reported in terminal you can do:
225
+
226
+ ```ruby
227
+ 30.times do
228
+ sleep(0.1)
229
+ bar.advance
230
+ end
231
+ ```
232
+
147
233
  ## Contributing
148
234
 
149
235
  1. Fork it ( https://github.com/peter-murach/tty-progressbar/fork )
data/examples/color.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'tty-progressbar'
2
+ require 'pastel'
3
+
4
+ pastel = Pastel.new
5
+ green = pastel.on_green(" ")
6
+ red = pastel.on_red(" ")
7
+
8
+ bar = TTY::ProgressBar.new("|:bar|",
9
+ total: 30,
10
+ complete: green,
11
+ incomplete: red
12
+ )
13
+
14
+ 30.times do
15
+ sleep(0.1)
16
+ bar.advance
17
+ end
data/examples/simple.rb CHANGED
@@ -1,4 +1,4 @@
1
- require'tty-progressbar'
1
+ require 'tty-progressbar'
2
2
 
3
3
  bar = TTY::ProgressBar.new("downloading [:bar] :elapsed :percent", total: 30)
4
4
  30.times do
@@ -9,6 +9,7 @@ require 'tty/progressbar/pipeline'
9
9
  require 'tty/progressbar/bar_formatter'
10
10
  require 'tty/progressbar/current_formatter'
11
11
  require 'tty/progressbar/elapsed_formatter'
12
+ require 'tty/progressbar/estimated_formatter'
12
13
  require 'tty/progressbar/percent_formatter'
13
14
  require 'tty/progressbar/total_formatter'
14
15
 
@@ -45,6 +46,8 @@ module TTY
45
46
 
46
47
  attr_reader :hide_cursor
47
48
 
49
+ attr_reader :output
50
+
48
51
  def_delegator :@pipeline, :use
49
52
 
50
53
  # Create progress bar
@@ -89,6 +92,7 @@ module TTY
89
92
  @last_render_time = Time.now
90
93
  @last_render_width = 0
91
94
  @done = false
95
+ @start_at = Time.now
92
96
  @pipeline = TTY::ProgressBar::Pipeline.new
93
97
 
94
98
  default_pipeline
@@ -138,21 +142,14 @@ module TTY
138
142
  # @api private
139
143
  def render
140
144
  return if @done
141
- now = Time.now
142
-
143
- if @hide_cursor && @last_render_time == 0
144
- write(ECMA_CSI + DEC_RST + DEC_TCEM)
145
+ if @hide_cursor && @last_render_width == 0 && !(@current >= total)
146
+ write(ECMA_CSI + DEC_TCEM + DEC_RST)
145
147
  end
146
148
 
147
- # Setup formatting values
148
- percent = width == 0 ? 100 : (ratio * 100).to_i
149
- elapsed = (now - @start_at) * 1000.0
150
- estimated = (percent == 100) ? 0 : elapsed * (total / @current - 1)
151
-
152
149
  formatted = @pipeline.decorate(self, @format)
153
150
  write(formatted, true)
154
151
 
155
- @last_render_time = Time.now
152
+ @last_render_time = Time.now
156
153
  @last_render_width = formatted.length
157
154
  end
158
155
 
@@ -189,7 +186,9 @@ module TTY
189
186
  # @api public
190
187
  def finish
191
188
  # reenable cursor if it is turned off
192
- write(ECMA_CSI + DEC_RST + DEC_TCEM, false) if @hide_cursor
189
+ if @hide_cursor && @last_render_width != 0
190
+ write(ECMA_CSI + DEC_TCEM + DEC_SET, false)
191
+ end
193
192
  return if @done
194
193
  @current = @width if @no_width
195
194
  render
@@ -197,15 +196,47 @@ module TTY
197
196
  @done = true
198
197
  end
199
198
 
200
- # Terminates the progress bar
199
+ # Check if progress is finised
200
+ #
201
+ # @return [Boolean]
202
+ # true when progress finished, false otherwise
201
203
  #
202
204
  # @api public
203
- def terminate
204
- @done = true
205
+ def complete?
206
+ @done
207
+ end
208
+
209
+ # Log message above the current progress bar
210
+ #
211
+ # @param [String] message
212
+ # the message to log out
213
+ #
214
+ # @api public
215
+ def log(message)
216
+ sanitized_message = message.gsub(/\r|\n/, ' ')
217
+ if @done
218
+ write(sanitized_message + "\n", false)
219
+ return
220
+ end
221
+ sanitized_message = padout(sanitized_message)
222
+
223
+ write(sanitized_message + "\n", true)
224
+ render
205
225
  end
206
226
 
207
227
  private
208
228
 
229
+ # Pad message out with spaces
230
+ #
231
+ # @api private
232
+ def padout(message)
233
+ if @last_render_width > message.length
234
+ remaining_width = @last_render_width - message.length
235
+ message += ' ' * remaining_width
236
+ end
237
+ message
238
+ end
239
+
209
240
  # Prepare default pipeline formatters
210
241
  #
211
242
  # @api private
@@ -213,6 +244,7 @@ module TTY
213
244
  @pipeline.use TTY::ProgressBar::CurrentFormatter
214
245
  @pipeline.use TTY::ProgressBar::TotalFormatter
215
246
  @pipeline.use TTY::ProgressBar::ElapsedFormatter
247
+ @pipeline.use TTY::ProgressBar::EstimatedFormatter
216
248
  @pipeline.use TTY::ProgressBar::PercentFormatter
217
249
  @pipeline.use TTY::ProgressBar::BarFormatter
218
250
  end
@@ -224,7 +256,7 @@ module TTY
224
256
  callback = proc { send(:resize, max_columns) }
225
257
  Signal.trap('SIGWINCH', &callback)
226
258
 
227
- Signal.trap('KILL') { @terminate }
259
+ Signal.trap('KILL') { @finish }
228
260
  end
229
261
  end # ProgressBar
230
262
  end # TTY
@@ -2,8 +2,11 @@
2
2
 
3
3
  module TTY
4
4
  class ProgressBar
5
+ # Used by {Pipeline} to format :current token
6
+ #
7
+ # @api private
5
8
  class CurrentFormatter
6
- def initialize(progress, *args, &block)
9
+ def initialize(progress)
7
10
  @progress = progress
8
11
  end
9
12
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  module TTY
4
4
  class ProgressBar
5
+ # Used by {Pipeline} to format :elapsed token
6
+ #
7
+ # @api private
5
8
  class ElapsedFormatter
6
9
  def initialize(progress, *args, &block)
7
10
  @progress = progress
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ module TTY
4
+ class ProgressBar
5
+ # Used by {Pipeline} to format :eta token
6
+ #
7
+ # @api private
8
+ class EstimatedFormatter
9
+ def initialize(progress)
10
+ @progress = progress
11
+ @converter = TTY::ProgressBar::Converter.new
12
+ end
13
+
14
+ def format(value)
15
+ elapsed = Time.now - @progress.start_at
16
+ estimated = (elapsed / @progress.ratio).to_f - elapsed
17
+ estimated = (estimated.infinite? || estimated < 0) ? 0.0 : estimated
18
+ value.gsub(/:eta/, @converter.to_time(estimated))
19
+ end
20
+ end # ElapsedFormatter
21
+ end # ProgressBar
22
+ end # TTY
@@ -2,6 +2,9 @@
2
2
 
3
3
  module TTY
4
4
  class ProgressBar
5
+ # Used by {Pipeline} to format :percent token
6
+ #
7
+ # @api private
5
8
  class PercentFormatter
6
9
  def initialize(progress, *args, &block)
7
10
  @progress = progress
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class ProgressBar
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end # ProgressBar
7
7
  end # TTY
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,20 @@
1
1
  # encoding: utf-8
2
2
 
3
+ if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+
12
+ SimpleCov.start do
13
+ command_name 'spec'
14
+ add_filter 'spec'
15
+ end
16
+ end
17
+
3
18
  require 'timecop'
4
19
  require 'tty-progressbar'
5
20
 
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::ProgressBar, '.advance' do
6
+ let(:output) { StringIO.new('', 'w+') }
7
+
8
+ it "allows to go back" do
9
+ progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
10
+ 5.times { progress.advance(1) }
11
+ expect(progress.current).to eq(5)
12
+ 5.times { progress.advance(-1) }
13
+ expect(progress.current).to eq(0)
14
+ end
15
+
16
+ it "cannot backtrack on finished" do
17
+ progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
18
+ 10.times { progress.advance(1) }
19
+ expect(progress.current).to eq(10)
20
+ 5.times { progress.advance(-1) }
21
+ expect(progress.current).to eq(10)
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::ProgressBar, '.complete?' do
6
+ let(:output) { StringIO.new('', 'w+') }
7
+
8
+ it "checks for completness" do
9
+ progress = TTY::ProgressBar.new("[:bar]", output: output, total: 3)
10
+ completes = []
11
+ 3.times do
12
+ completes << progress.complete?
13
+ progress.advance
14
+ end
15
+ completes << progress.complete?
16
+ expect(completes).to eq([
17
+ false, false, false, true
18
+ ])
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::ProgressBar, '.new' do
6
+ let(:output) { StringIO.new('', 'w+') }
7
+
8
+ before { Timecop.safe_mode = false }
9
+
10
+ it "displays elapsed time" do
11
+ time_now = Time.local(2014, 10, 5, 12, 0, 0)
12
+ Timecop.freeze(time_now)
13
+ progress = TTY::ProgressBar.new(":eta", output: output, total: 5)
14
+
15
+ 5.times do |sec|
16
+ time_now = Time.local(2014, 10, 5, 12, 0, sec)
17
+ Timecop.freeze(time_now)
18
+ progress.advance
19
+ end
20
+
21
+ output.rewind
22
+ expect(output.read).to eq([
23
+ "\e[1G 0s",
24
+ "\e[1G 1s",
25
+ "\e[1G 1s",
26
+ "\e[1G 0s",
27
+ "\e[1G 0s\n"
28
+ ].join)
29
+ Timecop.return
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe TTY::ProgressBar, 'frequency' do
4
+ let(:output) { StringIO.new('', 'w+') }
5
+
6
+ before { Timecop.safe_mode = false }
7
+
8
+ it "limits frequency to 500Hz, permiting every second one" do
9
+ time_now = Time.local(2014, 10, 5, 12, 0, 0, 0)
10
+ Timecop.freeze(time_now)
11
+ progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10, frequency: 500)
12
+
13
+ 10.times do |sec|
14
+ time_now = Time.local(2014, 10, 5, 12, 0, 0, sec * 1000)
15
+ Timecop.freeze(time_now)
16
+ progress.advance
17
+ end
18
+
19
+ output.rewind
20
+ expect(output.read).to eq([
21
+ "\e[1G[=== ]",
22
+ "\e[1G[===== ]",
23
+ "\e[1G[======= ]",
24
+ "\e[1G[========= ]",
25
+ "\e[1G[==========]\n"
26
+ ].join)
27
+ Timecop.return
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::ProgressBar, 'hide_cursor' do
6
+ let(:output) { StringIO.new('', 'w+') }
7
+
8
+ it "hides cursor" do
9
+ progress = TTY::ProgressBar.new("[:bar]", output: output,
10
+ total: 5, hide_cursor: true)
11
+ 5.times { progress.advance }
12
+ output.rewind
13
+ expect(output.read).to eq([
14
+ "\e[?25l\e[1G[= ]",
15
+ "\e[1G[== ]",
16
+ "\e[1G[=== ]",
17
+ "\e[1G[==== ]",
18
+ "\e[?25h\e[1G[=====]\n"
19
+ ].join)
20
+ end
21
+
22
+ it "reenables cursor on finish" do
23
+ progress = TTY::ProgressBar.new("[:bar]", output: output,
24
+ total: 5, hide_cursor: true)
25
+
26
+ progress.advance(6)
27
+ expect(progress.complete?).to eq(true)
28
+ output.rewind
29
+ expect(output.read).to eq("\e[1G[=====]\n")
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe TTY::ProgressBar, '.log' do
6
+ let(:output) { StringIO.new('', 'w+') }
7
+
8
+ it "logs message" do
9
+ progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
10
+ 2.times {
11
+ progress.log 'foo bar'
12
+ progress.advance
13
+ }
14
+ output.rewind
15
+ expect(output.read).to eq([
16
+ "\e[1Gfoo bar\n",
17
+ "\e[1G[ ]",
18
+ "\e[1G[= ]",
19
+ "\e[1Gfoo bar \n",
20
+ "\e[1G[= ]",
21
+ "\e[1G[== ]",
22
+ ].join)
23
+ end
24
+
25
+ it "logs message under when complete" do
26
+ progress = TTY::ProgressBar.new("[:bar]", output: output, total: 10)
27
+ progress.advance(10)
28
+ expect(progress.complete?).to eq(true)
29
+ progress.log 'foo bar'
30
+ output.rewind
31
+ expect(output.read).to eq("\e[1G[==========]\nfoo bar\n")
32
+ end
33
+ end
@@ -12,4 +12,12 @@ RSpec.describe TTY::ProgressBar::Pipeline, '.decorate' do
12
12
  tokenized = "[:current/:total]"
13
13
  expect(pipeline.decorate(progress_bar, tokenized)).to eq("[3/10]")
14
14
  end
15
+
16
+ it "enumerates pipeline formatters" do
17
+ pipeline.use TTY::ProgressBar::CurrentFormatter
18
+ pipeline.use TTY::ProgressBar::TotalFormatter
19
+ yielded = []
20
+ pipeline.each { |formatter| yielded << formatter }
21
+ expect(yielded.size).to eq(2)
22
+ end
15
23
  end
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-01 00:00:00.000000000 Z
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,10 +48,13 @@ files:
48
48
  - .gitignore
49
49
  - .rspec
50
50
  - .ruby-version
51
+ - .travis.yml
52
+ - CHANGELOG.md
51
53
  - Gemfile
52
54
  - LICENSE.txt
53
55
  - README.md
54
56
  - Rakefile
57
+ - examples/color.rb
55
58
  - examples/simple.rb
56
59
  - lib/tty-progressbar.rb
57
60
  - lib/tty/progressbar.rb
@@ -59,16 +62,23 @@ files:
59
62
  - lib/tty/progressbar/converter.rb
60
63
  - lib/tty/progressbar/current_formatter.rb
61
64
  - lib/tty/progressbar/elapsed_formatter.rb
65
+ - lib/tty/progressbar/estimated_formatter.rb
62
66
  - lib/tty/progressbar/percent_formatter.rb
63
67
  - lib/tty/progressbar/pipeline.rb
64
68
  - lib/tty/progressbar/total_formatter.rb
65
69
  - lib/tty/progressbar/version.rb
66
70
  - spec/spec_helper.rb
71
+ - spec/unit/advance_spec.rb
67
72
  - spec/unit/bar_formatter_spec.rb
73
+ - spec/unit/complete_spec.rb
68
74
  - spec/unit/converter_spec.rb
69
75
  - spec/unit/current_formatter_spec.rb
70
76
  - spec/unit/custom_formatter_spec.rb
71
77
  - spec/unit/elapsed_formatter_spec.rb
78
+ - spec/unit/estimated_formatter_spec.rb
79
+ - spec/unit/frequency_spec.rb
80
+ - spec/unit/hide_cursor_spec.rb
81
+ - spec/unit/log_spec.rb
72
82
  - spec/unit/new_spec.rb
73
83
  - spec/unit/percent_formatter_spec.rb
74
84
  - spec/unit/pipeline_spec.rb
@@ -102,11 +112,17 @@ specification_version: 4
102
112
  summary: A flexible progress bars drawing in terminal emulators.
103
113
  test_files:
104
114
  - spec/spec_helper.rb
115
+ - spec/unit/advance_spec.rb
105
116
  - spec/unit/bar_formatter_spec.rb
117
+ - spec/unit/complete_spec.rb
106
118
  - spec/unit/converter_spec.rb
107
119
  - spec/unit/current_formatter_spec.rb
108
120
  - spec/unit/custom_formatter_spec.rb
109
121
  - spec/unit/elapsed_formatter_spec.rb
122
+ - spec/unit/estimated_formatter_spec.rb
123
+ - spec/unit/frequency_spec.rb
124
+ - spec/unit/hide_cursor_spec.rb
125
+ - spec/unit/log_spec.rb
110
126
  - spec/unit/new_spec.rb
111
127
  - spec/unit/percent_formatter_spec.rb
112
128
  - spec/unit/pipeline_spec.rb