lolize 0.0.2 → 0.0.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.
- data/.travis.yml +9 -0
- data/Gemfile.lock +3 -1
- data/README.md +34 -6
- data/Rakefile +11 -0
- data/lib/lolize.rb +5 -0
- data/lib/lolize/auto.rb +2 -2
- data/lib/lolize/colorizer.rb +13 -10
- data/lib/lolize/hooker.rb +12 -0
- data/lib/lolize/version.rb +1 -1
- data/lolize.gemspec +1 -0
- metadata +19 -3
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lolize (0.0.
|
4
|
+
lolize (0.0.3)
|
5
5
|
paint (~> 0.8.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
paint (0.8.3)
|
11
|
+
rake (0.9.2)
|
11
12
|
|
12
13
|
PLATFORMS
|
13
14
|
ruby
|
@@ -15,3 +16,4 @@ PLATFORMS
|
|
15
16
|
DEPENDENCIES
|
16
17
|
lolize!
|
17
18
|
paint (~> 0.8.3)
|
19
|
+
rake
|
data/README.md
CHANGED
@@ -4,16 +4,43 @@ Colorize your ruby output with rainbow :)
|
|
4
4
|
|
5
5
|
The colorize algorithm is based on [lolcat](https://github.com/busyloop/lolcat).
|
6
6
|
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install lolize
|
10
|
+
|
11
|
+
You need 256-color terminal for best experience.
|
12
|
+
|
7
13
|
## How to lolize
|
8
14
|
|
9
|
-
|
15
|
+
Just require `lolize/auto`. it will automatically hook your `$stdout` and `$stderr`.
|
16
|
+
|
17
|
+
### Bundler Gemfile
|
18
|
+
|
19
|
+
For example, you can do this in your rails project:
|
20
|
+
|
21
|
+
# Gemfile
|
22
|
+
gem 'lolize', :require => 'lolize/auto'
|
23
|
+
|
24
|
+

|
25
|
+
|
26
|
+
### Any Ruby, anywhere
|
27
|
+
|
28
|
+
Here is the snippet:
|
10
29
|
|
11
30
|
gem 'lolize'
|
12
31
|
require 'lolize/auto'
|
13
32
|
|
14
|
-
|
33
|
+
You can even do this in your compass `config.rb`:
|
15
34
|
|
16
|
-
|
35
|
+

|
36
|
+
|
37
|
+
## Don't colorize everything please
|
38
|
+
|
39
|
+
gem 'lolize'
|
40
|
+
require 'lolize'
|
41
|
+
colorizer = Lolize::Colorizer.new
|
42
|
+
colorizer.write "Hello, World\n"*5
|
43
|
+
puts "I AM WHITE" # This is clean
|
17
44
|
|
18
45
|
## Why lolize
|
19
46
|
|
@@ -26,15 +53,16 @@ If you try this:
|
|
26
53
|
rails c 2>&1 | lolcat
|
27
54
|
|
28
55
|
You will find that the last line won't be displayed forever.
|
29
|
-
|
30
|
-
After some googling, I think it need
|
56
|
+
It seems hard to solve this problem, some platform-dependent C-extension is needed.
|
31
57
|
|
32
58
|
## Caution
|
33
59
|
|
34
60
|
* This is just a fun project
|
35
|
-
* If something gets wrong within output hook, the program might crash silently
|
36
61
|
* Never use this in your production project!!!!
|
62
|
+
* It will slow your console output
|
63
|
+
* If something gets wrong within output hook, the program might crash silently
|
37
64
|
|
38
65
|
## License
|
39
66
|
|
40
67
|
MIT License
|
68
|
+
|
data/Rakefile
CHANGED
@@ -1,2 +1,13 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
task :default do
|
5
|
+
# A very simple "DONT CRASH TEST", I just want to ensure this won't crash the program
|
6
|
+
require 'lolize'
|
7
|
+
colorizer = Lolize::Colorizer.new
|
8
|
+
colorizer.write "*****\n"*5
|
9
|
+
|
10
|
+
5.times { puts "*"*5 }
|
11
|
+
require 'lolize/auto'
|
12
|
+
5.times { puts "*"*5 }
|
13
|
+
end
|
data/lib/lolize.rb
CHANGED
data/lib/lolize/auto.rb
CHANGED
data/lib/lolize/colorizer.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'paint'
|
2
|
-
require 'singleton'
|
3
2
|
|
4
3
|
module Lolize
|
5
4
|
class Colorizer
|
6
|
-
include Singleton
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
::Lolize::Colorizer.instance.write(s)
|
13
|
-
end
|
14
|
-
end
|
6
|
+
RAW_WRITE_METHOD = :write_without_lolize
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
@instance ||= Lolize::Colorizer.new
|
15
10
|
end
|
16
11
|
|
17
12
|
def initialize
|
@@ -23,6 +18,8 @@ module Lolize
|
|
23
18
|
@state = :normal
|
24
19
|
end
|
25
20
|
|
21
|
+
# The algorithm is from lolcat (https://github.com/busyloop/lolcat)
|
22
|
+
# lolcat is released with WTFPL
|
26
23
|
def rainbow
|
27
24
|
red = Math.sin(@freq*@color + 0) * 127 + 128
|
28
25
|
green = Math.sin(@freq*@color + 2*Math::PI/3) * 127 + 128
|
@@ -51,7 +48,13 @@ module Lolize
|
|
51
48
|
end
|
52
49
|
|
53
50
|
def raw_write(s)
|
54
|
-
$stdout.
|
51
|
+
if $stdout.respond_to?(RAW_WRITE_METHOD)
|
52
|
+
# if $stdout is hook
|
53
|
+
$stdout.send(RAW_WRITE_METHOD, s)
|
54
|
+
else
|
55
|
+
# $stdout is not hooked
|
56
|
+
$stdout.write(s)
|
57
|
+
end
|
55
58
|
end
|
56
59
|
end
|
57
60
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- miaout17
|
@@ -34,6 +34,20 @@ dependencies:
|
|
34
34
|
version: 0.8.3
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
37
51
|
description: Colorize your ruby stdout with Lolcat
|
38
52
|
email:
|
39
53
|
- miaout17@gmail.com
|
@@ -45,6 +59,7 @@ extra_rdoc_files: []
|
|
45
59
|
|
46
60
|
files:
|
47
61
|
- .gitignore
|
62
|
+
- .travis.yml
|
48
63
|
- Gemfile
|
49
64
|
- Gemfile.lock
|
50
65
|
- MIT-LICENSE
|
@@ -53,6 +68,7 @@ files:
|
|
53
68
|
- lib/lolize.rb
|
54
69
|
- lib/lolize/auto.rb
|
55
70
|
- lib/lolize/colorizer.rb
|
71
|
+
- lib/lolize/hooker.rb
|
56
72
|
- lib/lolize/version.rb
|
57
73
|
- lolize.gemspec
|
58
74
|
has_rdoc: true
|