lolize 0.0.1 → 0.0.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/Gemfile.lock +17 -0
- data/MIT-LICENSE +22 -0
- data/README.md +40 -0
- data/lib/lolize.rb +2 -47
- data/lib/lolize/auto.rb +5 -0
- data/lib/lolize/colorizer.rb +57 -0
- data/lib/lolize/version.rb +1 -1
- data/lolize.gemspec +1 -1
- metadata +15 -10
data/Gemfile.lock
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 miaout17
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Lolize
|
2
|
+
|
3
|
+
Colorize your ruby output with rainbow :)
|
4
|
+
|
5
|
+
The colorize algorithm is based on [lolcat](https://github.com/busyloop/lolcat).
|
6
|
+
|
7
|
+
## How to lolize
|
8
|
+
|
9
|
+
In your ruby code/irb:
|
10
|
+
|
11
|
+
gem 'lolize'
|
12
|
+
require 'lolize/auto'
|
13
|
+
|
14
|
+
Bundler Gemfile:
|
15
|
+
|
16
|
+
gem 'lolize', :require => 'lolize/auto'
|
17
|
+
|
18
|
+
## Why lolize
|
19
|
+
|
20
|
+
Why ask? Just for fun LOL.
|
21
|
+
|
22
|
+
## Why not pipe with lolcat?
|
23
|
+
|
24
|
+
If you try this:
|
25
|
+
|
26
|
+
rails c 2>&1 | lolcat
|
27
|
+
|
28
|
+
You will find that the last line won't be displayed forever.
|
29
|
+
|
30
|
+
After some googling, I think it need
|
31
|
+
|
32
|
+
## Caution
|
33
|
+
|
34
|
+
* This is just a fun project
|
35
|
+
* If something gets wrong within output hook, the program might crash silently
|
36
|
+
* Never use this in your production project!!!!
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
MIT License
|
data/lib/lolize.rb
CHANGED
@@ -1,47 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
module Lolize
|
4
|
-
def self.write(s)
|
5
|
-
s.lines.each_with_index do |line, index|
|
6
|
-
lol_write(line)
|
7
|
-
raw_write("\n") if line.length>0 && line[-1].chr=="\n"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.lol_write(s)
|
12
|
-
@opts ||= {
|
13
|
-
:animate => false,
|
14
|
-
:duration => 12,
|
15
|
-
:os => 0,
|
16
|
-
:speed => 20,
|
17
|
-
:spread => 8.0,
|
18
|
-
:freq => 0.3
|
19
|
-
}
|
20
|
-
@opts[:os] += 1
|
21
|
-
Lol.send(:println, s.dup, {}, @opts)
|
22
|
-
end
|
23
|
-
def self.raw_write(s)
|
24
|
-
$stdout.raw_write(s)
|
25
|
-
end
|
26
|
-
def self.lolize(output)
|
27
|
-
class << output
|
28
|
-
alias :raw_write :write
|
29
|
-
def write(s)
|
30
|
-
Lolize.write(s)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module Lol
|
37
|
-
def self.puts(s='')
|
38
|
-
# Lolize.raw_write("#{s}\n")
|
39
|
-
end
|
40
|
-
def self.print(s)
|
41
|
-
Lolize.raw_write(s)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
Lolize.lolize($stdout)
|
46
|
-
Lolize.lolize($stderr)
|
47
|
-
|
1
|
+
require 'lolize/version'
|
2
|
+
require 'lolize/colorizer'
|
data/lib/lolize/auto.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'paint'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module Lolize
|
5
|
+
class Colorizer
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def self.lolize(output)
|
9
|
+
class << output
|
10
|
+
alias :raw_write :write
|
11
|
+
def write(s)
|
12
|
+
::Lolize::Colorizer.instance.write(s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@freq = 0.3
|
19
|
+
@spread = 8.0
|
20
|
+
@line_color = 0
|
21
|
+
@color = 0
|
22
|
+
|
23
|
+
@state = :normal
|
24
|
+
end
|
25
|
+
|
26
|
+
def rainbow
|
27
|
+
red = Math.sin(@freq*@color + 0) * 127 + 128
|
28
|
+
green = Math.sin(@freq*@color + 2*Math::PI/3) * 127 + 128
|
29
|
+
blue = Math.sin(@freq*@color + 4*Math::PI/3) * 127 + 128
|
30
|
+
@color += 1/@spread
|
31
|
+
"#%02X%02X%02X" % [ red, green, blue ]
|
32
|
+
end
|
33
|
+
|
34
|
+
def write(s)
|
35
|
+
s.each_char do |c|
|
36
|
+
case @state
|
37
|
+
when :normal
|
38
|
+
if c=="\e"
|
39
|
+
@state = :ansi
|
40
|
+
elsif c=="\n"
|
41
|
+
@line_color += 1
|
42
|
+
@color = @line_color
|
43
|
+
raw_write(c)
|
44
|
+
else
|
45
|
+
raw_write(Paint[c, rainbow])
|
46
|
+
end
|
47
|
+
when :ansi
|
48
|
+
@state = :normal if c=='m'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def raw_write(s)
|
54
|
+
$stdout.raw_write(s)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/lolize/version.rb
CHANGED
data/lolize.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- miaout17
|
@@ -15,23 +15,23 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-27 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: paint
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 57
|
30
30
|
segments:
|
31
|
-
- 42
|
32
31
|
- 0
|
33
|
-
-
|
34
|
-
|
32
|
+
- 8
|
33
|
+
- 3
|
34
|
+
version: 0.8.3
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
description: Colorize your ruby stdout with Lolcat
|
@@ -46,8 +46,13 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- .gitignore
|
48
48
|
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- MIT-LICENSE
|
51
|
+
- README.md
|
49
52
|
- Rakefile
|
50
53
|
- lib/lolize.rb
|
54
|
+
- lib/lolize/auto.rb
|
55
|
+
- lib/lolize/colorizer.rb
|
51
56
|
- lib/lolize/version.rb
|
52
57
|
- lolize.gemspec
|
53
58
|
has_rdoc: true
|