each_with_anim 0.1.3
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +6 -0
- data/anim.gif +0 -0
- data/anim_change.gif +0 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/each_with_anim.gemspec +33 -0
- data/lib/each_with_anim/version.rb +3 -0
- data/lib/each_with_anim.rb +36 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9a6e695f901511bf908374fbefb93eab72cce12
|
4
|
+
data.tar.gz: cd4da316383ba995682d18a0637544bb6509c688
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac00acf4a403b87d4727c6399b4060eed93da31e63e7d37ad2361ca6763d45f68d1ba3f53ce789ef4b979e469f6a5c26a60e96e5c0cbd31e7ce27635c8f378d7
|
7
|
+
data.tar.gz: 9c4a656d7fbdd2cca656355bb74afe27438c2c2ab7a9d24cab4cc586f60a536a7e9ed1656edabdc4dfb4af7e0aac0d2e75717dc136694e752e6f31891b5fedae
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 7rpn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# each_with_anim
|
2
|
+
|
3
|
+
RubyのCUI上でループ時のアニメーションが簡単に作れるメソッドです。<br>
|
4
|
+
ループが終了する予測時間も測定してくれます。
|
5
|
+
|
6
|
+
Each_with_anim is **easiest to make** progress bar and other **cool animations** in CUI.
|
7
|
+
|
8
|
+

|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
$ gem install each_with_anim
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
each_with_animは,アニメーションを表示する以外は基本的にeachと同じ振る舞いをします。<br>
|
17
|
+
Use "each_with_anim" like "each" method.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require "each_with_anim"
|
21
|
+
|
22
|
+
list = %w(hage hoge foo) * 1000
|
23
|
+
list.each_with_anim do |elem|
|
24
|
+
#something
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
もちろんwith_indexとかも使えます。<br>
|
29
|
+
あとeach_with_animationはeach_with_animのエイリアスになってます。ただ長いので非推奨。<br>
|
30
|
+
also, if you want to use "with_index",
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
list = %w(hage hoge foo) * 1000
|
34
|
+
list.each_with_animation.with_index do |elem,i|
|
35
|
+
#something
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
同様に,引数を取ってアニメーションを変えることができます。今はまだ2つだけ。<br>
|
40
|
+
暇なときに増やして行きます。<br>
|
41
|
+
if you want to change animation,
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
list = %w(hage hoge foo) * 1000
|
45
|
+
list.each_with_anim(1) do |elem|
|
46
|
+
#something
|
47
|
+
end
|
48
|
+
```
|
49
|
+

|
50
|
+
|
51
|
+
|
52
|
+
## Problem
|
53
|
+
|
54
|
+
each_with_anim内でprintすると表示がバグります。<br>
|
55
|
+
解決策を絶賛探し中。
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
list = %w(hage hoge foo) * 10
|
59
|
+
list.each_with_anim do |elem|
|
60
|
+
puts "piyoo"
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/7rpn/each_with_anim. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
67
|
+
|
68
|
+
なんでもok<br>
|
69
|
+
すごい顔文字師がいたら助けてください笑
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
75
|
+
自由に使ってください。
|
data/Rakefile
ADDED
data/anim.gif
ADDED
Binary file
|
data/anim_change.gif
ADDED
Binary file
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "each_with_anim"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'each_with_anim/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "each_with_anim"
|
8
|
+
spec.version = EachWithAnim::VERSION
|
9
|
+
spec.authors = ["7rpn"]
|
10
|
+
spec.email = ["7rpn.deadlock@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Each_with_anim is easiest to make progress bar and other cool animations in CUI.}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/7rpn/each_with_anim"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "each_with_anim/version"
|
2
|
+
|
3
|
+
module Enumerable
|
4
|
+
def each_with_anim(kind=0)
|
5
|
+
return enum_for(__method__) unless block_given?
|
6
|
+
puts
|
7
|
+
array_size = self.length
|
8
|
+
@start_time, @before_size = Time.now, 0
|
9
|
+
self.each_with_index do |elem,i|
|
10
|
+
make_animation(i,array_size,kind)
|
11
|
+
yield elem
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method :each_with_animation, :each_with_anim
|
15
|
+
protected
|
16
|
+
def make_animation(i,array_size,kind)
|
17
|
+
left = "---"
|
18
|
+
now_time = Time.now
|
19
|
+
left = ((now_time- @start_time)*(array_size-i)*10.0/i).to_i/10.0 unless i == 0
|
20
|
+
bar_len = 200
|
21
|
+
now_len = (bar_len*(i+1))/array_size
|
22
|
+
char =
|
23
|
+
case kind
|
24
|
+
when 0 then (0x2588..0x258F).to_a.reverse.pack("U*")
|
25
|
+
when 1 then " " + (0x2581..0x2588).to_a.pack("U*")
|
26
|
+
when 2 then rand = Random.rand(8000);" " + (rand..(rand+8)).to_a.pack("U*");
|
27
|
+
end
|
28
|
+
bar = ("\u2588" * now_len.to_s(8)[0..-2].to_i(8)) + char[now_len.to_s(8)[-1].to_i]
|
29
|
+
bar = (bar+(" "*(bar_len/8-bar.size+1)))[0..-2]
|
30
|
+
parc = (1000*(i+1)/size)/10.0
|
31
|
+
str = "#{(" "*(6 - parc.to_s.size))+parc.to_s}%% |#{bar}| #{i+1}/#{size} left: #{left}sec."
|
32
|
+
printf (" "*@before_size)+"\e[#{@before_size}D"+str+"\e[#{str.size}D"
|
33
|
+
@before_size = str.size
|
34
|
+
puts if i+1 == size
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: each_with_anim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 7rpn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- 7rpn.deadlock@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- anim.gif
|
71
|
+
- anim_change.gif
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- each_with_anim.gemspec
|
75
|
+
- lib/each_with_anim.rb
|
76
|
+
- lib/each_with_anim/version.rb
|
77
|
+
homepage: https://github.com/7rpn/each_with_anim
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata:
|
81
|
+
allowed_push_host: https://rubygems.org
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Each_with_anim is easiest to make progress bar and other cool animations
|
102
|
+
in CUI.
|
103
|
+
test_files: []
|
104
|
+
has_rdoc:
|