tty-progressbar 0.15.1 → 0.18.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +495 -125
  5. data/lib/tty-progressbar.rb +2 -2
  6. data/lib/tty/progressbar.rb +169 -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 +18 -20
  17. data/lib/tty/progressbar/formatter/estimated_time.rb +39 -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 +3 -1
  30. metadata +56 -164
  31. data/.codeclimate.yml +0 -11
  32. data/.gitignore +0 -14
  33. data/.rspec +0 -3
  34. data/.travis.yml +0 -26
  35. data/CODE_OF_CONDUCT.md +0 -74
  36. data/Gemfile +0 -14
  37. data/Rakefile +0 -8
  38. data/appveyor.yml +0 -23
  39. data/examples/color.rb +0 -18
  40. data/examples/failure.rb +0 -12
  41. data/examples/iterator.rb +0 -5
  42. data/examples/lazy.rb +0 -6
  43. data/examples/multi/main_bar.rb +0 -13
  44. data/examples/multi/simple.rb +0 -13
  45. data/examples/multi/width.rb +0 -13
  46. data/examples/simple.rb +0 -7
  47. data/examples/slow_process.rb +0 -29
  48. data/examples/speed.rb +0 -11
  49. data/examples/threaded.rb +0 -14
  50. data/examples/tokens.rb +0 -12
  51. data/examples/unicode.rb +0 -7
  52. data/spec/spec_helper.rb +0 -51
  53. data/spec/unit/advance_spec.rb +0 -25
  54. data/spec/unit/clear_spec.rb +0 -17
  55. data/spec/unit/complete_spec.rb +0 -16
  56. data/spec/unit/converter/to_bytes_spec.rb +0 -47
  57. data/spec/unit/converter/to_seconds_spec.rb +0 -15
  58. data/spec/unit/converter/to_time_spec.rb +0 -19
  59. data/spec/unit/custom_formatter_spec.rb +0 -26
  60. data/spec/unit/custom_token_spec.rb +0 -14
  61. data/spec/unit/events_spec.rb +0 -33
  62. data/spec/unit/finish_spec.rb +0 -15
  63. data/spec/unit/formatter/bar_spec.rb +0 -16
  64. data/spec/unit/formatter/byte_rate_spec.rb +0 -32
  65. data/spec/unit/formatter/current_byte_spec.rb +0 -16
  66. data/spec/unit/formatter/current_spec.rb +0 -14
  67. data/spec/unit/formatter/elapsed_spec.rb +0 -58
  68. data/spec/unit/formatter/estimated_spec.rb +0 -27
  69. data/spec/unit/formatter/mean_byte_spec.rb +0 -32
  70. data/spec/unit/formatter/mean_rate_spec.rb +0 -31
  71. data/spec/unit/formatter/percent_spec.rb +0 -16
  72. data/spec/unit/formatter/rate_spec.rb +0 -31
  73. data/spec/unit/formatter/total_byte_spec.rb +0 -16
  74. data/spec/unit/formatter/total_spec.rb +0 -16
  75. data/spec/unit/frequency_spec.rb +0 -27
  76. data/spec/unit/head_spec.rb +0 -32
  77. data/spec/unit/hide_cursor_spec.rb +0 -27
  78. data/spec/unit/inspect_spec.rb +0 -11
  79. data/spec/unit/iterate_spec.rb +0 -79
  80. data/spec/unit/log_spec.rb +0 -29
  81. data/spec/unit/meter_spec.rb +0 -70
  82. data/spec/unit/multi/advance_spec.rb +0 -123
  83. data/spec/unit/multi/events_spec.rb +0 -115
  84. data/spec/unit/multi/finish_spec.rb +0 -41
  85. data/spec/unit/multi/line_inset_spec.rb +0 -65
  86. data/spec/unit/multi/register_spec.rb +0 -35
  87. data/spec/unit/multi/reset_spec.rb +0 -28
  88. data/spec/unit/multi/stop_spec.rb +0 -15
  89. data/spec/unit/multi/width_spec.rb +0 -118
  90. data/spec/unit/new_spec.rb +0 -76
  91. data/spec/unit/pipeline_spec.rb +0 -19
  92. data/spec/unit/ratio_spec.rb +0 -31
  93. data/spec/unit/render_spec.rb +0 -25
  94. data/spec/unit/reset_spec.rb +0 -31
  95. data/spec/unit/resize_spec.rb +0 -35
  96. data/spec/unit/set_current_spec.rb +0 -43
  97. data/spec/unit/start_spec.rb +0 -14
  98. data/spec/unit/stop_spec.rb +0 -19
  99. data/spec/unit/update_spec.rb +0 -22
  100. data/spec/unit/width_spec.rb +0 -86
  101. data/tasks/console.rake +0 -9
  102. data/tasks/coverage.rake +0 -9
  103. data/tasks/spec.rake +0 -27
  104. data/tty-progressbar.gemspec +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 940663302a6775a3d728f4f10d15baf71da3506de9f3d38c41afd1cb9e62c9fd
