lolize 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lolize (0.0.1)
5
+ paint (~> 0.8.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ paint (0.8.3)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ lolize!
17
+ paint (~> 0.8.3)
@@ -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.
@@ -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
@@ -1,47 +1,2 @@
1
- require 'lolcat'
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'
@@ -0,0 +1,5 @@
1
+ require 'lolize'
2
+
3
+ Lolize::Colorizer.lolize($stdout)
4
+ Lolize::Colorizer.lolize($stderr)
5
+
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Lolize
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'lolcat','42.0.99'
22
+ s.add_dependency 'paint', '~> 0.8.3'
23
23
  end
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-26 00:00:00 +08:00
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: lolcat
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: 393
29
+ hash: 57
30
30
  segments:
31
- - 42
32
31
  - 0
33
- - 99
34
- version: 42.0.99
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