unicolor 1.0.0

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 ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in unicolor.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 jugyo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ unicolor
2
+ ====
3
+
4
+ Colorize an object uniquely!
5
+
6
+ Install
7
+ ----
8
+
9
+ $ gem install unicolor
10
+
11
+ Usage
12
+ ----
13
+
14
+ Call Object#unicolor:
15
+
16
+ > require 'unicolor'
17
+ > "foo".unicolor
18
+ => "\e[31mfoo\e[0m"
19
+
20
+ Object#uc as alias:
21
+
22
+ > "foo".uc
23
+ => "\e[31mfoo\e[0m"
24
+
25
+ Change the theme
26
+ ----
27
+
28
+ > Unicolor.theme :bg
29
+ > "foo".uc
30
+ => "\e[41mfoo\e[0m"
31
+
32
+ Define a theme
33
+ ----
34
+
35
+ > Unicolor.define_theme :my_theme, (31..36).to_a
36
+
37
+ Standard themes
38
+ ----
39
+
40
+ Unicolor.define_theme :fg, (31..36).to_a + (91..96).to_a
41
+ Unicolor.define_theme :bg, (41..46).to_a + (101..106).to_a
42
+ Unicolor.define_theme :fg256, (1..255).map{|i| [38, 5, i]}
43
+ Unicolor.define_theme :bg256, (1..255).map{|i| [48, 5, i]}
44
+
45
+ Copyright
46
+ ----
47
+
48
+ Copyright (c) 2011 jugyo. See LICENSE.txt for further details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ require "unicolor/version"
2
+
3
+ module Unicolor
4
+ class << self
5
+ def theme(name = nil)
6
+ name ? @theme = name : @theme
7
+ end
8
+
9
+ def themes
10
+ @themes ||= {}
11
+ end
12
+
13
+ def define_theme(name, colors)
14
+ themes[name] = colors
15
+ end
16
+
17
+ def colors
18
+ themes[theme]
19
+ end
20
+
21
+ def colorize(str)
22
+ "\e[#{color_for(str)}m#{str}\e[0m"
23
+ end
24
+
25
+ def color_for(str)
26
+ result = colors[str.to_i(36) % colors.size]
27
+ result = [result].flatten
28
+ result.join(';')
29
+ end
30
+ end
31
+
32
+
33
+ def unicolor
34
+ Unicolor.colorize(self.to_s)
35
+ end
36
+ alias_method :uc, :unicolor
37
+ end
38
+
39
+ Object.send(:include, Unicolor)
40
+
41
+ Unicolor.define_theme :fg, (31..36).to_a + (91..96).to_a
42
+ Unicolor.define_theme :bg, (41..46).to_a + (101..106).to_a
43
+ Unicolor.define_theme :fg256, (1..255).map{|i| [38, 5, i]}
44
+ Unicolor.define_theme :bg256, (1..255).map{|i| [48, 5, i]}
45
+
46
+ Unicolor.theme :fg
@@ -0,0 +1,3 @@
1
+ module Unicolor
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "unicolor/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "unicolor"
7
+ s.version = Unicolor::VERSION
8
+ s.authors = ["jugyo"]
9
+ s.email = ["jugyo.org@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Colorize an object uniquely!}
12
+ s.description = %q{Colorize an object uniquely! Call Object#unicolor}
13
+
14
+ s.rubyforge_project = "unicolor"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unicolor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jugyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-11 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Colorize an object uniquely! Call Object#unicolor
15
+ email:
16
+ - jugyo.org@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - LICENCE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/unicolor.rb
26
+ - lib/unicolor/version.rb
27
+ - unicolor.gemspec
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: unicolor
48
+ rubygems_version: 1.8.11
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Colorize an object uniquely!
52
+ test_files: []