4
- data.tar.gz: 60d9a661744ebf03811bb9c68a3254003c1f28882998fe21083b0226beab720e
3
+ metadata.gz: 6e266e18a501b913609146035057b886fb5810fa9415b4ba217cf21901b4963e
4
+ data.tar.gz: 7ef378c17f1d033f4ef38258591ece40267cf51f4867786f42c6aaec4734edf7
5
5
  SHA512:
6
- metadata.gz: 0f195b2df5a8c46be31ab2464a4b0413357e2a1ed89136a8e11ffc509b59e243a8a5719d1caa616f0e5b1e0608936ce271992e06ed2d7db4dbfb4a6aabf05396
7
- data.tar.gz: 4223f51b08087157277d8bc660b06751962b2884401484e4962250e6031fa24c6fc524f21f90bb5709adc76f023eacf063ca652a792088292a44ef0c1af1a7ec
6
+ metadata.gz: b77549a6eafedcd5bbe077013f53a694cbcfe0b21fe3d098a8e790dbb8c95e37af1f49b2d3c928196002c26f3e0f1dbda0eb472a947f5c0f421e49cf9bfc3df1
7
+ data.tar.gz: 22b5ea40361f6a300211a34031f39436120be9fcac78a62fb51a334c0f279422ad45229c5379584a85368478e72a242f376abbec6682833b4c82015d5bb3f816
data/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.18.2] - 2021-03-08
4
+
5
+ ### Fixed
6
+ * Fix calculating total in MultiBar with indeterminate children by Tim Tilberg(@ttilberg)
7
+
8
+ ## [v0.18.1] - 2021-01-25
9
+
10
+ ### Fixed
11
+ * Fix :eta and :eta_time format tokens display when progress isn't started
12
+
13
+ ## [v0.18.0] - 2021-01-20
14
+
15
+ ### Added
16
+ * Add #resume to allow stopped or paused bar to continue progressing
17
+ * Add :clear_head option to remove head when progress is done
18
+ * Add #configure to allow runtime configuration
19
+ * Add Multi#done? to check if all bar are stopped or finished
20
+ * Add indeterminate progress support when no total is given
21
+ * Add :bar_format option to allow selecting preconfigured bar displays
22
+ * Add :eta_time format token to display the estimated time of day at completion
23
+ * Add measurement of the total elapsed time that ignores stopped time intervals
24
+ * Add #pause to prevent bar from continuing progression and suspend time measurements
25
+ * Add Multi#pause to allow suspending progression of all registered bars at once
26
+ * Add Multi#resume to start again all registered bars that are stopped or paused
27
+ * Add Timer class to handle the total elapsed time measurements
28
+
29
+ ### Changed
30
+ * Change Multi#stopped? to check that all bars are stopped
31
+ * Change gemspec to load version directly and remove test artifacts
32
+ * Change to update strings-ansi and tty-screen dependencies
33
+ * Change Pipeline to inject progress bar instance only once
34
+ * Change :elapsed and :eta to show days after running for 24 hours
35
+ * Change to ensure complete, incomplete and unknown option cannot be an empty string
36
+ * Change to allow setting total to nil via accessor
37
+ * Change gemspec to allow version 2.0 of unicode-display_width dependency
38
+ * Change #stop to show hidden cursor after render similar to #finish
39
+
40
+ ### Fixed
41
+ * Fix MultiBar top bar to allow resuming progress when stopped/done (@d4be4st)
42
+ * Fix MultiBar to only set width when top bar present
43
+
44
+ ## [v0.17.0] - 2019-05-31
45
+
46
+ ### Changed
47
+ * Change gemspec to load files directly without git
48
+ * Change to update tty-cursor and tty-screen dependencies
49
+
50
+ ## [v0.16.0] - 2018-08-27
51
+
52
+ ### Added
53
+ * Add strings-ansi dependency
54
+
55
+ ### Changed
56
+ * Change tty-cursor dependency version
57
+
58
+ ### Fixed
59
+ * Fix to handle ANSI codes in bar formatting to allow correct size calculation
60
+
3
61
  ## [v0.15.1] - 2018-07-19
