tty-progressbar 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +492 -126
  5. data/lib/tty-progressbar.rb +2 -2
  6. data/lib/tty/progressbar.rb +168 -68
  7. data/lib/tty/progressbar/configuration.rb +121 -27
  8. data/lib/tty/progressbar/converter.rb +16 -19
  9. data/lib/tty/progressbar/formats.rb +120 -0
  10. data/lib/tty/progressbar/formatter.rb +33 -38
  11. data/lib/tty/progressbar/formatter/bar.rb +74 -27
  12. data/lib/tty/progressbar/formatter/byte_rate.rb +6 -20
  13. data/lib/tty/progressbar/formatter/current.rb +4 -19
  14. data/lib/tty/progressbar/formatter/current_byte.rb +9 -17
  15. data/lib/tty/progressbar/formatter/elapsed.rb +9 -18
  16. data/lib/tty/progressbar/formatter/estimated.rb +14 -18
  17. data/lib/tty/progressbar/formatter/estimated_time.rb +37 -0
  18. data/lib/tty/progressbar/formatter/mean_byte.rb +6 -20
  19. data/lib/tty/progressbar/formatter/mean_rate.rb +6 -20
  20. data/lib/tty/progressbar/formatter/percent.rb +10 -16
  21. data/lib/tty/progressbar/formatter/rate.rb +5 -19
  22. data/lib/tty/progressbar/formatter/total.rb +10 -16
  23. data/lib/tty/progressbar/formatter/total_byte.rb +14 -18
  24. data/lib/tty/progressbar/formatters.rb +53 -0
  25. data/lib/tty/progressbar/meter.rb +2 -2
  26. data/lib/tty/progressbar/multi.rb +61 -21
  27. data/lib/tty/progressbar/pipeline.rb +13 -6
  28. data/lib/tty/progressbar/timer.rb +89 -0
  29. data/lib/tty/progressbar/version.rb +1 -1
  30. metadata +44 -103
  31. data/Rakefile +0 -8
  32. data/examples/color.rb +0 -18
  33. data/examples/failure.rb +0 -12
  34. data/examples/iterator.rb +0 -5
  35. data/examples/lazy.rb +0 -6
  36. data/examples/multi/main_bar.rb +0 -13
  37. data/examples/multi/simple.rb +0 -13
  38. data/examples/multi/width.rb +0 -13
  39. data/examples/simple.rb +0 -7
  40. data/examples/slow_process.rb +0 -29
  41. data/examples/speed.rb +0 -11
  42. data/examples/threaded.rb +0 -14
  43. data/examples/tokens.rb +0 -12
  44. data/examples/unicode.rb +0 -7
  45. data/spec/spec_helper.rb +0 -53
  46. data/spec/unit/advance_spec.rb +0 -25
  47. data/spec/unit/clear_spec.rb +0 -17
  48. data/spec/unit/complete_spec.rb +0 -16
  49. data/spec/unit/converter/to_bytes_spec.rb +0 -47
  50. data/spec/unit/converter/to_seconds_spec.rb +0 -15
  51. data/spec/unit/converter/to_time_spec.rb +0 -19
  52. data/spec/unit/custom_formatter_spec.rb +0 -26
  53. data/spec/unit/custom_token_spec.rb +0 -14
  54. data/spec/unit/events_spec.rb +0 -33
  55. data/spec/unit/finish_spec.rb +0 -15
  56. data/spec/unit/formatter/bar_spec.rb +0 -33
  57. data/spec/unit/formatter/byte_rate_spec.rb +0 -32
  58. data/spec/unit/formatter/current_byte_spec.rb +0 -16
  59. data/spec/unit/formatter/current_spec.rb +0 -14
  60. data/spec/unit/formatter/elapsed_spec.rb +0 -58
  61. data/spec/unit/formatter/estimated_spec.rb +0 -27
  62. data/spec/unit/formatter/mean_byte_spec.rb +0 -32
  63. data/spec/unit/formatter/mean_rate_spec.rb +0 -31
  64. data/spec/unit/formatter/percent_spec.rb +0 -16
  65. data/spec/unit/formatter/rate_spec.rb +0 -31
  66. data/spec/unit/formatter/total_byte_spec.rb +0 -16
  67. data/spec/unit/formatter/total_spec.rb +0 -16
  68. data/spec/unit/frequency_spec.rb +0 -27
  69. data/spec/unit/head_spec.rb +0 -32
  70. data/spec/unit/hide_cursor_spec.rb +0 -27
  71. data/spec/unit/inspect_spec.rb +0 -11
  72. data/spec/unit/iterate_spec.rb +0 -79
  73. data/spec/unit/log_spec.rb +0 -29
  74. data/spec/unit/meter_spec.rb +0 -70
  75. data/spec/unit/multi/advance_spec.rb +0 -123
  76. data/spec/unit/multi/events_spec.rb +0 -115
  77. data/spec/unit/multi/finish_spec.rb +0 -41
  78. data/spec/unit/multi/line_inset_spec.rb +0 -65
  79. data/spec/unit/multi/register_spec.rb +0 -35
  80. data/spec/unit/multi/reset_spec.rb +0 -28
  81. data/spec/unit/multi/stop_spec.rb +0 -15
  82. data/spec/unit/multi/width_spec.rb +0 -118
  83. data/spec/unit/new_spec.rb +0 -76
  84. data/spec/unit/pipeline_spec.rb +0 -19
  85. data/spec/unit/ratio_spec.rb +0 -31
  86. data/spec/unit/render_spec.rb +0 -25
  87. data/spec/unit/reset_spec.rb +0 -31
  88. data/spec/unit/resize_spec.rb +0 -35
  89. data/spec/unit/set_current_spec.rb +0 -43
  90. data/spec/unit/start_spec.rb +0 -14
  91. data/spec/unit/stop_spec.rb +0 -19
  92. data/spec/unit/update_spec.rb +0 -22
  93. data/spec/unit/width_spec.rb +0 -86
  94. data/tasks/console.rake +0 -9
  95. data/tasks/coverage.rake +0 -9
  96. data/tasks/spec.rake +0 -27
  97. data/tty-progressbar.gemspec +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aedcd9e5ed7d14d3b50023577a864d973f136c24210d9fb3257ef31fb0a17d14
4
- data.tar.gz: 5415df0a28f43df5fdcee7c154537d4cec6e47af4a30360f1c840a428ef494d3
3
+ metadata.gz: d266b064379d48a7f7efa620115e1de7d289d7d469f09ef3879cc1ccaceb71db
4
+ data.tar.gz: 14ec207136b4910387f398f443351632e12c60744d389c1747a90ddf90cae5cd
5
5
  SHA512:
