indicator 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,23 +4,23 @@ Display activity with ASCII spinners and progress indicators.
4
4
  = Description
5
5
  Sometimes you need to display activity on the text console to inform the user that the
6
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.
7
+ widget to display an animation text during a long-running process in your console app.
8
8
 
9
9
 
10
10
  =Installation
11
- * From the command line.
12
- * Type gem install indicator
13
- * Using Gemfile.
14
- (1) Add to your application Gemfile
11
+ From the command line.
12
+ gem install indicator
15
13
 
16
- gem 'indicator'
14
+ Using Gemfile.
17
15
 
18
- (2) Type
16
+ 1 Add to your application Gemfile
17
+ gem 'indicator'
19
18
 
20
- bundle install
19
+ 2 Type
20
+ bundle install
21
21
 
22
22
  =Usage
23
- Simply and fast
23
+ Animated
24
24
 
25
25
  Indicator::spin do
26
26
  10.times do
@@ -28,4 +28,20 @@ Simply and fast
28
28
  end
29
29
  end
30
30
 
31
+ On demand update
31
32
 
33
+ Indicator::spin(:ondemand => true) do |spinner|
34
+ 10.times do
35
+ spinner.spinning
36
+ sleep 0.2
37
+ end
38
+ end
39
+
40
+ Manual control
41
+
42
+ spinner = Indicator.spinner
43
+ 10.times do
44
+ spinner.spinning
45
+ sleep 0.2
46
+ end
47
+ spinner.clean
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- module CharTree
2
+ module Indicator
3
3
  class Spin
4
4
  attr_accessor :pre, :post, :delay
5
5
 
@@ -14,7 +14,8 @@ module CharTree
14
14
 
15
15
  def init
16
16
  @current = 0
17
- @spin = false
17
+ @spin = ''
18
+ printf @spin
18
19
  end
19
20
 
20
21
  def inc
@@ -22,14 +23,18 @@ module CharTree
22
23
  end
23
24
 
24
25
  def spinning
26
+ spin
27
+ sleep @delay if @delay
28
+ end
29
+
30
+ def spin
31
+ clean
25
32
  build
26
33
  printf @spin
27
- sleep @delay if @delay
28
- clear
29
34
  end
30
35
 
31
- def clear
32
- printf "\b" * @spin.length
36
+ def clean
37
+ printf "\b" * @spin.length if @spin.length > 0
33
38
  end
34
39
 
35
40
  private
@@ -1,3 +1,3 @@
1
1
  module Indicator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/indicator.rb CHANGED
@@ -4,24 +4,27 @@ module Indicator
4
4
  class << self
5
5
 
6
6
  def spinner
7
-
7
+ Indicator::Spin.new
8
8
  end
9
9
 
10
- def spin spin = CharTree::Spin.new, opts={}, &blk
10
+ def spin opts={}, &blk
11
+ spinner = opts[:spinner] || self.spinner
12
+ noclean = opts[:noclean] || false
11
13
  ondemand = opts[:ondemand] || false
12
- noclear = opts[:noclear] || false
13
14
 
14
15
  if ondemand
15
-
16
+ yield spinner
16
17
  else
17
- t = Thread.new { yield }
18
+ t = Thread.new { yield spinner }
18
19
 
19
20
  while t.alive?
20
- spin.spinning
21
+ spinner.spinning
21
22
  end
22
23
 
23
24
  t.join
24
25
  end
26
+
27
+ spinner.clean unless noclean
25
28
  end
26
29
 
27
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &16080760 !ruby/object:Gem::Requirement
16
+ requirement: &7808580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.7.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *16080760
24
+ version_requirements: *7808580
25
25
  description: Sometimes you need to display activity on the text console to inform
26
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
27
+ sets or make you own widget to display an animation text during a long-running process
28
28
  in your console app.
29
29
  email:
30
30
  - mabarroso@mabarroso.com