spinning_cursor 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/TODO +5 -0
- data/VERSION +1 -1
- data/lib/spinning_cursor.rb +53 -25
- data/lib/spinning_cursor/cursor.rb +1 -1
- data/spinning_cursor.gemspec +3 -3
- data/test/test_exceptions.rb +17 -1
- data/test/test_spinning_cursor.rb +1 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Beautifully keep your users informed with what your program is doing when a
|
|
7
7
|
more complex solution, such as a progress bar, doesn't fit your needs.
|
8
8
|
|
9
9
|
Inspired by Chris Wanstrath's
|
10
|
-
[Choice](
|
10
|
+
[Choice](https://github.com/defunkt/choice), Spinning Cursor provides
|
11
11
|
you with a _sexy_ DSL for easy use of the library.
|
12
12
|
|
13
13
|
## Installation
|
@@ -51,9 +51,9 @@ It's as easy as that!
|
|
51
51
|
### Options
|
52
52
|
|
53
53
|
* `banner` - This displays before the cursor. Defaults to "Loading".
|
54
|
-
* `type` - The type of
|
54
|
+
* `type` - The type of cursor (currently only `:dots` and `:spinner`).
|
55
55
|
Defaults to `:spinner`.
|
56
|
-
* `action` - The stuff you want to do whilst the
|
56
|
+
* `action` - The stuff you want to do whilst the cursor is spinning.
|
57
57
|
* `message` - The message you want to show the user once the task is finished.
|
58
58
|
Defaults to "Done".
|
59
59
|
|
@@ -111,7 +111,7 @@ You get the message. (see what I did there?)
|
|
111
111
|
|
112
112
|
### I need to change the banner message during the task
|
113
113
|
|
114
|
-
Yay! All you need is the new version of the gem (
|
114
|
+
Yay! All you need is the new version of the gem (v0.1.0) and you can change
|
115
115
|
the banner message in the same way you would the finish message, using
|
116
116
|
`set_banner`:
|
117
117
|
|
data/TODO
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/spinning_cursor.rb
CHANGED
@@ -10,27 +10,28 @@ module SpinningCursor
|
|
10
10
|
# thread if an action block is passed.
|
11
11
|
#
|
12
12
|
def start(&block)
|
13
|
-
if
|
14
|
-
if
|
13
|
+
if not @curs.nil?
|
14
|
+
if @curs.alive?
|
15
15
|
stop
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
@parsed = Parser.new(block)
|
20
|
+
@cursor = Cursor.new(@parsed.banner nil)
|
21
|
+
@curs = Thread.new { @cursor.spin(@parsed.type nil) }
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
if @@parsed.action.nil?
|
23
|
+
if @parsed.action.nil?
|
24
|
+
# record start time
|
25
|
+
do_exec_time
|
27
26
|
return
|
28
27
|
end
|
29
28
|
# The action
|
30
29
|
begin
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
do_exec_time do
|
31
|
+
@parsed.originator.instance_eval &@parsed.action
|
32
|
+
end
|
33
|
+
rescue Exception => e
|
34
|
+
set_message "#{e.message}\n#{e.backtrace.join("\n")}"
|
34
35
|
ensure
|
35
36
|
return stop
|
36
37
|
end
|
@@ -42,12 +43,17 @@ module SpinningCursor
|
|
42
43
|
#
|
43
44
|
def stop
|
44
45
|
begin
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
@curs.kill
|
47
|
+
# Wait for the cursor to die -- can cause problems otherwise
|
48
|
+
while @curs.alive? ; end
|
49
|
+
# Set cursor to nil so set_banner method only works
|
50
|
+
# when cursor is actually running.
|
51
|
+
@cursor = nil
|
49
52
|
reset_line
|
50
|
-
puts (
|
53
|
+
puts (@parsed.message nil)
|
54
|
+
# Set parsed to nil so set_message method only works
|
55
|
+
# when cursor is actually running.
|
56
|
+
@parsed = nil
|
51
57
|
|
52
58
|
# Return execution time
|
53
59
|
get_exec_time
|
@@ -60,10 +66,10 @@ module SpinningCursor
|
|
60
66
|
# Determines whether the cursor thread is still running
|
61
67
|
#
|
62
68
|
def alive?
|
63
|
-
if
|
69
|
+
if @curs.nil?
|
64
70
|
return false
|
65
71
|
else
|
66
|
-
|
72
|
+
@curs.alive?
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|
@@ -73,7 +79,7 @@ module SpinningCursor
|
|
73
79
|
#
|
74
80
|
def set_message(msg)
|
75
81
|
begin
|
76
|
-
|
82
|
+
@parsed.message msg
|
77
83
|
rescue NameError
|
78
84
|
raise CursorNotRunning.new "Cursor isn't running... are you sure " +
|
79
85
|
"you're calling this from an action block?"
|
@@ -85,7 +91,7 @@ module SpinningCursor
|
|
85
91
|
#
|
86
92
|
def set_banner(banner)
|
87
93
|
begin
|
88
|
-
|
94
|
+
@cursor.banner = banner
|
89
95
|
rescue NameError
|
90
96
|
raise CursorNotRunning.new "Cursor isn't running... are you sure " +
|
91
97
|
"you're calling this from an action block?"
|
@@ -96,14 +102,36 @@ module SpinningCursor
|
|
96
102
|
# Retrieves execution time information
|
97
103
|
#
|
98
104
|
def get_exec_time
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
105
|
+
if not @start.nil?
|
106
|
+
if @finish.nil? && @curs.alive? == false
|
107
|
+
do_exec_time
|
108
|
+
end
|
109
|
+
return { :started => @start, :finished => @finish,
|
110
|
+
:elapsed => @elapsed }
|
111
|
+
else
|
103
112
|
raise NoTaskError.new "An execution hasn't started or finished."
|
104
113
|
end
|
105
114
|
end
|
106
115
|
|
116
|
+
private
|
117
|
+
|
118
|
+
#
|
119
|
+
# Takes a block, and returns the start, finish and elapsed times
|
120
|
+
#
|
121
|
+
def do_exec_time
|
122
|
+
if @curs.alive?
|
123
|
+
@start = Time.now
|
124
|
+
if block_given?
|
125
|
+
yield
|
126
|
+
@finish = Time.now
|
127
|
+
@elapsed = @finish - @start
|
128
|
+
end
|
129
|
+
else
|
130
|
+
@finish = Time.now
|
131
|
+
@elapsed = @finish - @start
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
107
135
|
class NoTaskError < Exception ; end
|
108
136
|
class CursorNotRunning < NoTaskError ; end
|
109
137
|
end
|
@@ -23,7 +23,7 @@ module SpinningCursor
|
|
23
23
|
attr_accessor :banner
|
24
24
|
|
25
25
|
#
|
26
|
-
# As of v0.1.0: only initializes the cursor class, use the
|
26
|
+
# As of v0.1.0: only initializes the cursor class, use the spin
|
27
27
|
# method to start the printing. Takes only the banner argument as
|
28
28
|
# a result of this.
|
29
29
|
#
|
data/spinning_cursor.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "spinning_cursor"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adnan Abdulhussein"]
|
12
|
-
s.date = "2012-04-
|
12
|
+
s.date = "2012-04-25"
|
13
13
|
s.description = "Spinning Cursor is a flexible DSL that allows you to easily produce a customizable waiting/loading message for your Ruby command line program. Beautifully keep your users informed with what your program is doing when a more complex solution, such as a progress bar, doesn't fit your needs."
|
14
14
|
s.email = "adnan@prydoni.us"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.homepage = "http://github.com/Prydonius/spinning_cursor"
|
42
42
|
s.licenses = ["MIT"]
|
43
43
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = "1.8.
|
44
|
+
s.rubygems_version = "1.8.23"
|
45
45
|
s.summary = "A DSL for adding animated loaders to your Ruby command line application."
|
46
46
|
|
47
47
|
if s.respond_to? :specification_version then
|
data/test/test_exceptions.rb
CHANGED
@@ -17,10 +17,26 @@ class TestSpinningCursor < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
should "raise NoTaskError when getting execution time if no task ran" do
|
20
|
+
should "a) raise NoTaskError when getting execution time if no task ran" do
|
21
21
|
assert_raise SpinningCursor::NoTaskError do
|
22
22
|
SpinningCursor.get_exec_time
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
should "raise CursorNotRunning errors when cursor has run and finished" do
|
27
|
+
SpinningCursor.start
|
28
|
+
SpinningCursor.stop
|
29
|
+
assert_raise SpinningCursor::CursorNotRunning do
|
30
|
+
SpinningCursor.set_message "Hi!"
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_raise SpinningCursor::CursorNotRunning do
|
34
|
+
SpinningCursor.set_banner "Hi!"
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_raise SpinningCursor::CursorNotRunning do
|
38
|
+
SpinningCursor.stop
|
39
|
+
end
|
40
|
+
end
|
25
41
|
end
|
26
42
|
end
|
@@ -9,7 +9,6 @@ class TestSpinningCursor < Test::Unit::TestCase
|
|
9
9
|
action { sleep 1 }
|
10
10
|
end
|
11
11
|
# Give it some time to abort
|
12
|
-
sleep 0.1
|
13
12
|
assert_equal false, SpinningCursor.alive?
|
14
13
|
end
|
15
14
|
end
|
@@ -63,7 +62,7 @@ class TestSpinningCursor < Test::Unit::TestCase
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
assert_equal true, (out.string.
|
65
|
+
assert_equal true, (out.string.include? "An exception!")
|
67
66
|
end
|
68
67
|
end
|
69
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spinning_cursor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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-04-
|
12
|
+
date: 2012-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
segments:
|
155
155
|
- 0
|
156
|
-
hash:
|
156
|
+
hash: 1437049553814384370
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
none: false
|
159
159
|
requirements:
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
164
|
rubyforge_project:
|
165
|
-
rubygems_version: 1.8.
|
165
|
+
rubygems_version: 1.8.23
|
166
166
|
signing_key:
|
167
167
|
specification_version: 3
|
168
168
|
summary: A DSL for adding animated loaders to your Ruby command line application.
|