6
- metadata.gz: fe9efc020a6f6303fb217858ffc5fb2dd5c6a227e4eb6d02f27b546d02e59efb8022c9fe8d1331651fbf5f384071717063a1cb36ccd8929900f25bbd4a6f58b4
7
- data.tar.gz: 3320f20951540bbebb844a2634fc5e2a772b90b0073292b6f464c43737ee01e1cc636b8001b3b271ba264847aa9af68d6b55424c63bdd44cfb43f367f0f776d6
6
+ metadata.gz: e872707b643d2b01f89fb056f31654f0d6aef50c9665936442c8c9f9cb8310f6bb8af447506d6ff3197284b4365595d475c799dc9d1c4dd20f0bc2d9fc395412
7
+ data.tar.gz: d695aa270398d79899aea3dcaa58964f6f24ea8888d84cecbb191982cb52717b82526eeb92561ee50af1ec00e1ddba8d0b378c6d5484c8ed70e2e6890f0e07f4
@@ -1,5 +1,36 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.18.0] - 2021-01-20
4
+
5
+ ### Added
6
+ * Add #resume to allow stopped or paused bar to continue progressing
7
+ * Add :clear_head option to remove head when progress is done
8
+ * Add #configure to allow runtime configuration
9
+ * Add Multi#done? to check if all bar are stopped or finished
10
+ * Add indeterminate progress support when no total is given
11
+ * Add :bar_format option to allow selecting preconfigured bar displays
12
+ * Add :eta_time format token to display the estimated time of day at completion
13
+ * Add measurement of the total elapsed time that ignores stopped time intervals
14
+ * Add #pause to prevent bar from continuing progression and suspend time measurements
15
+ * Add Multi#pause to allow suspending progression of all registered bars at once
16
+ * Add Multi#resume to start again all registered bars that are stopped or paused
17
+ * Add Timer class to handle the total elapsed time measurements
18
+
19
+ ### Changed
20
+ * Change Multi#stopped? to check that all bars are stopped
21
+ * Change gemspec to load version directly and remove test artifacts
22
+ * Change to update strings-ansi and tty-screen dependencies
23
+ * Change Pipeline to inject progress bar instance only once
24
+ * Change :elapsed and :eta to show days after running for 24 hours
25
+ * Change to ensure complete, incomplete and unknown option cannot be an empty string
26
+ * Change to allow setting total to nil via accessor
27
+ * Change gemspec to allow version 2.0 of unicode-display_width dependency
28
+ * Change #stop to show hidden cursor after render similar to #finish
29
+
30
+ ### Fixed
31
+ * Fix MultiBar top bar to allow resuming progress when stopped/done (@d4be4st)
32
+ * Fix MultiBar to only set width when top bar present
33
+
3
34
  ## [v0.17.0] - 2019-05-31
4
35
 
5
36
  ### Changed
@@ -201,6 +232,7 @@
201
232
 
202
233
  * Initial implementation and release
203
234
 
