shell-spinner 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.markdown → README.md} +0 -0
- data/lib/shell-spinner.rb +58 -36
- data/lib/shell-spinner/version.rb +1 -1
- metadata +4 -8
- data/.gitignore +0 -5
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/shell-spinner.gemspec +0 -18
File without changes
|
data/lib/shell-spinner.rb
CHANGED
@@ -2,58 +2,80 @@ require "shell-spinner/version"
|
|
2
2
|
|
3
3
|
module ShellSpinner
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class Runner
|
6
|
+
def initialize
|
7
|
+
require 'stringio'
|
8
|
+
@buffer, @original_output = StringIO.new, $stdout
|
8
9
|
end
|
9
|
-
end
|
10
10
|
|
11
|
-
|
11
|
+
def wrap_block text = nil, &block
|
12
|
+
with_message text do
|
13
|
+
with_spinner &block
|
14
|
+
end
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
require 'colorize'
|
17
|
+
private
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
def catch_user_output
|
20
|
+
$stdout = @buffer
|
18
21
|
yield
|
19
|
-
|
20
|
-
|
21
|
-
print "fail\n".colorize(:red) unless text.nil?
|
22
|
-
re_raise_exception e
|
22
|
+
ensure
|
23
|
+
$stdout = @original_output
|
23
24
|
end
|
24
|
-
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
thread = Thread.new { proc.call }
|
26
|
+
def with_message text = nil
|
27
|
+
require 'colorize'
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
begin
|
30
|
+
print "#{text}... " unless text.nil?
|
31
|
+
catch_user_output { yield }
|
32
|
+
print "done\n".colorize(:green) unless text.nil?
|
33
|
+
print user_output.colorize(:blue)
|
34
|
+
rescue Exception => e
|
35
|
+
print "fail\n".colorize(:red) unless text.nil?
|
36
|
+
print user_output.colorize(:blue)
|
37
|
+
re_raise_exception e
|
38
|
+
end
|
39
|
+
end
|
34
40
|
|
35
|
-
|
41
|
+
def user_output
|
42
|
+
@buffer.rewind
|
43
|
+
@buffer.read
|
36
44
|
end
|
37
45
|
|
38
|
-
|
39
|
-
|
46
|
+
def with_spinner
|
47
|
+
chars = %w{ | / - \\ }
|
48
|
+
thread = Thread.new { yield }
|
49
|
+
|
50
|
+
while thread.alive?
|
51
|
+
@original_output.print chars[0]
|
52
|
+
sleep 0.1
|
53
|
+
@original_output.print "\b"
|
40
54
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
new_exception
|
55
|
+
chars.push chars.shift
|
56
|
+
end
|
57
|
+
|
58
|
+
thread.join
|
46
59
|
end
|
47
|
-
end
|
48
60
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
61
|
+
def re_raise_exception e
|
62
|
+
raise begin
|
63
|
+
new_exception = build_new_exception(e)
|
64
|
+
new_exception.set_backtrace e.backtrace
|
65
|
+
new_exception
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Needs for cases when custom exceptions needs a several required arguments
|
70
|
+
def build_new_exception e
|
71
|
+
e.class.new(e.message)
|
72
|
+
rescue
|
73
|
+
Exception.new e.message
|
74
|
+
end
|
54
75
|
end
|
55
76
|
end
|
56
77
|
|
57
78
|
def ShellSpinner text = nil, &block
|
58
|
-
ShellSpinner.
|
79
|
+
runner = ShellSpinner::Runner.new
|
80
|
+
runner.wrap_block text, &block
|
59
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shell-spinner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -35,13 +35,9 @@ executables: []
|
|
35
35
|
extensions: []
|
36
36
|
extra_rdoc_files: []
|
37
37
|
files:
|
38
|
-
- .
|
39
|
-
- Gemfile
|
40
|
-
- README.markdown
|
41
|
-
- Rakefile
|
42
|
-
- lib/shell-spinner.rb
|
38
|
+
- README.md
|
43
39
|
- lib/shell-spinner/version.rb
|
44
|
-
- shell-spinner.
|
40
|
+
- lib/shell-spinner.rb
|
45
41
|
homepage: https://github.com/cheef/shell-spinner
|
46
42
|
licenses: []
|
47
43
|
post_install_message:
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/shell-spinner.gemspec
DELETED
@@ -1,18 +0,0 @@
|
|
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
|