shell-spinner 1.0.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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.markdown +42 -0
- data/Rakefile +1 -0
- data/lib/shell-spinner.rb +52 -0
- data/lib/shell-spinner/version.rb +3 -0
- data/shell-spinner.gemspec +18 -0
- metadata +64 -0
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Shell Spinner
|
2
|
+
|
3
|
+
Gem provides animated spinner for UNIX shell and could be used with rake tasks and any console scripts.
|
4
|
+
It basically wraps any code and show spinner until code isn't completed.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install shell-spinner
|
9
|
+
|
10
|
+
In Rails 3, add this to your Gemfile and run the bundle command.
|
11
|
+
|
12
|
+
gem "shell-spinner"
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
The main gem function ```ShellSpinner``` accepts text string as first argument,
|
17
|
+
which is not required, but it's better to have it for pretty output.
|
18
|
+
And it accepts block of code. So spinner will be presented while block is running.
|
19
|
+
|
20
|
+
require 'shell-spinner'
|
21
|
+
|
22
|
+
# With message
|
23
|
+
ShellSpinner "Positive result" do
|
24
|
+
Rake::Task["foo:bar"].invoke
|
25
|
+
end
|
26
|
+
|
27
|
+
# Spinner without message
|
28
|
+
ShellSpinner do
|
29
|
+
sleep 1
|
30
|
+
end
|
31
|
+
|
32
|
+
# With exception
|
33
|
+
ShellSpinner "Code with exception" do
|
34
|
+
sleep 2
|
35
|
+
raise "Some exception"
|
36
|
+
end
|
37
|
+
|
38
|
+
This code produces output similar to:
|
39
|
+
|
40
|
+
> Positive result... done
|
41
|
+
> Code with exception... fail
|
42
|
+
> <exception message and backtrace>
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "shell-spinner/version"
|
2
|
+
|
3
|
+
module ShellSpinner
|
4
|
+
|
5
|
+
def self.wrap text = nil, &block
|
6
|
+
with_message text do
|
7
|
+
join_spinner_thread(block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.with_message text = nil
|
14
|
+
require 'colorize'
|
15
|
+
|
16
|
+
begin
|
17
|
+
print "#{text}... " unless text.nil?
|
18
|
+
yield
|
19
|
+
print "done\n".colorize(:green) unless text.nil?
|
20
|
+
rescue Exception => e
|
21
|
+
print "fail\n".colorize(:red) unless text.nil?
|
22
|
+
re_raise_exception e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.join_spinner_thread proc
|
27
|
+
chars = %w{ | / - \\ }
|
28
|
+
thread = Thread.new { proc.call }
|
29
|
+
|
30
|
+
while thread.alive?
|
31
|
+
print chars[0]
|
32
|
+
sleep 0.1
|
33
|
+
print "\b"
|
34
|
+
|
35
|
+
chars.push chars.shift
|
36
|
+
end
|
37
|
+
|
38
|
+
thread.join
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.re_raise_exception e
|
42
|
+
raise begin
|
43
|
+
e.class.new(e.message).tap do |exception|
|
44
|
+
exception.set_backtrace e.backtrace
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def ShellSpinner text = nil, &block
|
51
|
+
ShellSpinner.wrap text, &block
|
52
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "shell-spinner/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "shell-spinner"
|
7
|
+
s.version = ShellSpinner::VERSION
|
8
|
+
s.authors = ["Ivan Garmatenko"]
|
9
|
+
s.email = %w(cheef.che@gmail.ru)
|
10
|
+
s.homepage = "https://github.com/cheef/shell-spinner"
|
11
|
+
s.summary = %q{Animated spinner for shell}
|
12
|
+
s.description = %q{Gem provides animated spinner for UNIX shell and could be used with rake tasks and any console scripts}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_paths = %w(lib)
|
16
|
+
|
17
|
+
s.add_runtime_dependency "colorize"
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shell-spinner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ivan Garmatenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: &84013340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *84013340
|
25
|
+
description: Gem provides animated spinner for UNIX shell and could be used with rake
|
26
|
+
tasks and any console scripts
|
27
|
+
email:
|
28
|
+
- cheef.che@gmail.ru
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- README.markdown
|
36
|
+
- Rakefile
|
37
|
+
- lib/shell-spinner.rb
|
38
|
+
- lib/shell-spinner/version.rb
|
39
|
+
- shell-spinner.gemspec
|
40
|
+
homepage: https://github.com/cheef/shell-spinner
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.10
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Animated spinner for shell
|
64
|
+
test_files: []
|