indicator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +9 -0
- data/lib/indicator/spin.rb +46 -0
- data/lib/indicator/version.rb +3 -0
- data/lib/indicator.rb +28 -0
- metadata +65 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= Indicator
|
2
|
+
Display activity with ASCII spinners and progress indicators.
|
3
|
+
|
4
|
+
= Description
|
5
|
+
Sometimes you need to display activity on the text console to inform the user that the
|
6
|
+
program is actually doing something. Be funny with a lot predefined sets or make you own
|
7
|
+
widget to display a animation text during a long-running process in your console app.
|
8
|
+
|
9
|
+
|
10
|
+
=Installation
|
11
|
+
* From the command line.
|
12
|
+
* Type gem install indicator
|
13
|
+
* Using Gemfile.
|
14
|
+
(1) Add to your application Gemfile
|
15
|
+
|
16
|
+
gem 'indicator'
|
17
|
+
|
18
|
+
(2) Type
|
19
|
+
|
20
|
+
bundle install
|
21
|
+
|
22
|
+
=Usage
|
23
|
+
Simply and fast
|
24
|
+
|
25
|
+
Indicator::spin do
|
26
|
+
10.times do
|
27
|
+
sleep 0.5
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module CharTree
|
3
|
+
class Spin
|
4
|
+
attr_accessor :pre, :post, :delay
|
5
|
+
|
6
|
+
def initialize opts={}
|
7
|
+
@frames = opts[:frames] || %w{ | / - \\ }
|
8
|
+
@delay = opts[:delay] || 0.1
|
9
|
+
@pre = opts[:pre] || ''
|
10
|
+
@post = opts[:post] || ''
|
11
|
+
@count = opts[:count] || nil
|
12
|
+
init
|
13
|
+
end
|
14
|
+
|
15
|
+
def init
|
16
|
+
@current = 0
|
17
|
+
@spin = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def inc
|
21
|
+
@current += 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def spinning
|
25
|
+
build
|
26
|
+
printf @spin
|
27
|
+
sleep @delay if @delay
|
28
|
+
clear
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear
|
32
|
+
printf "\b" * @spin.length
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def build
|
37
|
+
@spin = @pre
|
38
|
+
@spin += @frames[0]
|
39
|
+
@frames.push @frames.shift
|
40
|
+
@spin += sprintf(" %3.2f%%", @count * 100.0 / @current) if @count
|
41
|
+
@spin += @post
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/lib/indicator.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../indicator/spin', __FILE__)
|
2
|
+
|
3
|
+
module Indicator
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def spinner
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def spin spin = CharTree::Spin.new, opts={}, &blk
|
11
|
+
ondemand = opts[:ondemand] || false
|
12
|
+
noclear = opts[:noclear] || false
|
13
|
+
|
14
|
+
if ondemand
|
15
|
+
|
16
|
+
else
|
17
|
+
t = Thread.new { yield }
|
18
|
+
|
19
|
+
while t.alive?
|
20
|
+
spin.spinning
|
21
|
+
end
|
22
|
+
|
23
|
+
t.join
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: indicator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Miguel Adolfo Barroso
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &16080760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.7.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *16080760
|
25
|
+
description: Sometimes you need to display activity on the text console to inform
|
26
|
+
the user that the program is actually doing something. Be funny with a lot predefined
|
27
|
+
sets or make you own widget to display a animation text during a long-running process
|
28
|
+
in your console app.
|
29
|
+
email:
|
30
|
+
- mabarroso@mabarroso.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/indicator/version.rb
|
36
|
+
- lib/indicator/spin.rb
|
37
|
+
- lib/indicator.rb
|
38
|
+
- MIT-LICENSE
|
39
|
+
- Rakefile
|
40
|
+
- README.rdoc
|
41
|
+
homepage: http://github.com/mabarroso/indicator
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Display activity with ASCII spinners and progress indicators.
|
65
|
+
test_files: []
|