tty-spinner 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +132 -0
- data/Rakefile +8 -0
- data/examples/basic.rb +9 -0
- data/lib/tty-spinner.rb +1 -0
- data/lib/tty/spinner.rb +134 -0
- data/lib/tty/spinner/formats.rb +18 -0
- data/lib/tty/spinner/version.rb +7 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/unit/hide_cursor_spec.rb +21 -0
- data/spec/unit/new_spec.rb +22 -0
- data/spec/unit/reset_spec.rb +23 -0
- data/spec/unit/spin_spec.rb +46 -0
- data/spec/unit/stop_spec.rb +49 -0
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/spec.rake +29 -0
- data/tty-spinner.gemspec +23 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e2a6c489b56c8375abe0015bff1ac62ad9eb208
|
4
|
+
data.tar.gz: 69bb91f2cbc1781b7aae9126a306ffc942683aa2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0eef90653e7d511c3653668e08aa4728f2ea5a17225a7c60f31cad9c8059b340e00f1087cabf8e6343eea212a67fd8a7fe7cb5fc54268c0b8efd6c7511c2d7fe
|
7
|
+
data.tar.gz: e8e97d5647daee951fe742431deddfa785c0c490a0fa04d08f00dde7c25cf70497ddb6d2ece86a53eeda0c2bab17fc406f78bfb8c6ecd851d11e4ce2f0bac36a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without yard benchmarks
|
3
|
+
script: "bundle exec rake ci"
|
4
|
+
rvm:
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1.0
|
8
|
+
- ruby-head
|
9
|
+
matrix:
|
10
|
+
include:
|
11
|
+
- rvm: jruby-19mode
|
12
|
+
- rvm: jruby-20mode
|
13
|
+
- rvm: jruby-21mode
|
14
|
+
- rvm: jruby-head
|
15
|
+
- rvm: rbx-2
|
16
|
+
allow_failures:
|
17
|
+
- rvm: ruby-head
|
18
|
+
- rvm: jruby-head
|
19
|
+
- rvm: jruby-19mode
|
20
|
+
- rvm: jruby-20mode
|
21
|
+
- rvm: jruby-21mode
|
22
|
+
fast_finish: true
|
23
|
+
branches:
|
24
|
+
only: master
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'rake', '~> 10.3.2'
|
7
|
+
gem 'rspec', '~> 3.1.0'
|
8
|
+
gem 'yard', '~> 0.8.7'
|
9
|
+
gem 'timecop', '~> 0.7.1'
|
10
|
+
gem 'pastel', '~> 0.3.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :metrics do
|
14
|
+
gem 'coveralls', '~> 0.7.0'
|
15
|
+
gem 'simplecov', '~> 0.8.2'
|
16
|
+
gem 'yardstick', '~> 0.9.9'
|
17
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Piotr Murach
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# TTY::Spinner
|
2
|
+
[][gem]
|
3
|
+
[][travis]
|
4
|
+
[][codeclimate]
|
5
|
+
[][coverage]
|
6
|
+
|
7
|
+
[gem]: http://badge.fury.io/rb/tty-spinner
|
8
|
+
[travis]: http://travis-ci.org/peter-murach/tty-spinner
|
9
|
+
[codeclimate]: https://codeclimate.com/github/peter-murach/tty-spinner
|
10
|
+
[coverage]: https://coveralls.io/r/peter-murach/tty-spinner
|
11
|
+
|
12
|
+
A terminal spinner for tasks that have non-deterministic time frame.
|
13
|
+
|
14
|
+
**TTY::Spinner** provides independent spinner component for [TTY](https://github.com/peter-murach/tty) toolkit.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'tty-spinner'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install tty-spinner
|
31
|
+
|
32
|
+
## Contents
|
33
|
+
|
34
|
+
* [1. Usage](#1-usage)
|
35
|
+
* [1.1 spin](#11-spin)
|
36
|
+
* [1.2 stop](#12-stop)
|
37
|
+
* [1.3 reset](#13-reset)
|
38
|
+
* [2. Configuration](#2-configuration)
|
39
|
+
* [3. Formatting](#3-formatting)
|
40
|
+
|
41
|
+
## 1. Usage
|
42
|
+
|
43
|
+
**TTY::ProgressBar** by default uses `:spin_1` type of formatter and requires no paramters:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
spinner = TTY::Spinner.new
|
47
|
+
```
|
48
|
+
|
49
|
+
In addition you can provide a message and format type you would like for the spinning display like so:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
spinner = TTY::Spinner.new('Loading ... ', format: :spin_2)
|
53
|
+
30.times do
|
54
|
+
spinner.spin
|
55
|
+
sleep(0.1)
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
This would product animation in your terminal:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
Loading ... ⎺
|
63
|
+
```
|
64
|
+
|
65
|
+
### 1.1 spin
|
66
|
+
|
67
|
+
The main workhorse of the spinner is the `spin` method. Looping over `spin` method will animate a given spinner.
|
68
|
+
|
69
|
+
### 1.2 stop
|
70
|
+
|
71
|
+
In order to stop the spinner call `stop`. This will finish drawing the spinning and return to new line.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
spinner.stop
|
75
|
+
```
|
76
|
+
|
77
|
+
You can further pass a stop message to print in place of spinning animation:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
spinner.stop('Done!')
|
81
|
+
```
|
82
|
+
|
83
|
+
which would produce for the above example the following:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
Loading ... Done!
|
87
|
+
```
|
88
|
+
|
89
|
+
### 1.3 reset
|
90
|
+
|
91
|
+
In order to reset the spinner to its initial frame do:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
spinner.reset
|
95
|
+
```
|
96
|
+
|
97
|
+
## 2. Configuration
|
98
|
+
|
99
|
+
There are number of configuration options that can be provided:
|
100
|
+
|
101
|
+
* `format` the formatting token (see [Formatting](#3-formatting))
|
102
|
+
* `output` the output stream defaulting to `stderr`
|
103
|
+
* `hide_cursor` to hide display cursor defaulting to `false`
|
104
|
+
|
105
|
+
## 3. Formatting
|
106
|
+
|
107
|
+
**TTY::Spinner** supports the following formatting for its spinners:
|
108
|
+
|
109
|
+
| Type | Animation |
|
110
|
+
| -------- | ----------- |
|
111
|
+
| :spin_1 | |
|
112
|
+
| :spin_2 | |
|
113
|
+
| :spin_3 | |
|
114
|
+
| :spin_4 | |
|
115
|
+
| :spin_5 | |
|
116
|
+
| :spin_6 | |
|
117
|
+
| :spin_7 | |
|
118
|
+
| :spin_8 | |
|
119
|
+
| :spin_9 | |
|
120
|
+
| :spin_10 | |
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
1. Fork it ( https://github.com/peter-murach/tty-spinner/fork )
|
125
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
126
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
127
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
128
|
+
5. Create a new Pull Request
|
129
|
+
|
130
|
+
## Copyright
|
131
|
+
|
132
|
+
Copyright (c) 2014 Piotr Murach. See LICENSE for further details.
|
data/Rakefile
ADDED
data/examples/basic.rb
ADDED
data/lib/tty-spinner.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tty/spinner'
|
data/lib/tty/spinner.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'tty/spinner/version'
|
4
|
+
require 'tty/spinner/formats'
|
5
|
+
|
6
|
+
module TTY
|
7
|
+
# Used for creating terminal spinner
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class Spinner
|
11
|
+
include Formats
|
12
|
+
ECMA_ESC = "\x1b"
|
13
|
+
ECMA_CSI = "\x1b["
|
14
|
+
ECMA_CHA = 'G'
|
15
|
+
|
16
|
+
DEC_RST = 'l'
|
17
|
+
DEC_SET = 'h'
|
18
|
+
DEC_TCEM = '?25'
|
19
|
+
|
20
|
+
# The object that responds to print call defaulting to stderr
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
attr_reader :output
|
24
|
+
|
25
|
+
# The current format type
|
26
|
+
#
|
27
|
+
# @return [String]
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
attr_reader :format
|
31
|
+
|
32
|
+
# Whether to show or hide cursor
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
attr_reader :hide_cursor
|
38
|
+
|
39
|
+
# The message to print before the spinner
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
# the current message
|
43
|
+
#
|
44
|
+
# @api public
|
45
|
+
attr_reader :message
|
46
|
+
|
47
|
+
# Initialize a spinner
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# spinner = TTY::Spinner.new
|
51
|
+
#
|
52
|
+
# @param [String] message
|
53
|
+
# the message to print in front of the spinner
|
54
|
+
#
|
55
|
+
# @param [Hash] options
|
56
|
+
# @option options [String] :format
|
57
|
+
# the spinner format type defaulting to :spin_1
|
58
|
+
# @option options [Object] :output
|
59
|
+
# the object that responds to print call defaulting to stderr
|
60
|
+
# @option options [Boolean] :hide_cursor
|
61
|
+
# display or hide cursor
|
62
|
+
#
|
63
|
+
# @api public
|
64
|
+
def initialize(*args)
|
65
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
66
|
+
@message = args.empty? ? '' : args.pop
|
67
|
+
|
68
|
+
@format = options.fetch(:format) { :spin_1 }
|
69
|
+
@output = options.fetch(:output) { $stderr }
|
70
|
+
@hide_cursor = options.fetch(:hide_cursor) { false }
|
71
|
+
|
72
|
+
@frames = FORMATS[@format.to_sym]
|
73
|
+
@length = @frames.length
|
74
|
+
@current = 0
|
75
|
+
@done = false
|
76
|
+
@spinning = false
|
77
|
+
end
|
78
|
+
|
79
|
+
# Perform a spin
|
80
|
+
#
|
81
|
+
# @return [String]
|
82
|
+
# the printed data
|
83
|
+
#
|
84
|
+
# @api public
|
85
|
+
def spin
|
86
|
+
return if @done
|
87
|
+
|
88
|
+
if @hide_cursor && !@spinning
|
89
|
+
write(ECMA_CSI + DEC_TCEM + DEC_RST)
|
90
|
+
end
|
91
|
+
|
92
|
+
data = message + @frames[@current]
|
93
|
+
write(data, true)
|
94
|
+
@current = (@current + 1) % @length
|
95
|
+
@spinning = true
|
96
|
+
data
|
97
|
+
end
|
98
|
+
|
99
|
+
# Finish spining
|
100
|
+
#
|
101
|
+
# @param [String] stop_message
|
102
|
+
# the stop message to print
|
103
|
+
#
|
104
|
+
# @api public
|
105
|
+
def stop(stop_message = '')
|
106
|
+
if @hide_cursor && @spinning
|
107
|
+
write(ECMA_CSI + DEC_TCEM + DEC_SET, false)
|
108
|
+
end
|
109
|
+
@done = true
|
110
|
+
return if message.empty? && stop_message.empty?
|
111
|
+
write(message + stop_message, true)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Reset the spinner to initial frame
|
115
|
+
#
|
116
|
+
# @api public
|
117
|
+
def reset
|
118
|
+
@current = 0
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
# Write data out to output
|
124
|
+
#
|
125
|
+
# @return [nil]
|
126
|
+
#
|
127
|
+
# @api private
|
128
|
+
def write(data, clear_first = false)
|
129
|
+
output.print(ECMA_CSI + '1' + ECMA_CHA) if clear_first
|
130
|
+
output.print(data)
|
131
|
+
output.flush
|
132
|
+
end
|
133
|
+
end # Spinner
|
134
|
+
end # TTY
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
module Formats
|
5
|
+
FORMATS = {
|
6
|
+
spin_1: "|/-\\",
|
7
|
+
spin_2: '⎺⎻⎼⎽⎼⎻',
|
8
|
+
spin_3: '◴◷◶◵',
|
9
|
+
spin_4: '◐◓◑◒',
|
10
|
+
spin_5: '◰◳◲◱',
|
11
|
+
spin_6: '▉▊▋▌▍▎▏▎▍▌▋▊▉',
|
12
|
+
spin_7: '▌▄▐▀',
|
13
|
+
spin_8: '■□▪▫',
|
14
|
+
spin_9: '←↑→↓',
|
15
|
+
spin_10: '╫╪'
|
16
|
+
}
|
17
|
+
end # Formats
|
18
|
+
end # TTY
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
|
4
|
+
require 'simplecov'
|
5
|
+
require 'coveralls'
|
6
|
+
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
Coveralls::SimpleCov::Formatter
|
10
|
+
]
|
11
|
+
|
12
|
+
SimpleCov.start do
|
13
|
+
command_name 'spec'
|
14
|
+
add_filter 'spec'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'tty-spinner'
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
+
end
|
24
|
+
|
25
|
+
config.mock_with :rspec do |mocks|
|
26
|
+
mocks.verify_partial_doubles = true
|
27
|
+
end
|
28
|
+
|
29
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
30
|
+
config.disable_monkey_patching!
|
31
|
+
|
32
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
33
|
+
# be too noisy due to issues in dependencies.
|
34
|
+
config.warnings = true
|
35
|
+
|
36
|
+
if config.files_to_run.one?
|
37
|
+
config.default_formatter = 'doc'
|
38
|
+
end
|
39
|
+
|
40
|
+
config.profile_examples = 2
|
41
|
+
|
42
|
+
config.order = :random
|
43
|
+
|
44
|
+
Kernel.srand config.seed
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Spinner, 'hide_cursor' do
|
6
|
+
let(:output) { StringIO.new('', 'w+') }
|
7
|
+
|
8
|
+
it "hides cursor" do
|
9
|
+
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
10
|
+
4.times { spinner.spin }
|
11
|
+
spinner.stop
|
12
|
+
output.rewind
|
13
|
+
expect(output.read).to eq([
|
14
|
+
"\e[?25l\e[1G|",
|
15
|
+
"\e[1G/",
|
16
|
+
"\e[1G-",
|
17
|
+
"\e[1G\\",
|
18
|
+
"\e[?25h"
|
19
|
+
].join)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Spinner, '.new' do
|
6
|
+
|
7
|
+
it "creates spinner with default format" do
|
8
|
+
spinner = TTY::Spinner.new
|
9
|
+
expect(spinner.format).to eq(:spin_1)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "allows to pass message in" do
|
13
|
+
spinner = TTY::Spinner.new("Initializing...")
|
14
|
+
expect(spinner.message).to eq("Initializing...")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows to set default output" do
|
18
|
+
output = $stdout
|
19
|
+
spinner = TTY::Spinner.new(output: output)
|
20
|
+
expect(spinner.output).to eq(output)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Spinner, '.reset' do
|
6
|
+
let(:output) { StringIO.new('', 'w+') }
|
7
|
+
|
8
|
+
it "spins default frames" do
|
9
|
+
spinner = TTY::Spinner.new(output: output)
|
10
|
+
5.times do |n|
|
11
|
+
spinner.spin
|
12
|
+
spinner.reset if n == 2
|
13
|
+
end
|
14
|
+
output.rewind
|
15
|
+
expect(output.read).to eq([
|
16
|
+
"\e[1G|",
|
17
|
+
"\e[1G/",
|
18
|
+
"\e[1G-",
|
19
|
+
"\e[1G|",
|
20
|
+
"\e[1G/"
|
21
|
+
].join)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Spinner, '.spin' do
|
6
|
+
let(:output) { StringIO.new('', 'w+') }
|
7
|
+
|
8
|
+
it "spins default frames" do
|
9
|
+
spinner = TTY::Spinner.new(output: output)
|
10
|
+
5.times { spinner.spin }
|
11
|
+
output.rewind
|
12
|
+
expect(output.read).to eq([
|
13
|
+
"\e[1G|",
|
14
|
+
"\e[1G/",
|
15
|
+
"\e[1G-",
|
16
|
+
"\e[1G\\",
|
17
|
+
"\e[1G|"
|
18
|
+
].join)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "spins chosen frame" do
|
22
|
+
spinner = TTY::Spinner.new(output: output, format: :spin_3)
|
23
|
+
5.times { spinner.spin }
|
24
|
+
output.rewind
|
25
|
+
expect(output.read).to eq([
|
26
|
+
"\e[1G◴",
|
27
|
+
"\e[1G◷",
|
28
|
+
"\e[1G◶",
|
29
|
+
"\e[1G◵",
|
30
|
+
"\e[1G◴"
|
31
|
+
].join)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "spins with message" do
|
35
|
+
message = "Loading ... "
|
36
|
+
spinner = TTY::Spinner.new(message, output: output)
|
37
|
+
4.times { spinner.spin }
|
38
|
+
output.rewind
|
39
|
+
expect(output.read).to eq([
|
40
|
+
"\e[1G#{message}|",
|
41
|
+
"\e[1G#{message}/",
|
42
|
+
"\e[1G#{message}-",
|
43
|
+
"\e[1G#{message}\\"
|
44
|
+
].join)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Spinner, '.stop' do
|
6
|
+
let(:output) { StringIO.new('', 'w+') }
|
7
|
+
|
8
|
+
it "stops after 2 spins" do
|
9
|
+
spinner = TTY::Spinner.new(output: output)
|
10
|
+
5.times do |n|
|
11
|
+
spinner.spin
|
12
|
+
spinner.stop if n == 1
|
13
|
+
end
|
14
|
+
output.rewind
|
15
|
+
expect(output.read).to eq([
|
16
|
+
"\e[1G|",
|
17
|
+
"\e[1G/"
|
18
|
+
].join)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "stops after 2 spins and prints stop message" do
|
22
|
+
spinner = TTY::Spinner.new(output: output)
|
23
|
+
5.times do |n|
|
24
|
+
spinner.spin
|
25
|
+
spinner.stop('Done!') if n == 1
|
26
|
+
end
|
27
|
+
output.rewind
|
28
|
+
expect(output.read).to eq([
|
29
|
+
"\e[1G|",
|
30
|
+
"\e[1G/",
|
31
|
+
"\e[1GDone!"
|
32
|
+
].join)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "stops after 2 spins with message and prints stop message" do
|
36
|
+
message = "Loading ... "
|
37
|
+
spinner = TTY::Spinner.new(message, output: output)
|
38
|
+
5.times do |n|
|
39
|
+
spinner.spin
|
40
|
+
spinner.stop('Done!') if n == 1
|
41
|
+
end
|
42
|
+
output.rewind
|
43
|
+
expect(output.read).to eq([
|
44
|
+
"\e[1G#{message}|",
|
45
|
+
"\e[1G#{message}/",
|
46
|
+
"\e[1G#{message}Done!"
|
47
|
+
].join)
|
48
|
+
end
|
49
|
+
end
|
data/tasks/console.rake
ADDED
data/tasks/coverage.rake
ADDED
data/tasks/spec.rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
desc 'Run all specs'
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
+
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :spec do
|
12
|
+
desc 'Run unit specs'
|
13
|
+
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
+
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run integration specs'
|
18
|
+
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
+
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
rescue LoadError
|
24
|
+
%w[spec spec:unit spec:integration].each do |name|
|
25
|
+
task name do
|
26
|
+
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/tty-spinner.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tty/spinner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tty-spinner"
|
8
|
+
spec.version = TTY::Spinner::VERSION
|
9
|
+
spec.authors = ["Piotr Murach"]
|
10
|
+
spec.email = ["pmurach@gmail.com"]
|
11
|
+
spec.summary = %q{A terminal spinner for tasks that have non-deterministic time frame.}
|
12
|
+
spec.description = %q{A terminal spinner for tasks that have non-deterministic time frame.}
|
13
|
+
spec.homepage = "https://github.com/peter-murach/tty-spinner"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tty-spinner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Piotr Murach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: A terminal spinner for tasks that have non-deterministic time frame.
|
42
|
+
email:
|
43
|
+
- pmurach@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- .ruby-version
|
51
|
+
- .travis.yml
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- examples/basic.rb
|
57
|
+
- lib/tty-spinner.rb
|
58
|
+
- lib/tty/spinner.rb
|
59
|
+
- lib/tty/spinner/formats.rb
|
60
|
+
- lib/tty/spinner/version.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/unit/hide_cursor_spec.rb
|
63
|
+
- spec/unit/new_spec.rb
|
64
|
+
- spec/unit/reset_spec.rb
|
65
|
+
- spec/unit/spin_spec.rb
|
66
|
+
- spec/unit/stop_spec.rb
|
67
|
+
- tasks/console.rake
|
68
|
+
- tasks/coverage.rake
|
69
|
+
- tasks/spec.rake
|
70
|
+
- tty-spinner.gemspec
|
71
|
+
homepage: https://github.com/peter-murach/tty-spinner
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: A terminal spinner for tasks that have non-deterministic time frame.
|
95
|
+
test_files:
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/unit/hide_cursor_spec.rb
|
98
|
+
- spec/unit/new_spec.rb
|
99
|
+
- spec/unit/reset_spec.rb
|
100
|
+
- spec/unit/spin_spec.rb
|
101
|
+
- spec/unit/stop_spec.rb
|
102
|
+
has_rdoc:
|