randrews-spinner 1.1.2
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/spinner.rb +62 -0
- metadata +53 -0
data/spinner.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# To demo in irb:
|
|
2
|
+
# load 'spinner.rb' ; include Spinner ; spinner_demo
|
|
3
|
+
#
|
|
4
|
+
# To use, include this module in a class and then wrap something in with_spinner
|
|
5
|
+
# It has two params, both optional. See spinner_demo for usage examples.
|
|
6
|
+
|
|
7
|
+
module Spinner
|
|
8
|
+
def with_spinner total=nil, message="Working...", &blk
|
|
9
|
+
current=0
|
|
10
|
+
shown=buildstr(message,current,total)
|
|
11
|
+
printf(shown)
|
|
12
|
+
|
|
13
|
+
spin=Proc.new do
|
|
14
|
+
clear(shown)
|
|
15
|
+
current+=1
|
|
16
|
+
shown=buildstr(message,current,total)
|
|
17
|
+
printf(shown)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
yield spin
|
|
21
|
+
|
|
22
|
+
clear(shown)
|
|
23
|
+
printf(" "*shown.length)
|
|
24
|
+
clear(shown)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def spinner_demo max=100
|
|
28
|
+
with_spinner max do |spin|
|
|
29
|
+
(1..max).each do |n|
|
|
30
|
+
spin.call
|
|
31
|
+
sleep 0.05
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
with_spinner nil, "No percentage..." do |spin|
|
|
36
|
+
(1..max).each do |n|
|
|
37
|
+
spin.call
|
|
38
|
+
sleep 0.05
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def clear str
|
|
47
|
+
printf("\b"*str.length)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def buildstr message, current, total
|
|
51
|
+
str="#{char(current)} #{message}"
|
|
52
|
+
if total
|
|
53
|
+
percent=(current*100.0/total)
|
|
54
|
+
str+= sprintf(" %3.2f%%",percent)
|
|
55
|
+
end
|
|
56
|
+
str
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def char n
|
|
60
|
+
%w{/ - \\ |}[n%4]
|
|
61
|
+
end
|
|
62
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: randrews-spinner
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ross Andrews
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-07-02 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Spinner is a Ruby library for displaying an animated spinner during long-running tasks.
|
|
17
|
+
email: randrews@geekfu.org
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- spinner.rb
|
|
26
|
+
has_rdoc: false
|
|
27
|
+
homepage: http://github.com/randrews/spinner
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: "0"
|
|
38
|
+
version:
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: "0"
|
|
44
|
+
version:
|
|
45
|
+
requirements: []
|
|
46
|
+
|
|
47
|
+
rubyforge_project: spinner
|
|
48
|
+
rubygems_version: 1.2.0
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 2
|
|
51
|
+
summary: Spinner is a Ruby library for displaying an animated spinner during long-running tasks.
|
|
52
|
+
test_files: []
|
|
53
|
+
|