235
+ [v0.18.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.17.0...v0.18.0
204
236
  [v0.17.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.16.0...v0.17.0
205
237
  [v0.16.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.15.1...v0.16.0
206
238
  [v0.15.1]: https://github.com/piotrmurach/tty-progressbar/compare/v0.15.0...v0.15.1
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Piotr Murach
1
+ Copyright (c) 2014 Piotr Murach (piotrmurach.com)
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  <div align="center">
2
- <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
2
+ <a href="https://ttytoolkit.org"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="TTY Toolkit logo"/></a>
3
3
  </div>
4
4
 
5
5
  # TTY::ProgressBar [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/tty-progressbar.svg)][gem]
8
- [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-progressbar.svg?branch=master)][travis]
8
+ [![Actions CI](https://github.com/piotrmurach/tty-progressbar/workflows/CI/badge.svg?branch=master)][gh_actions_ci]
9
9
  [![Build status](https://ci.appveyor.com/api/projects/status/w3jafjeatt1ulufa?svg=true)][appveyor]
10
10
  [![Maintainability](https://api.codeclimate.com/v1/badges/e85416137d2057169575/maintainability)][codeclimate]
11
11
  [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-progressbar/badge.svg)][coverage]
@@ -13,41 +13,46 @@
13
13
 
14
14
  [gitter]: https://gitter.im/piotrmurach/tty
15
15
  [gem]: http://badge.fury.io/rb/tty-progressbar
16
- [travis]: http://travis-ci.org/piotrmurach/tty-progressbar
16
+ [gh_actions_ci]: https://github.com/piotrmurach/tty-progressbar/actions?query=workflow%3ACI
17
17
  [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-progressbar
18
18
  [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-progressbar/maintainability
19
19
  [coverage]: https://coveralls.io/github/piotrmurach/tty-progressbar
20
20
  [inchpages]: http://inch-ci.org/github/piotrmurach/tty-progressbar
21
21
 
22
- > A flexible progress bars drawing in terminal emulators.
22
+ > A flexible and extensible progress bar for terminal applications.
23
23
 
24
- **TTY::ProgressBar** provides independent progress bars component for [TTY](https://github.com/piotrmurach/tty) toolkit.
24
+ **TTY::ProgressBar** provides independent progress bar component for [TTY](https://github.com/piotrmurach/tty) toolkit.
25
25
 
26
26
  ## Features
27
27
 
28
- * Fully [configurable](#3-configuration)
29
- * Extremely flexible progress display [formatting](#4-formatting)
30
- * Includes many predefined tokens to calculate ETA, Bytes ... [tokens](#41-tokens)
31
- * Allows to define your [custom tokens](#42-custom-formatters)
32
- * Supports parallel multi progress bars [multi](#6-ttyprogressbarmulti-api)
33
- * Handles Unicode characters in progress bar [unicode](#44-unicode)
34
- * Works on all ECMA-48 compatible terminals
28
+ * **Customisable.** Choose from many [configuration](#3-configuration) options to get the behaviour you want.
29
+ * **Flexible.** Describe bar [format](#4-formatting) and pick from many predefined [tokens](#41-tokens) and [bar styles](#37-bar_format).
30
+ * **Extensible.** Define [custom tokens](#42-custom-formatters) to fit your needs.
31
+ * **Powerful.** Display [multi](#6-ttyprogressbarmulti-api) progress bars in parallel.
32
+ * Show an unbounded operation with [indeterminate](#31-total) progress.
33
+ * [Pause](#210-pause) and [resume](#212-resume) progress at any time.
34
+ * Include [Unicode](#44-unicode) characters in progress bar.
35
+ * Works on all ECMA-48 compatible terminals.
35
36
 
36
37
  ## Installation
37
38
 
38
39
  Add this line to your application's Gemfile:
39
40
 
40
41
  ```ruby
41
- gem 'tty-progressbar'
42
+ gem "tty-progressbar"
42
43
  ```
43
44
 
44
45
  And then execute:
45
46
 
46
- $ bundle
47
+ ```
48
+ $ bundle
49
+ ```
47
50
 
48
51
  Or install it yourself as:
49
52
 
50
- $ gem install tty-progressbar
53
+ ```
54
+ $ gem install tty-progressbar
55
+ ```
51
56
 
52
57
  ## Contents
53
58
 
@@ -62,15 +67,29 @@ Or install it yourself as:
62
67
  * [2.7 update](#27-update)
63
68
  * [2.8 finish](#28-finish)
64
69
  * [2.9 stop](#29-stop)
65
- * [2.10 reset](#210-reset)
66
- * [2.11 complete?](#211-complete)
67
- * [2.12 resize](#212-resize)
68
- * [2.13 on](#213-on)
70
+ * [2.10 pause](#210-pause)
71
+ * [2.11 reset](#211-reset)
72
+ * [2.12 resume](#212-resume)
73
+ * [2.13 complete?](#213-complete)
74
+ * [2.14 paused?](#214-paused)
75
+ * [2.15 stopped?](#215-stopped)
76
+ * [2.16 indeterminate?](#216-indeterminate)
77
+ * [2.17 resize](#217-resize)
78
+ * [2.18 on](#218-on)
69
79
  * [3. Configuration](#3-configuration)
70
- * [3.1 :head](#31-head)
71
- * [3.2 :output](#32-output)
72
- * [3.3 :frequency](#33-frequency)
73
- * [3.4 :interval](#34-interval)
80
+ * [3.1 :total](#31-total)
81
+ * [3.1 :width](#32-width)
82
+ * [3.3 :complete](#33-complete)
83
+ * [3.4 :incomplete](#34-incomplete)
84
+ * [3.5 :head](#35-head)
85
+ * [3.6 :unknown](#36-unknown)
86
+ * [3.7 :bar_format](#37-bar_format)
87
+ * [3.8 :output](#38-output)
88
+ * [3.9 :frequency](#39-frequency)
89
+ * [3.10 :interval](#310-interval)
90
+ * [3.11 :hide_cursor](#311-hide_cursor)
91
+ * [3.12 :clear](#312-clear)
92
+ * [3.13 :clear_head](#313-clear_head)
74
93
  * [4. Formatting](#4-formatting)
75
94
  * [4.1 Tokens](#41-tokens)
76
95
  * [4.2 Custom Formatters](#42-custom-formatters)
@@ -84,40 +103,63 @@ Or install it yourself as:
84
103
  * [6.4 start](#64-start)
85
104
  * [6.5 finish](#65-finish)
86
105
  * [6.6 stop](#66-stop)
87
- * [6.7 complete?](#67-complete)
88
- * [6.8 on](#68-on)
89
- * [6.9 :style](#69-style)
106
+ * [6.7 pause](#67-pause)
107
+ * [6.8 resume](#68-resume)
108
+ * [6.9 complete?](#69-complete)
109
+ * [6.10 paused?](#610-paused)
110
+ * [6.11 stopped?](#611-stopped)
111
+ * [6.12 on](#612-on)
112
+ * [6.13 :style](#613-style)
90
113
  * [7. Examples](#7-examples)
91
114
  * [7.1 Color](#71-color)
92
115
  * [7.2 Speed](#72-speed)
93
116
 
94
117
  ## 1. Usage
95
118
 
96
- **TTY::ProgressBar** requires only format string and total number of steps to completion. Once initialized, use `advance` method to indicated the progress like so:
119
+ **TTY::ProgressBar** requires only a format string with `:bar` [token](#41-tokens) and total number of steps to completion:
97
120
 
98
121
  ```ruby
99
122
  bar = TTY::ProgressBar.new("downloading [:bar]", total: 30)
123
+ ```
124
+
125
+ Once initialized, use [advance](#21-advance) method to indicated progress:
126
+
127
+ ```ruby
100
128
  30.times do
101
129
  sleep(0.1)
102
- bar.advance(1)
130
+ bar.advance # by default increases by 1
103
131
  end
104
132
  ```
105
133
 
106
- This would produce animation in your terminal:
134
+ This would produce the following animation in your terminal:
107
135
 
108
136
  ```ruby
109
137
  # downloading [======================= ]
110
138
  ```
111
139
 
112
- Use **TTY::ProgressBar::Multi** to display multiple parallel progress bars:
140
+ You can further change a progress bar behaviour and display by changing [configuration](#3-configuration) options and using many predefined [tokens](#41-tokens) and [bar formats](#37-bar_format).
141
+
142
+ When you don't know the total yet, you can set it to `nil` to switch to [indeterminate](#31-total) progress:
143
+
144
+ ```ruby
145
+ # downloading [ <=> ]
146
+ ```
147
+
148
+ Use [TTY::ProgressBar::Multi](#6-ttyprogressbarmulti-api) to display multiple parallel progress bars.
149
+
150
+ Declare a top level bar and then register child bars:
113
151
 
114
152
  ```ruby
115
153
  bars = TTY::ProgressBar::Multi.new("main [:bar] :percent")
116
154
 
117
155
  bar1 = bars.register("one [:bar] :percent", total: 15)
118
156
  bar2 = bars.register("two [:bar] :percent", total: 15)
157
+ ```
119
158
 
120
- bars.start
159
+ Then progress the child bars in parallel:
160
+
161
+ ```ruby
162
+ bars.start # starts all registered bars timers
121
163
 
122
164
  th1 = Thread.new { 15.times { sleep(0.1); bar1.advance } }
123
165
  th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
@@ -125,7 +167,7 @@ th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
125
167
  [th1, th2].each { |t| t.join }
126
168
  ```
127
169
 
128
- which will produce:
170
+ A possible terminal output may look like this:
129
171
 
130
172
  ```ruby
131
173
  # ┌ main [=============== ] 50%
@@ -137,10 +179,10 @@ which will produce:
137
179
 
138
180
  ### 2.1 advance
139
181
 
140
- Once you have **TTY::ProgressBar** instance, you can progress the display by calling `advance` method. By default it will increase by `1` but you can pass any number of steps, for instance, when used to advance number of bytes of downloaded file.
182
+ Once you have **TTY::ProgressBar** instance, you can progress the display by calling `advance` method. By default, it will increase by `1` but you can pass any number of steps, for instance, a number of bytes for a downloaded file:
141
183
 
142
184
  ```ruby
143
- bar.advance(1000)
185
+ bar.advance(1024)
144
186
  ```
145
187
 
146
188
  You can also pass negative steps if you wish to backtrack the progress:
@@ -149,13 +191,13 @@ You can also pass negative steps if you wish to backtrack the progress:
149
191
  bar.advance(-1)
150
192
  ```
151
193
 
152
- Note: If a progress bar has already finished then negative steps will not set it back to desired value.
194
+ *Note:* If a progress bar has already finished then any negative steps will not set it back to desired value.
153
195
 
154
196
  ### 2.2 iterate
155
197
 
156
198
  To simplify progressing over an enumerable you can use `iterate` which as a first argument accepts an `Enumerable` and as a second the amount to progress the bar with.
157
199
 
158
- First, create a progress bar without a total which will be dynamically handled for you:
200
+ First, create a progress bar without a total which will be automatically updated for you once iteration starts:
159
201
 
160
202
  ```ruby
161
203
  bar = TTY::ProgressBar.new("[:bar]")
@@ -167,7 +209,7 @@ Then, either directly iterate over a collection by yielding values to a block:
167
209
  bar.iterate(30.times) { |v| ... }
168
210
  ```
169
211
 
170
- or return an `Enumerator`:
212
+ Or return an `Enumerator`:
171
213
 
172
214
  ```ruby
173
215
  progress = bar.iterate(30.times)
@@ -195,7 +237,7 @@ downloader = Enumerator.new do |y|
195
237
  end
196
238
  ```
197
239
 
198
- would be used with progress bar with the total size matching the content size like so:
240
+ Would be used with progress bar with the total size matching the content size like so:
199
241
 
200
242
  ```ruby
201
243
  bar = TTY::ProgressBar.new("[:bar]", total: content_size)
@@ -209,17 +251,17 @@ Please run [slow_process example](examples/slow_process.rb) to see this in actio
209
251
 
210
252
  ### 2.3 current=
211
253
 
212
- **TTY::ProgressBar** allows you to set progress to a given value by calling `current=` method.
254
+ A progress doesn't have to start from zero. You can set it to a given value using `current=` method:
213
255
 
214
256
  ```ruby
215
257
  bar.current = 50
216
258
  ```
217
259
 
218
- Note: If a progress bar has already finished then negative steps will not set it back to desired value.
260
+ *Note:* If a progress bar has already finished then setting current value will not have any effect.
219
261
 
220
262
  ### 2.4 ratio=
221
263
 
222
- In order to update overall completion of a progress bar as an exact percentage use the `ratio=` method. The method accepts values between `0` and `1` inclusive. For example, a ratio of 0.5 will attempt to set the progress bar halfway:
264
+ In order to update overall completion of a progress bar as an exact percentage use the `ratio=` method. The method accepts values between `0` and `1` inclusive. For example, a ratio of `0.5` will attempt to set the progress bar halfway:
223
265
 
224
266
  ```ruby
225
267
  bar.ratio = 0.5
@@ -227,13 +269,15 @@ bar.ratio = 0.5
227
269
 
228
270
  ### 2.5 width=
229
271
 
230
- 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:
272
+ You can set how many terminal columns will the `:bar` actually span excluding any other tokens and/or text.
273
+
274
+ For example, if you need the bar to be always 20 columns wide do:
231
275
 
232
276
  ```ruby
233
277
  bar.width = 20
234
278
  ```
235
279
 
236
- or with configuration options:
280
+ Or with configuration options:
237
281
 
238
282
  ```ruby
239
283
  bar = TTY::ProgressBar.new("[:bar]", width: 20)
@@ -241,7 +285,7 @@ bar = TTY::ProgressBar.new("[:bar]", width: 20)
241
285
 
242
286
  ### 2.6 start
243
287
 
244
- 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:
288
+ By default the timer for internal time estimation is started automatically when the `advance` method is called. However, if you require control on when the progression timer is started use `start` call:
245
289
 
246
290
  ```ruby
247
291
  bar.start # => sets timer and draws initial progress bar
@@ -249,15 +293,15 @@ bar.start # => sets timer and draws initial progress bar
249
293
 
250
294
  ### 2.7 update
251
295
 
252
- Once the progress bar has been started you can change its configuration option(s) by calling `update`:
296
+ Once a progress bar has been started, you can change its configuration option(s) by calling `update`:
253
297
 
254
298
  ```ruby
255
- bar.update(complete: '+', frequency: 10)
299
+ bar.update(complete: "+", frequency: 10)
256
300
  ```
257
301
 
258
302
  ### 2.8 finish
259
303
 
260
- In order to immediately stop and finish the progress call `finish`. This will finish drawing the progress and return to new line.
304
+ In order to immediately stop and finish progress of a bar call `finish`. This will finish drawing the progress by advancing it to 100% and returning to a new line.
261
305
 
262
306
  ```ruby
263
307
  bar.finish
@@ -265,13 +309,23 @@ bar.finish
265
309
 
266
310
  ### 2.9 stop
267
311
 
268
- In order to immediately stop the bar in the current position and thus finish any further progress use `stop`:
312
+ In order to immediately stop a bar in the current position and thus prevent any further progress use `stop`:
269
313
 
270
314
  ```ruby
271
315
  bar.stop
272
316
  ```
273
317
 
274
- ### 2.10 reset
318
+ ### 2.10 pause
319
+
320
+ A running progress bar can be paused at the current position using `pause` method:
321
+
322
+ ```ruby
323
+ bar.pause
324
+ ```
325
+
326
+ A paused progress bar will stop accumulating any time measurements like elapsed time. It also won't return to a new line, so a progress animation can be smoothly resumed.
327
+
328
+ ### 2.11 reset
275
329
 
276
330
  In order to reset currently running or finished progress bar to its original configuration and initial position use `reset` like so:
277
331
 
@@ -279,23 +333,57 @@ In order to reset currently running or finished progress bar to its original con
279
333
  bar.reset
280
334
  ```
281
335
 
282
- After resetting the bar if you wish to draw and start the bar and its timers use `start` call.
336
+ After resetting a progress bar, if you wish to draw and start a bar and its timers use `start` call.
337
+
338
+ ### 2.12 resume
339
+
340
+ When a bar is stopped or paused, you can continue its progression using the `resume` method.
341
+
342
+ ```ruby
343
+ bar.resume
344
+ ```
345
+
346
+ A resumed progression will continue accumulating the total elapsed time without including time intervals for pausing or stopping.
283
347
 
284
- ### 2.11 complete?
348
+ ### 2.13 complete?
285
349
 
286
- During progresion you can check if a bar is finished or not by calling `complete?`. The bar will only return `true` if the progression finished successfuly, otherwise `false` will be returned.
350
+ During progression you can check whether a bar is finished or not by calling `complete?`. The bar will only return `true` if the progression finished successfully, otherwise `false` will be returned.
287
351
 
288
352
  ```ruby
289
353
  bar.complete? # => false
290
354
  ```
291
355
 
292
- ### 2.12 resize
356
+ ### 2.14 paused?
357
+
358
+ To check whether a progress bar is paused or not use `paused?`:
359
+
360
+ ```ruby
361
+ bar.paused? # => true
362
+ ```
363
+
364
+ ### 2.15 stopped?
365
+
366
+ To check whether a progress bar is stopped or not use `stopped?`:
367
+
368
+ ```ruby
369
+ bar.stopped? # => true
370
+ ```
371
+
372
+ ### 2.16 indeterminate?
293
373
 
294
- If you wish for a progress bar to change it's current width, you can use `resize` by passing in a new desired length. However, if you don't provide any width the `resize` will use terminal current width as its base for scaling.
374
+ You can make a progress bar indeterminate by setting `:total` to `nil`. In this state, a progress bar animation is displayed to show unbounded task. You can check whether the progress bar is indeterminate with the `indeterminate?` method:
295
375
 
296
376
  ```ruby
297
- bar.resize # => determine terminal width and scale accordingly
298
- bar.resize(50) # => will resize bar proportionately from this point onwards
377
+ bar.indeterminate? # => false
378
+ ```
379
+
380
+ ### 2.17 resize
381
+
382
+ If you want to change a progress bar's current width, use `resize` and pass in a new desired length. However, if you don't provide any width the `resize` will use terminal current width as its base for scaling.
383
+
384
+ ```ruby
385
+ bar.resize # determine terminal width and scale accordingly
386
+ bar.resize(50) # will resize bar proportionately from this point onwards
299
387
  ```
300
388
 
301
389
  To handle automatic resizing you can trap `:WINCH` signal:
@@ -304,66 +392,229 @@ To handle automatic resizing you can trap `:WINCH` signal:
304
392
  trap(:WINCH) { bar.resize }
305
393
  ```
306
394
 
307
- ### 2.13 on
395
+ ### 2.18 on
308
396
 
309
- The progress bar fires events when it is progressing, stopped or finished. You can register to listen for events using the `on` message.
397
+ A progress bar fires events when it is progressing, paused, stopped or finished. You can register to listen for these events using the `on` message.
310
398
 
311
- Every time an `advance` is called the `:progress` event gets fired which you can listen for inside a block which includes the actual amount of progress as a first yielded argument:
399
+ Every time an `advance` is called the `:progress` event gets fired which you can listen for inside a block. A first yielded argument is the actual amount of progress:
312
400
 
313
401
  ```ruby
314
402
  bar.on(:progress) { |amount| ... }
315
403
  ```
316
404
 
317
- When the progress bar finishes and completes then the `:done` event is fired. You can listen for this event:
405
+ When a progress bar finishes and completes then the `:done` event is fired. You can listen for this event:
318
406
 
319
407
  ```ruby
320
408
  bar.on(:done) { ... }
321
409
  ```
322
410
 
323
- Alternatively, when the progress bar gets stopped the `:stopped` event is fired. You can listen for this event:
411
+ Alternatively, when a progress bar gets stopped the `:stopped` event is fired. You can listen for this event:
324
412
 
325
413
  ```ruby
326
414
  bar.on(:stopped) { ... }
327
415
  ```
328
416
 
417
+ Anytime a progress bar is paused the `:paused` event will be fired. To listen for this event do:
418
+
419
+ ```ruby
420
+ bar.on(:paused) { ... }
421
+ ```
422
+
329
423
  ## 3. Configuration
330
424
 
331
425
  There are number of configuration options that can be provided:
332
426
 
333
- * `:total` total number of steps to completion
334
- * `:width` of the bars display in terminal columns excluding formatting options. Defaults to total steps
335
- * `:complete` completion character by default `=`
336
- * `:incomplete` incomplete character by default single space
337
- * [:head](#31-head) the head character by default `=`
338
- * [:output](#32-output) the output stream defaulting to `stderr`
339
- * [:frequency](#33-frequency) used to throttle the output, by default `0`
340
- * [:interval](#34-interval) used to measure the speed, by default `1 sec`
341
- * `:hide_cursor` to hide display cursor defaulting to `false`
342
- * `:clear` to clear the finished bar defaulting to `false`
427
+ * [:total](#31-total) - the total number of steps to completion.
428
+ * [:width](#32-width) - the number of terminal columns for displaying a bar excluding other tokens. Defaults to total steps.
429
+ * [:complete](#33-complete) - the completion character, by default `=`.
430
+ * [:incomplete](#34-incomplete) - the incomplete character, by default single space.
431
+ * [:head](#35-head) - the head character, by default `=`.
432
+ * [:unknown](#36-unknown) - the character(s) used to show indeterminate progress, defaults to `<=>`.
433
+ * [:bar_format](#37-bar_format) - the predefined bar format, by default `:classic`.
434
+ * [:output](#38-output) - the output stream defaulting to `stderr`.
435
+ * [:frequency](#39-frequency) - used to throttle the output, by default `0`.
436
+ * [:interval](#310-interval) - the time interval used to measure rate, by default `1 sec`.
437
+ * [:hide_cursor](#311-hide_cursor) - whether to hide the console cursor or not, defaults to `false`.
438
+ * [:clear](#312-clear) - whether to clear the finished bar or not, defaults to `false`.
439
+ * [:clear_head](#313-clear_head) - whether to clear the head character when the progress is done or not, defaults to `false`.
343
440
 
344
441
  All the above options can be passed in as hash options or block parameters:
345
442
 
346
443
  ```ruby
347
- TTY::ProgressBar.new "[:bar]" do |config|
444
+ bar = TTY::ProgressBar.new("[:bar]") do |config|
348
445
  config.total = 30
349
446
  config.frequency = 10
350
447
  config.clear = true
351
448
  end
352
449
  ```
353
450
 
354
- ### 3.1 :head
451
+ The progress bar's configuration can also be changed at runtime with `configure`:
452
+
453
+ ```ruby
454
+ bar.configure do |config|
455
+ config.total = 100 # takes precedence over the original value
456
+ config.frequencye = 20
457
+ end
458
+ ```
459
+
460
+ Or with the [update](#27-update) method:
461
+
462
+ ```ruby
463
+ bar.update(total: 100, frequency: 20)
464
+ ```
465
+
466
+ ### 3.1 :total
467
+
468
+ The `:total` option determines the final value at which the progress bar fills up and stops.
469
+
470
+ ```ruby
471
+ TTY::ProgressBar.new("[:bar]", total: 30)
472
+ ```
473
+
474
+ Setting `:total` to `nil` or leaving it out will cause the progress bar to switch to indeterminate mode. Instead of showing completeness for a task, it will render animation like `<=>` that moves left and right:
475
+
476
+ ```ruby
477
+ # [ <=> ]
478
+ ```
479
+
480
+ The indeterminate mode is useful to show time-consuming and unbounded task.
481
+
482
+ Run [examples/indeterminate](https://github.com/piotrmurach/tty-progressbar/blob/master/examples/indeterminate.rb) to see indeterminate progress animation in action.
483
+
484
+ ### 3.2 :width
485
+
486
+ The progress bar width defaults to the total value and is capped at the maximum terminal width minus all the labels. If you want to enforce the bar to have a specific length use the `:width` option:
487
+
488
+ ```ruby
489
+ TTY::ProgressBar.new("[:bar]", width: 30)
490
+ ```
491
+
492
+ ### 3.3 :complete
493
+
494
+ By default, the `=` character is used to mark progression but this can be changed with `:complete` option:
495
+
496
+ ```ruby
497
+ TTY::ProgressBar.new("[:bar]", complete: "x")
498
+ ```
499
+
500
+ Then the output could look like this:
501
+
502
+ ```ruby
503
+ # [xxxxxxxx ]
504
+ ```
505
+
506
+ ### 3.4 :incomplete
507
+
508
+ By default no characters are shown to mark the remaining progress in the `:classic` bar format. Other [bar styles](#37-bar_format) often have incomplete character. You can change this with `:incomplete` option:
509
+
510
+ ```ruby
511
+ TTY::ProgressBar.new("[:bar]", incomplete: "_")
512
+ ```
513
+
514
+ A possible output may look like this:
515
+
516
+ ```ruby
517
+ # [======_________]
518
+ ```
519
+
520
+ ### 3.5 :head
355
521
 
356
522
  If you prefer for the animated bar to display a specific character for a head of progression then use `:head` option:
357
523
 
358
524
  ```ruby
359
- bar = TTY::ProressBar.new("[:bar]", head: '>')
360
- #
525
+ TTY::ProgressBar.new("[:bar]", head: ">")
526
+ ```
527
+
528
+ This could result in output like this:
529
+
530
+ ```ruby
361
531
  # [=======> ]
362
532
  ```
363
533
 
364
- ### 3.2 :output
534
+ ### 3.6 :unknown
535
+
536
+ By default, a progress bar shows indeterminate progress using `<=>` characters:
537
+
538
+ ```ruby
539
+ # [ <=> ]
540
+ ```
541
+
542
+ Other [bar formats](#37-bar_format) use different characters.
365
543
 
366
- The progress bar only outputs to a console and when output is redirected to a file or a pipe it does nothing. This is so, for example, your error logs do not overflow with progress bars output.
544
+ You can change this with the `:unknown` option:
545
+
546
+ ```ruby
547
+ TTY::ProgressBar.new("[:bar]", unknown: "<?>")
548
+ ```
549
+
550
+ This may result in the following output:
551
+
552
+ ```ruby
553
+ # [ <?> ]
554
+ ````
555
+
556
+ ### 3.7 :bar_format
557
+
558
+ There are number of preconfigured bar formats you can choose from.
559
+
560
+ | Name | Determinate | Indeterminate |
561
+ |:-----------|:-------------|:--------------|
562
+ | `:arrow` | `▸▸▸▸▸▹▹▹▹▹` | `◂▸` |
563
+ | `:asterisk`| `✱✱✱✱✱✳✳✳✳✳` | `✳✱✳` |
564
+ | `:blade` | `▰▰▰▰▰▱▱▱▱▱` | `▱▰▱` |
565
+ | `:block` | `█████░░░░░` | `█` |
566
+ | `:box` | `■■■■■□□□□□` | `□■□` |
567
+ | `:bracket` | `❭❭❭❭❭❭❭❭❭❭` | `❬=❭` |
568
+ | `:burger` | `≡≡≡≡≡≡≡≡≡≡` | `<≡>` |
569
+ | `:button` | `⦿⦿⦿⦿⦿⦾⦾⦾⦾⦾` | `⦾⦿⦾` |
570
+ | `:chevron` | `››››››››››` | `‹=›` |
571
+ | `:circle` | `●●●●●○○○○○` | `○●○` |
572
+ | `:classic` | `==========` | `<=>` |
573
+ | `:crate` | `▣▣▣▣▣⬚⬚⬚⬚⬚` | `⬚▣⬚` |
574
+ | `:diamond` | `♦♦♦♦♦♢♢♢♢♢` | `♢♦♢` |
575
+ | `:dot` | `・・・・・・・・・・` | `・・・` |
576
+ | `:heart` | `♥♥♥♥♥♡♡♡♡♡` | `♡♥♡` |
577
+ | `:rectangle` | `▮▮▮▮▮▯▯▯▯▯` | `▯▮▯` |
578
+ | `:square` | `▪▪▪▪▪▫▫▫▫▫` | `▫▪▫` |
579
+ | `:star` | `★★★★★☆☆☆☆☆` | `☆★☆` |
580
+ | `:track` | `▬▬▬▬▬═════` | `═▬═` |
581
+ | `:tread` | `❱❱❱❱❱❱❱❱❱❱` | `❰=❱` |
582
+ | `:triangle`| `▶▶▶▶▶▷▷▷▷▷` | `◀▶` |
583
+ | `:wave` | `~~~~~_____` | `<~>` |
584
+
585
+ For example, you can specify `:box` format with the `:bar_format` option:
586
+
587
+ ```ruby
588
+ TTY::ProgressBar.new("[:bar]", bar_format: :box)
589
+ ```
590
+
591
+ This will result in output like this:
592
+
593
+ ```ruby
594
+ # [■■■■■□□□□□□□□□□]
595
+ ```
596
+
597
+ You can overwrite `:complete`, `:incomplete`, `:head` and `:unknown` characters:
598
+
599
+ ```ruby
600
+ TTY::ProgressBar.new("[:bar]", bar_format: :box, incomplete: " ", unknown: "?")
601
+ ```
602
+
603
+ This will display the following when total is given:
604
+
605
+ ```ruby
606
+ # [■■■■■ ]
607
+ ```
608
+
609
+ And for the unknown progress the `?` character will move from left to right:
610
+
611
+ ```ruby
612
+ # [ ? ]
613
+ ```
614
+
615
+ ### 3.8 :output
616
+
617
+ A progress bar only outputs to a console. When the output is, for example, redirected to a file or a pipe, the progress bar doesn't get printed. This is so, for example, your error logs do not overflow with progress bar output.
367
618
 
368
619
  You can change where console output is streamed with `:output` option:
369
620
 
@@ -373,7 +624,7 @@ bar = TTY::ProgressBar.new(output: $stdout)
373
624
 
374
625
  The output stream defaults to `stderr`.
375
626
 
376
- ### 3.3 :frequency
627
+ ### 3.9 :frequency
377
628
 
378
629
  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.
379
630
 
@@ -383,9 +634,9 @@ The `frequency` option accepts `integer` representing number of `Hz` units, for
383
634
  TTY::ProgressBar.new("[:bar]", total: 30, frequency: 10) # 10 Hz
384
635
  ```
385
636
 
386
- ### 3.4 :interval
637
+ ### 3.10 :interval
387
638
 
388
- For every call of `advance` method the **ProgressBar** takes a sample for speed measurement. By default the samples are grouped per second but you can change that by passing the `interval` option.
639
+ Every time `advance` method is called, a time sample is taken for speed measurement. By default, all the samples are grouped in second intervals to provide a rate of speed. You can change this by passing the `interval` option.
389
640
 
390
641
  The `interval` option is an `integer` that represents the number of seconds, for example, interval of `60` would mean that speed is measured per 1 minute.
391
642
 
@@ -395,6 +646,55 @@ TTY::ProgressBar.new(":rate/minute", total: 100, interval: 60) # 1 minute
395
646
  TTY::ProgressBar.new(":rate/hour", total: 100, interval: 3600) # 1 hour
396
647
  ```
397
648
 
649
+ ### 3.11 :hide_cursor
650
+
651
+ By default the cursor is visible during progress bar rendering. If you wish to hide it, you can do so with the `:hide_cursor` option.
652
+
653
+ Please note that hiding cursor changes user's terminal and you need to ensure that the cursor is made visible after your code finishes. This means also handling premature interrupt signals and other unpredictable events.
654
+
655
+ One solution is to wrap your progress rendering inside the `begin` and `ensure` like so:
656
+
657
+ ```ruby
658
+ progress = TTY::ProgressBar.new("[:bar]", hide_cursor: true)
659
+
660
+ begin
661
+ # logic to advance progress bar
662
+ ensure
663
+ progress.stop # or progress.finish
664
+ # both methods will ensure that cursor is made visible again
665
+ end
666
+ ```
667
+
668
+ ### 3.12 :clear
669
+
670
+ By default, when a progress bar finishes it returns to a new line leaving the last progress output behind.
671
+
672
+ If you prefer to erase a progress bar when it is finished use `:clear` option:
673
+
674
+ ```ruby
675
+ TTY::ProgressBar.new("[:bar]", clear: true)
676
+ ```
677
+
678
+ ### 3.13 :clear_head
679
+
680
+ When a progress bar finishes and its animation includes [:head](#35-head) character, the character will remain in the output:
681
+
682
+ ```ruby
683
+ # [=============>]
684
+ ```
685
+
686
+ To replace a head character when a progress bar is finished use `:clear_head` option:
687
+
688
+ ```ruby
689
+ TTY::ProgressBar.new("[:bar]", clear_head: true)
690
+ ```
691
+
692
+ This will result in the following output:
693
+
694
+ ```ruby
695
+ # [==============]
696
+ ```
697
+
398
698
  ## 4. Formatting
399
699
 
400
700
  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:
@@ -414,38 +714,55 @@ These are the tokens that are currently supported:
414
714
  * `:total_byte` the total progress in bytes
415
715
  * `:percent` the completion percentage
416
716
  * `:elapsed` the elapsed time in seconds
417
- * `:eta` the esitmated time to completion in seconds
717
+ * `:eta` the estimated time to completion in seconds
718
+ * `:eta_time` the estimated time of day at completion
418
719
  * `:rate` the current rate of progression per second
419
- * `:byte_rate` the current rate of pregression in bytes per second
720
+ * `:byte_rate` the current rate of progression in bytes per second
420
721
  * `:mean_rate` the averaged rate of progression per second
421
722
  * `:mean_byte` the averaged rate of progression in bytes per second
422
723
 
724
+ In the indeterminate mode, the progress bar displays `-` for tokens that cannot be calculated like `:total`, `:total_byte`, `:percent` and `:eta`. The following format:
725
+
726
+ ```ruby
727
+ "[:bar] :current/:total :total_byte :percent ET::elapsed ETA::eta :rate/s"
728
+ ```
729
+
730
+ Will result in:
731
+
732
+ ```ruby
733
+ # [ <=> ] 23/- -B -% ET: 1s ETA:--s 18.01/s
734
+ ```
735
+
423
736
  ### 4.2 Custom Formatters
424
737
 
425
738
  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. This option is preferred if you are going to rely on progress bar internal data such as `rate`, `current` etc. which will all be available on the passed in progress bar instance.
426
739
 
427
- For example, begin by creating custom formatter called `TimeFormatter` that will dynamicly update `:time` token in format string. The methods that you need to specify are `initialize`, `matches?` and `format` like follows:
740
+ For example, let's say you want to add `:time` token. First, start by creating a custom formatter class called `TimeFormatter` that will dynamically update `:time` token in the formatted string. In order for the `TimeFormatter` to recognise the `:time` token, you'll need to include the `TTY::ProgressBar::Formatter` module with a regular expression matching the token like so:
428
741
 
429
742
  ```ruby
430
743
  class TimeFormatter
431
- def initialize(progress)
432
- @progress = progress # current progress bar instance
433
- end
744
+ include TTY::ProgressBar::Formatter[/:time/i]
745
+ ...
746
+ end
747
+ ```
434
748
 
435
- def matches?(value) # specify condition to match for in display string
436
- value.to_s =~ /:time/
437
- end
749
+ Next, add `call` method that will substitute the matched token with an actual value. For example, to see the time elapsed since the start do:
750
+
751
+ ```ruby
752
+ class TimeFormatter
753
+ include TTY::ProgressBar::Formatter[/:time/i]
438
754
 
439
- def format(value) # specify how display string is formatted
440
- transformed = (Time.now - @progress.start_at).to_s
441
- value.gsub(/:time/, transformed) # => :time token replacement
755
+ def call(value) # specify how display string is formatted
756
+ # access current progress bar instance to read start time
757
+ elapsed = (Time.now - progress.start_time).to_s
758
+ value.gsub(matcher, elapsed) # replace :time token with a value
442
759
  end
443
760
  end
444
761
  ```
445
762
 
446
- Notice that you have access to all the configuration options inside the formatter by simply invoking them on the `@progress` instance.
763
+ Notice that you have access to all the configuration options inside the formatter by simply invoking them on the `progress` instance.
447
764
 
448
- Create **TTY::ProgressBar** instance with new token:
765
+ Create **TTY::ProgressBar** instance using the new token:
449
766
 
450
767
  ```ruby
451
768
  bar = TTY::ProgressBar.new(":time", total: 30)
@@ -457,7 +774,7 @@ Then add `TimeFormatter` to the pipeline like so:
457
774
  bar.use TimeFormatter
458
775
  ```
459
776
 
460
- and then invoke progression:
777
+ Then invoke progression:
461
778
 
462
779
  ```ruby
463
780
  bar.advance
@@ -465,39 +782,47 @@ bar.advance
465
782
 
466
783
  ### 4.3 Custom Tokens
467
784
 
468
- You can define custom tokens by passing pairs `name: value` to `advance` method in order to dynamically update formatted bar. This option is useful for lightweight content replacement such as titles that doesn't depend on the internal data of progressbar. For example:
785
+ You can define custom tokens by passing pairs `name: value` to `advance` method in order to dynamically update formatted bar. This option is useful for lightweight content replacement such as titles that doesn't depend on the internal data of a progress bar. For example:
469
786
 
470
787
  ```ruby
471
788
  bar = TTY::ProgressBar.new("(:current) :title", total: 4)
472
- bar.advance(title: 'Hello Piotr!')
473
- bar.advance(3, title: 'Bye Piotr!')
789
+ bar.advance(title: "Hello Piotr!")
790
+ bar.advance(3, title: "Bye Piotr!")
474
791
  ```
475
792
 
476
- which outputs:
793
+ This will output:
477
794
 
478
795
  ```ruby
479
- (1) Hello Piotr!
480
- (4) Bye Piotr!
796
+ # (1) Hello Piotr!
797
+ # (4) Bye Piotr!
481
798
  ```
482
799
 
483
800
  ### 4.4 Unicode
484
801
 
485
- The format string as well as `:complete`, `:head` and `:incomplete` configuration options can contain Unicode characters that aren't monospaced.
802
+ The format string as well as [:complete](#33-complete), [:head](#35-head), [:incomplete](#34-incomplete) and [:unknown](#36-unknown) configuration options can contain Unicode characters that aren't monospaced.
486
803
 
487
804
  For example, you can specify complete bar progression character to be Unicode non-monospaced:
488
805
 
489
806
  ```ruby
490
- bar = TTY::ProgressBar.new("Unicode [:bar]", total: 30, complete: '')
491
- #
492
- # => Unicode [あああああああああああああああ]
807
+ bar = TTY::ProgressBar.new("Unicode [:bar]", total: 30, complete: "")
808
+ ```
809
+
810
+ Advancing above progress bar to completion will fit `あ` characters in 30 terminal columns:
811
+
812
+ ```ruby
813
+ # Unicode [あああああああああああああああ]
493
814
  ```
494
815
 
495
816
  Similarly, the formatted string can include Unicode characters:
496
817
 
497
818
  ```ruby
498
819
  bar = TTY::ProgressBar.new("あめかんむり[:bar]", total: 20)
499
- #
500
- # => あめかんむり[== ]
820
+ ```
821
+
822
+ A finished progress bar will also fit within allowed width:
823
+
824
+ ```ruby
825
+ # あめかんむり[== ]
501
826
  ```
502
827
 
503
828
  ## 5. Logging
@@ -505,11 +830,11 @@ bar = TTY::ProgressBar.new("あめかんむり[:bar]", total: 20)
505
830
  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.
506
831
 
507
832
  ```ruby
508
- bar.log('Piotrrrrr')
833
+ bar.log("Piotrrrrr")
509
834
  bar.advance
510
835
  ```
511
836
 
512
- will result in:
837
+ This could result in the following output:
513
838
 
514
839
  ```ruby
515
840
  # Piotrrrrr
@@ -520,14 +845,13 @@ will result in:
520
845
 
521
846
  ### 6.1 new
522
847
 
523
- The multi progress bar can be created in two ways. If you simply want to group multiple progress bars you can create multi bar like so:
848
+ The multi progress bar can be created in two ways. If you simply want to group multiple progress bars together, you can create multi bar without a format string like so:
524
849
 
525
850
  ```ruby
526
851
  TTY::ProgressBar::Multi.new
527
852
  ```
528
853
 
529
-
530
- However, if you want a top level multibar that tracks all the registered progress bars then provide a formatted string:
854
+ However, if you want a top level multibar that tracks progress of all the registered progress bars then you need to provide a formatted string:
531
855
 
532
856
  ```ruby
533
857
  TTY::ProgressBar::Multi.new("main [:bar] :percent")
@@ -542,15 +866,15 @@ multibar = TTY::ProgressBar::Multi.new
542
866
  bar = multibar.register("[:bar]", total: 30)
543
867
  ```
544
868
 
545
- The `register` call returns the newly created progress bar which answers all the progress bar api messages.
869
+ The `register` call returns the newly created progress bar that can be changed using all the available [progress bar API](#2-ttyprogressbar-api) methods.
546
870
 
547
- Please remember to specify total value for each registered progress bar, either when sending `register` message or when using `update` to dynamicaly assign the total value.
871
+ *Note:* Remember to specify total value for each registered progress bar, either when sending `register` message or when using `update` to dynamically assign the total value.
548
872
 
549
873
  ### 6.3 advance
550
874
 
551
875
  Once multi progress bar has been created you can advance each registered progress bar individually, either by executing them one after the other synchronously or by placing them in separate threads thus progressing each bar asynchronously. The multi bar handles synchronization and display of all bars as they continue their respective rendering.
552
876
 
553
- For example, to display two bars async, first register them with the multi bar:
877
+ For example, to display two bars asynchronously, first register them with the multi bar:
554
878
 
555
879
  ```ruby
556
880
  bar1 = multibar.register("one [:bar]", total: 20)
@@ -572,7 +896,7 @@ Finally, wait for the threads to finish:
572
896
 
573
897
  ### 6.4 start
574
898
 
575
- By default the top level multi bar will be rendered as the first bar and have its timer started when on of the regsitered bars advances. However, if you wish to start timers and draw the top level multi bar do:
899
+ By default the top level multi bar will be rendered as the first bar and have its timer started when one of the registered bars advances. However, if you wish to start timers and draw the top level multi bar do:
576
900
 
577
901
  ```ruby
578
902
  multibar.start # => sets timer and draws top level multi progress bar
@@ -580,7 +904,7 @@ multibar.start # => sets timer and draws top level multi progress bar
580
904
 
581
905
  ### 6.5 finish
582
906
 
583
- In order to finish all progress bars call `finish`. This will finish the top level progress bar, if it exists, all any registered progress bars still in progress.
907
+ In order to finish all progress bars call `finish`. This will finish the top level progress bar, if it exists, and any registered progress bar still in progress.
584
908
 
585
909
  ```ruby
586
910
  multibar.finish
@@ -594,7 +918,23 @@ Use `stop` to terminate immediately all progress bars registered with the multib
594
918
  multibar.stop
595
919
  ```
596
920
 
597
- ### 6.7 complete?
921
+ ### 6.7 pause
922
+
923
+ All running progress bars can be paused at their current positions using the `pause` method:
924
+
925
+ ```ruby
926
+ multibar.pause
927
+ ````
928
+
929
+ ### 6.8 resume
930
+
931
+ When one or more registered progress bar is stopped or paused, they can be resumed all at once using the `resume` method:
932
+
933
+ ```ruby
934
+ multibar.resume
935
+ ```
936
+
937
+ ### 6.9 complete?
598
938
 
599
939
  To check if all registered progress bars have been successfully finished use `complete?`
600
940
 
@@ -602,7 +942,23 @@ To check if all registered progress bars have been successfully finished use `co
602
942
  multibar.complete? # => true
603
943
  ```
604
944
 
605
- ### 6.8 on
945
+ ### 6.10 paused?
946
+
947
+ To check whether all progress bars are paused or not use `paused?`:
948
+
949
+ ```ruby
950
+ multibar.paused? # => true
951
+ ```
952
+
953
+ ### 6.11 stopped?
954
+
955
+ To check whether all progress bars are stopped or not use `stopped?`:
956
+
957
+ ```ruby
958
+ multibar.stopped? # => true
959
+ ```
960
+
961
+ ### 6.12 on
606
962
 
607
963
  Similar to `TTY::ProgressBar` the multi bar fires events when it is progressing, stopped or finished. You can register to listen for events using the `on` message.
608
964
 
@@ -618,21 +974,27 @@ When all the registered progress bars finish and complete then the `:done` event
618
974
  multibar.on(:done) { ... }
619
975
  ```
620
976
 
621
- Finally, when any of the progress bars gets stopped the `:stopped` event is fired. You can listen for this event:
977
+ When any of the progress bars gets stopped the `:stopped` event is fired. You can listen for this event:
622
978
 
623
979
  ```ruby
624
980
  multibar.on(:stopped) { ... }
625
981
  ```
626
982
 
627
- ### 6.9 :style
983
+ Anytime a registered progress bar pauses, a `:paused` event will be fired. To listen for this event do:
984
+
985
+ ```ruby
986
+ multibar.on(:paused) { ... }
987
+ ```
988
+
989
+ ### 6.13 :style
628
990
 
629
991
  In addition to all [configuration options](#3-configuration) you can style multi progress bar:
630
992
 
631
993
  ```ruby
632
994
  TTY::ProgressBar::Multi.new("[:bar]", style: {
633
- top: '. '
634
- middle: '|-> '
635
- bottom: '|__ '
995
+ top: ". ",
996
+ middle: "|-> ",
997
+ bottom: "|__ "
636
998
  })
637
999
  ```
638
1000
 
@@ -645,7 +1007,7 @@ This section demonstrates some of the possible uses for the **TTY::ProgressBar**
645
1007
  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/piotrmurach/pastel) library like so:
646
1008
 
647
1009
  ```ruby
648
- require 'pastel'
1010
+ require "pastel"
649
1011
 
650
1012
  pastel = Pastel.new
651
1013
  green = pastel.on_green(" ")
@@ -698,6 +1060,10 @@ This will result in output similar to:
698
1060
 
699
1061
  This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
700
1062
 
1063
+ ## Code of Conduct
1064
+
1065
+ Everyone interacting in the TTY::ProgressBar project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/tty-progressbar/blob/master/CODE_OF_CONDUCT.md).
1066
+
701
1067
  ## Copyright
702
1068
 
703
- Copyright (c) 2014-2018 Piotr Murach. See LICENSE for further details.
1069
+ Copyright (c) 2014 Piotr Murach. See LICENSE for further details.