4
62
 
5
63
  ### Fixed
@@ -184,6 +242,11 @@
184
242
 
185
243
  * Initial implementation and release
186
244
 
245
+ [v0.18.2]: https://github.com/piotrmurach/tty-progressbar/compare/v0.18.1...v0.18.2
246
+ [v0.18.1]: https://github.com/piotrmurach/tty-progressbar/compare/v0.18.0...v0.18.1
247
+ [v0.18.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.17.0...v0.18.0
248
+ [v0.17.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.16.0...v0.17.0
249
+ [v0.16.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.15.1...v0.16.0
187
250
  [v0.15.1]: https://github.com/piotrmurach/tty-progressbar/compare/v0.15.0...v0.15.1
188
251
  [v0.15.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.14.0...v0.15.0
189
252
  [v0.14.0]: https://github.com/piotrmurach/tty-progressbar/compare/v0.13.0...v0.14.0
data/LICENSE.txt CHANGED
@@ -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,7 +1,11 @@
1
+ <div align="center">
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
+ </div>
4
+
1
5
  # TTY::ProgressBar [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
2
6
 
3
7
  [![Gem Version](https://badge.fury.io/rb/tty-progressbar.svg)][gem]
4
- [![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]
5
9
  [![Build status](https://ci.appveyor.com/api/projects/status/w3jafjeatt1ulufa?svg=true)][appveyor]
6
10
  [![Maintainability](https://api.codeclimate.com/v1/badges/e85416137d2057169575/maintainability)][codeclimate]
7
11
  [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-progressbar/badge.svg)][coverage]
@@ -9,41 +13,46 @@
9
13
 
10
14
  [gitter]: https://gitter.im/piotrmurach/tty
11
15
  [gem]: http://badge.fury.io/rb/tty-progressbar
12
- [travis]: http://travis-ci.org/piotrmurach/tty-progressbar
16
+ [gh_actions_ci]: https://github.com/piotrmurach/tty-progressbar/actions?query=workflow%3ACI
13
17
  [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-progressbar
14
18
  [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-progressbar/maintainability
15
19
  [coverage]: https://coveralls.io/github/piotrmurach/tty-progressbar
16
20
  [inchpages]: http://inch-ci.org/github/piotrmurach/tty-progressbar
17
21
 
18
- > A flexible progress bars drawing in terminal emulators.
22
+ > A flexible and extensible progress bar for terminal applications.
19
23
 
20
- **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.
21
25
 
22
26
  ## Features
23
27
 
24
- * Fully [configurable](#3-configuration)
25
- * Extremely flexible progress display [formatting](#4-formatting)
26
- * Includes many predefined tokens to calculate ETA, Bytes ... [tokens](#41-tokens)
27
- * Allows to define your [custom tokens](#42-custom-formatters)
28
- * Supports parallel multi progress bars [multi](#6-ttyprogressbarmulti-api)
29
- * Handles Unicode characters in progress bar [unicode](#44-unicode)
30
- * 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.
31
36
 
32
37
  ## Installation
33
38
 
34
39
  Add this line to your application's Gemfile:
35
40
 
36
41
  ```ruby
37
- gem 'tty-progressbar'
42
+ gem "tty-progressbar"
38
43
  ```
39
44
 
40
45
  And then execute:
41
46
 
42
- $ bundle
47
+ ```
48
+ $ bundle
49
+ ```
43
50
 
44
51
  Or install it yourself as:
45
52
 
46
- $ gem install tty-progressbar
53
+ ```
54
+ $ gem install tty-progressbar
55
+ ```
47
56
 
48
57
  ## Contents
49
58
 
@@ -58,15 +67,29 @@ Or install it yourself as:
58
67
  * [2.7 update](#27-update)
59
68
  * [2.8 finish](#28-finish)
60
69
  * [2.9 stop](#29-stop)
61
- * [2.10 reset](#210-reset)
62
- * [2.11 complete?](#211-complete)
63
- * [2.12 resize](#212-resize)
64
- * [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)
65
79
  * [3. Configuration](#3-configuration)
66
- * [3.1 :head](#31-head)
67
- * [3.2 :output](#32-output)
68
- * [3.3 :frequency](#33-frequency)
69
- * [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)
70
93
  * [4. Formatting](#4-formatting)
71
94
  * [4.1 Tokens](#41-tokens)
72
95
  * [4.2 Custom Formatters](#42-custom-formatters)
@@ -80,40 +103,63 @@ Or install it yourself as:
80
103
  * [6.4 start](#64-start)
81
104
  * [6.5 finish](#65-finish)
82
105
  * [6.6 stop](#66-stop)
83
- * [6.7 complete?](#67-complete)
84
- * [6.8 on](#68-on)
85
- * [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)
86
113
  * [7. Examples](#7-examples)
87
114
  * [7.1 Color](#71-color)
88
115
  * [7.2 Speed](#72-speed)
89
116
 
90
117
  ## 1. Usage
91
118
 
92
- **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:
93
120
 
94
121
  ```ruby
95
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
96
128
  30.times do
97
129
  sleep(0.1)
98
- bar.advance(1)
130
+ bar.advance # by default increases by 1
99
131
  end
100
132
  ```
101
133
 
102
- This would produce animation in your terminal:
134
+ This would produce the following animation in your terminal:
103
135
 
104
136
  ```ruby
105
137
  # downloading [======================= ]
106
138
  ```
107
139
 
108
- 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:
109
151
 
110
152
  ```ruby
111
153
  bars = TTY::ProgressBar::Multi.new("main [:bar] :percent")
112
154
 
113
155
  bar1 = bars.register("one [:bar] :percent", total: 15)
114
156
  bar2 = bars.register("two [:bar] :percent", total: 15)
157
+ ```
115
158
 
116
- bars.start
159
+ Then progress the child bars in parallel:
160
+
161
+ ```ruby
162
+ bars.start # starts all registered bars timers
117
163
 
118
164
  th1 = Thread.new { 15.times { sleep(0.1); bar1.advance } }
119
165
  th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
@@ -121,7 +167,7 @@ th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
121
167
  [th1, th2].each { |t| t.join }
122
168
  ```
123
169
 
124
- which will produce:
170
+ A possible terminal output may look like this:
125
171
 
126
172
  ```ruby
127
173
  # ┌ main [=============== ] 50%
@@ -133,10 +179,10 @@ which will produce:
133
179
 
134
180
  ### 2.1 advance
135
181
 
136
- 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:
137
183
 
138
184
  ```ruby
139
- bar.advance(1000)
185
+ bar.advance(1024)
140
186
  ```
141
187
 
142
188
  You can also pass negative steps if you wish to backtrack the progress:
@@ -145,13 +191,13 @@ You can also pass negative steps if you wish to backtrack the progress:
145
191
  bar.advance(-1)
146
192
  ```
147
193
 
148
- 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.
149
195
 
150
196
  ### 2.2 iterate
151
197
 
152
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.
153
199
 
154
- 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:
155
201
 
156
202
  ```ruby
157
203
  bar = TTY::ProgressBar.new("[:bar]")
@@ -163,7 +209,7 @@ Then, either directly iterate over a collection by yielding values to a block:
163
209
  bar.iterate(30.times) { |v| ... }
164
210
  ```
165
211
 
166
- or return an `Enumerator`:
212
+ Or return an `Enumerator`:
167
213
 
168
214
  ```ruby
169
215
  progress = bar.iterate(30.times)
@@ -191,7 +237,7 @@ downloader = Enumerator.new do |y|
191
237
  end
192
238
  ```
193
239
 
194
- 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:
195
241
 
196
242
  ```ruby
197
243
  bar = TTY::ProgressBar.new("[:bar]", total: content_size)
@@ -205,17 +251,17 @@ Please run [slow_process example](examples/slow_process.rb) to see this in actio
205
251
 
206
252
  ### 2.3 current=
207
253
 
208
- **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:
209
255
 
210
256
  ```ruby
211
257
  bar.current = 50
212
258
  ```
213
259
 
214
- 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.
215
261
 
216
262
  ### 2.4 ratio=
217
263
 
218
- 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:
219
265
 
220
266
  ```ruby
221
267
  bar.ratio = 0.5
@@ -223,13 +269,15 @@ bar.ratio = 0.5
223
269
 
224
270
  ### 2.5 width=
225
271
 
226
- 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:
227
275
 
228
276
  ```ruby
229
277
  bar.width = 20
230
278
  ```
231
279
 
232
- or with configuration options:
280
+ Or with configuration options:
233
281
 
234
282
  ```ruby
235
283
  bar = TTY::ProgressBar.new("[:bar]", width: 20)
@@ -237,7 +285,7 @@ bar = TTY::ProgressBar.new("[:bar]", width: 20)
237
285
 
238
286
  ### 2.6 start
239
287
 
240
- 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:
241
289
 
242
290
  ```ruby
243
291
  bar.start # => sets timer and draws initial progress bar
@@ -245,15 +293,15 @@ bar.start # => sets timer and draws initial progress bar
245
293
 
246
294
  ### 2.7 update
247
295
 
248
- 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`:
249
297
 
250
298
  ```ruby
251
- bar.update(complete: '+', frequency: 10)
299
+ bar.update(complete: "+", frequency: 10)
252
300
  ```
253
301
 
254
302
  ### 2.8 finish
255
303
 
256
- 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.
257
305
 
258
306
  ```ruby
259
307
  bar.finish
@@ -261,13 +309,23 @@ bar.finish
261
309
 
262
310
  ### 2.9 stop
263
311
 
264
- 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`:
265
313
 
266
314
  ```ruby
267
315
  bar.stop
268
316
  ```
269
317
 
270
- ### 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
271
329
 
272
330
  In order to reset currently running or finished progress bar to its original configuration and initial position use `reset` like so:
273
331
 
@@ -275,23 +333,57 @@ In order to reset currently running or finished progress bar to its original con
275
333
  bar.reset
276
334
  ```
277
335
 
278
- 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.
279
347
 
280
- ### 2.11 complete?
348
+ ### 2.13 complete?
281
349
 
282
- 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.
283
351
 
284
352
  ```ruby
285
353
  bar.complete? # => false
286
354
  ```
287
355
 
288
- ### 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?
373
+
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:
375
+
376
+ ```ruby
377
+ bar.indeterminate? # => false
378
+ ```
379
+
380
+ ### 2.17 resize
289
381
 
290
- 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.
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.
291
383
 
292
384
  ```ruby
293
- bar.resize # => determine terminal width and scale accordingly
294
- bar.resize(50) # => will resize bar proportionately from this point onwards
385
+ bar.resize # determine terminal width and scale accordingly
386
+ bar.resize(50) # will resize bar proportionately from this point onwards
295
387
  ```
296
388
 
297
389
  To handle automatic resizing you can trap `:WINCH` signal:
@@ -300,66 +392,229 @@ To handle automatic resizing you can trap `:WINCH` signal:
300
392
  trap(:WINCH) { bar.resize }
301
393
  ```
302
394
 
303
- ### 2.13 on
395
+ ### 2.18 on
304
396
 
305
- 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.
306
398
 
307
- 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:
308
400
 
309
401
  ```ruby
310
402
  bar.on(:progress) { |amount| ... }
311
403
  ```
312
404
 
313
- 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:
314
406
 
315
407
  ```ruby
316
408
  bar.on(:done) { ... }
317
409
  ```
318
410
 
319
- 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:
320
412
 
321
413
  ```ruby
322
414
  bar.on(:stopped) { ... }
323
415
  ```
324
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
+
325
423
  ## 3. Configuration
326
424
 
327
425
  There are number of configuration options that can be provided:
328
426
 
329
- * `:total` total number of steps to completion
330
- * `:width` of the bars display in terminal columns excluding formatting options. Defaults to total steps
331
- * `:complete` completion character by default `=`
332
- * `:incomplete` incomplete character by default single space
333
- * [:head](#31-head) the head character by default `=`
334
- * [:output](#32-output) the output stream defaulting to `stderr`
335
- * [:frequency](#33-frequency) used to throttle the output, by default `0`
336
- * [:interval](#34-interval) used to measure the speed, by default `1 sec`
337
- * `:hide_cursor` to hide display cursor defaulting to `false`
338
- * `: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`.
339
440
 
340
441
  All the above options can be passed in as hash options or block parameters:
341
442
 
342
443
  ```ruby
343
- TTY::ProgressBar.new "[:bar]" do |config|
444
+ bar = TTY::ProgressBar.new("[:bar]") do |config|
344
445
  config.total = 30
345
446
  config.frequency = 10
346
447
  config.clear = true
347
448
  end
348
449
  ```
349
450
 
350
- ### 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
351
521
 
352
522
  If you prefer for the animated bar to display a specific character for a head of progression then use `:head` option:
353
523
 
354
524
  ```ruby
355
- bar = TTY::ProressBar.new("[:bar]", head: '>')
356
- #
525
+ TTY::ProgressBar.new("[:bar]", head: ">")
526
+ ```
527
+
528
+ This could result in output like this:
529
+
530
+ ```ruby
357
531
  # [=======> ]
358
532
  ```
359
533
 
360
- ### 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.
543
+
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
361
616
 
362
- 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.
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.
363
618
 
364
619
  You can change where console output is streamed with `:output` option:
365
620
 
@@ -369,7 +624,7 @@ bar = TTY::ProgressBar.new(output: $stdout)
369
624
 
370
625
  The output stream defaults to `stderr`.
371
626
 
372
- ### 3.3 :frequency
627
+ ### 3.9 :frequency
373
628
 
374
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.
375
630
 
@@ -379,9 +634,9 @@ The `frequency` option accepts `integer` representing number of `Hz` units, for
379
634
  TTY::ProgressBar.new("[:bar]", total: 30, frequency: 10) # 10 Hz
380
635
  ```
381
636
 
382
- ### 3.4 :interval
637
+ ### 3.10 :interval
383
638
 
384
- 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.
385
640
 
386
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.
387
642
 
@@ -391,6 +646,55 @@ TTY::ProgressBar.new(":rate/minute", total: 100, interval: 60) # 1 minute
391
646
  TTY::ProgressBar.new(":rate/hour", total: 100, interval: 3600) # 1 hour
392
647
  ```
393
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
+
394
698
  ## 4. Formatting
395
699
 
396
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:
@@ -410,38 +714,55 @@ These are the tokens that are currently supported:
410
714
  * `:total_byte` the total progress in bytes
411
715
  * `:percent` the completion percentage
412
716
  * `:elapsed` the elapsed time in seconds
413
- * `: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
414
719
  * `:rate` the current rate of progression per second
415
- * `:byte_rate` the current rate of pregression in bytes per second
720
+ * `:byte_rate` the current rate of progression in bytes per second
416
721
  * `:mean_rate` the averaged rate of progression per second
417
722
  * `:mean_byte` the averaged rate of progression in bytes per second
418
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
+
419
736
  ### 4.2 Custom Formatters
420
737
 
421
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.
422
739
 
423
- 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:
424
741
 
425
742
  ```ruby
426
743
  class TimeFormatter
427
- def initialize(progress)
428
- @progress = progress # current progress bar instance
429
- end
744
+ include TTY::ProgressBar::Formatter[/:time/i]
745
+ ...
746
+ end
747
+ ```
430
748
 
431
- def matches?(value) # specify condition to match for in display string
432
- value.to_s =~ /:time/
433
- 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]
434
754
 
435
- def format(value) # specify how display string is formatted
436
- transformed = (Time.now - @progress.start_at).to_s
437
- 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
438
759
  end
439
760
  end
440
761
  ```
441
762
 
442
- 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.
443
764
 
444
- Create **TTY::ProgressBar** instance with new token:
765
+ Create **TTY::ProgressBar** instance using the new token:
445
766
 
446
767
  ```ruby
447
768
  bar = TTY::ProgressBar.new(":time", total: 30)
@@ -453,7 +774,7 @@ Then add `TimeFormatter` to the pipeline like so:
453
774
  bar.use TimeFormatter
454
775
  ```
455
776
 
456
- and then invoke progression:
777
+ Then invoke progression:
457
778
 
458
779
  ```ruby
459
780
  bar.advance
@@ -461,39 +782,47 @@ bar.advance
461
782
 
462
783
  ### 4.3 Custom Tokens
463
784
 
464
- 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:
465
786
 
466
787
  ```ruby
467
788
  bar = TTY::ProgressBar.new("(:current) :title", total: 4)
468
- bar.advance(title: 'Hello Piotr!')
469
- bar.advance(3, title: 'Bye Piotr!')
789
+ bar.advance(title: "Hello Piotr!")
790
+ bar.advance(3, title: "Bye Piotr!")
470
791
  ```
471
792
 
472
- which outputs:
793
+ This will output:
473
794
 
474
795
  ```ruby
475
- (1) Hello Piotr!
476
- (4) Bye Piotr!
796
+ # (1) Hello Piotr!
797
+ # (4) Bye Piotr!
477
798
  ```
478
799
 
479
800
  ### 4.4 Unicode
480
801
 
481
- The format string as well as `:complete`, `:head` and `:incompelte` 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.
482
803
 
483
804
  For example, you can specify complete bar progression character to be Unicode non-monospaced:
484
805
 
485
806
  ```ruby
486
- bar = TTY::ProgressBar.new("Unicode [:bar]", total: 30, complete: '')
487
- #
488
- # => 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 [あああああああああああああああ]
489
814
  ```
490
815
 
491
816
  Similarly, the formatted string can include Unicode characters:
492
817
 
493
818
  ```ruby
494
819
  bar = TTY::ProgressBar.new("あめかんむり[:bar]", total: 20)
495
- #
496
- # => あめかんむり[== ]
820
+ ```
821
+
822
+ A finished progress bar will also fit within allowed width:
823
+
824
+ ```ruby
825
+ # あめかんむり[== ]
497
826
  ```
498
827
 
499
828
  ## 5. Logging
@@ -501,11 +830,11 @@ bar = TTY::ProgressBar.new("あめかんむり[:bar]", total: 20)
501
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.
502
831
 
503
832
  ```ruby
504
- bar.log('Piotrrrrr')
833
+ bar.log("Piotrrrrr")
505
834
  bar.advance
506
835
  ```
507
836
 
508
- will result in:
837
+ This could result in the following output:
509
838
 
510
839
  ```ruby
511
840
  # Piotrrrrr
@@ -516,14 +845,13 @@ will result in:
516
845
 
517
846
  ### 6.1 new
518
847
 
519
- 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:
520
849
 
521
850
  ```ruby
522
851
  TTY::ProgressBar::Multi.new
523
852
  ```
524
853
 
525
-
526
- 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:
527
855
 
528
856
  ```ruby
529
857
  TTY::ProgressBar::Multi.new("main [:bar] :percent")
@@ -538,15 +866,15 @@ multibar = TTY::ProgressBar::Multi.new
538
866
  bar = multibar.register("[:bar]", total: 30)
539
867
  ```
540
868
 
541
- 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.
542
870
 
543
- 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.
544
872
 
545
873
  ### 6.3 advance
546
874
 
547
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.
548
876
 
549
- 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:
550
878
 
551
879
  ```ruby
552
880
  bar1 = multibar.register("one [:bar]", total: 20)
@@ -568,7 +896,7 @@ Finally, wait for the threads to finish:
568
896
 
569
897
  ### 6.4 start
570
898
 
571
- 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:
572
900
 
573
901
  ```ruby
574
902
  multibar.start # => sets timer and draws top level multi progress bar
@@ -576,7 +904,7 @@ multibar.start # => sets timer and draws top level multi progress bar
576
904
 
577
905
  ### 6.5 finish
578
906
 
579
- 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.
580
908
 
581
909
  ```ruby
582
910
  multibar.finish
@@ -590,7 +918,23 @@ Use `stop` to terminate immediately all progress bars registered with the multib
590
918
  multibar.stop
591
919
  ```
592
920
 
593
- ### 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?
594
938
 
595
939
  To check if all registered progress bars have been successfully finished use `complete?`
596
940
 
@@ -598,7 +942,23 @@ To check if all registered progress bars have been successfully finished use `co
598
942
  multibar.complete? # => true
599
943
  ```
600
944
 
601
- ### 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
602
962
 
603
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.
604
964
 
@@ -614,21 +974,27 @@ When all the registered progress bars finish and complete then the `:done` event
614
974
  multibar.on(:done) { ... }
615
975
  ```
616
976
 
617
- 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:
618
978
 
619
979
  ```ruby
620
980
  multibar.on(:stopped) { ... }
621
981
  ```
622
982
 
623
- ### 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
624
990
 
625
991
  In addition to all [configuration options](#3-configuration) you can style multi progress bar:
626
992
 
627
993
  ```ruby
628
994
  TTY::ProgressBar::Multi.new("[:bar]", style: {
629
- top: '. '
630
- middle: '|-> '
631
- bottom: '|__ '
995
+ top: ". ",
996
+ middle: "|-> ",
997
+ bottom: "|__ "
632
998
  })
633
999
  ```
634
1000
 
@@ -641,7 +1007,7 @@ This section demonstrates some of the possible uses for the **TTY::ProgressBar**
641
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:
642
1008
 
643
1009
  ```ruby
644
- require 'pastel'
1010
+ require "pastel"
645
1011
 
646
1012
  pastel = Pastel.new
647
1013
  green = pastel.on_green(" ")
@@ -694,6 +1060,10 @@ This will result in output similar to:
694
1060
 
695
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.
696
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
+
697
1067
  ## Copyright
698
1068
 
699
- Copyright (c) 2014-2018 Piotr Murach. See LICENSE for further details.
1069
+ Copyright (c) 2014 Piotr Murach. See LICENSE for further details.