colorlib 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3794b8dfed2624aa20d320e9a4b92bcf67ca7861
4
+ data.tar.gz: 4f3ae2a94c75a217be4a17764c8c718006e5b1b5
5
+ SHA512:
6
+ metadata.gz: 8eb1b5e98a249a8407af6e62c80d1183ee5e6d7d3811e4e8195161bd554999685a960cc7ca7005cc2aef0da30fabf0708b1a1147c5f08e3884ebcfa436c7f973
7
+ data.tar.gz: cf0c6095a0ee40bee44114841582ea85920e718a36064dfc3d1f9e4d26354c29e3ff8bb5f6c9f71effc44960bdb7a1aa45d5023ac90f2344bbfd272054494b67
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in colorlib.gemspec
4
+ gemspec
@@ -0,0 +1,167 @@
1
+ Copyright (c) 2014 Kilobyte
2
+
3
+ GNU LESSER GENERAL PUBLIC LICENSE
4
+ Version 3, 29 June 2007
5
+
6
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+
11
+ This version of the GNU Lesser General Public License incorporates
12
+ the terms and conditions of version 3 of the GNU General Public
13
+ License, supplemented by the additional permissions listed below.
14
+
15
+ 0. Additional Definitions.
16
+
17
+ As used herein, "this License" refers to version 3 of the GNU Lesser
18
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
19
+ General Public License.
20
+
21
+ "The Library" refers to a covered work governed by this License,
22
+ other than an Application or a Combined Work as defined below.
23
+
24
+ An "Application" is any work that makes use of an interface provided
25
+ by the Library, but which is not otherwise based on the Library.
26
+ Defining a subclass of a class defined by the Library is deemed a mode
27
+ of using an interface provided by the Library.
28
+
29
+ A "Combined Work" is a work produced by combining or linking an
30
+ Application with the Library. The particular version of the Library
31
+ with which the Combined Work was made is also called the "Linked
32
+ Version".
33
+
34
+ The "Minimal Corresponding Source" for a Combined Work means the
35
+ Corresponding Source for the Combined Work, excluding any source code
36
+ for portions of the Combined Work that, considered in isolation, are
37
+ based on the Application, and not on the Linked Version.
38
+
39
+ The "Corresponding Application Code" for a Combined Work means the
40
+ object code and/or source code for the Application, including any data
41
+ and utility programs needed for reproducing the Combined Work from the
42
+ Application, but excluding the System Libraries of the Combined Work.
43
+
44
+ 1. Exception to Section 3 of the GNU GPL.
45
+
46
+ You may convey a covered work under sections 3 and 4 of this License
47
+ without being bound by section 3 of the GNU GPL.
48
+
49
+ 2. Conveying Modified Versions.
50
+
51
+ If you modify a copy of the Library, and, in your modifications, a
52
+ facility refers to a function or data to be supplied by an Application
53
+ that uses the facility (other than as an argument passed when the
54
+ facility is invoked), then you may convey a copy of the modified
55
+ version:
56
+
57
+ a) under this License, provided that you make a good faith effort to
58
+ ensure that, in the event an Application does not supply the
59
+ function or data, the facility still operates, and performs
60
+ whatever part of its purpose remains meaningful, or
61
+
62
+ b) under the GNU GPL, with none of the additional permissions of
63
+ this License applicable to that copy.
64
+
65
+ 3. Object Code Incorporating Material from Library Header Files.
66
+
67
+ The object code form of an Application may incorporate material from
68
+ a header file that is part of the Library. You may convey such object
69
+ code under terms of your choice, provided that, if the incorporated
70
+ material is not limited to numerical parameters, data structure
71
+ layouts and accessors, or small macros, inline functions and templates
72
+ (ten or fewer lines in length), you do both of the following:
73
+
74
+ a) Give prominent notice with each copy of the object code that the
75
+ Library is used in it and that the Library and its use are
76
+ covered by this License.
77
+
78
+ b) Accompany the object code with a copy of the GNU GPL and this license
79
+ document.
80
+
81
+ 4. Combined Works.
82
+
83
+ You may convey a Combined Work under terms of your choice that,
84
+ taken together, effectively do not restrict modification of the
85
+ portions of the Library contained in the Combined Work and reverse
86
+ engineering for debugging such modifications, if you also do each of
87
+ the following:
88
+
89
+ a) Give prominent notice with each copy of the Combined Work that
90
+ the Library is used in it and that the Library and its use are
91
+ covered by this License.
92
+
93
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
94
+ document.
95
+
96
+ c) For a Combined Work that displays copyright notices during
97
+ execution, include the copyright notice for the Library among
98
+ these notices, as well as a reference directing the user to the
99
+ copies of the GNU GPL and this license document.
100
+
101
+ d) Do one of the following:
102
+
103
+ 0) Convey the Minimal Corresponding Source under the terms of this
104
+ License, and the Corresponding Application Code in a form
105
+ suitable for, and under terms that permit, the user to
106
+ recombine or relink the Application with a modified version of
107
+ the Linked Version to produce a modified Combined Work, in the
108
+ manner specified by section 6 of the GNU GPL for conveying
109
+ Corresponding Source.
110
+
111
+ 1) Use a suitable shared library mechanism for linking with the
112
+ Library. A suitable mechanism is one that (a) uses at run time
113
+ a copy of the Library already present on the user's computer
114
+ system, and (b) will operate properly with a modified version
115
+ of the Library that is interface-compatible with the Linked
116
+ Version.
117
+
118
+ e) Provide Installation Information, but only if you would otherwise
119
+ be required to provide such information under section 6 of the
120
+ GNU GPL, and only to the extent that such information is
121
+ necessary to install and execute a modified version of the
122
+ Combined Work produced by recombining or relinking the
123
+ Application with a modified version of the Linked Version. (If
124
+ you use option 4d0, the Installation Information must accompany
125
+ the Minimal Corresponding Source and Corresponding Application
126
+ Code. If you use option 4d1, you must provide the Installation
127
+ Information in the manner specified by section 6 of the GNU GPL
128
+ for conveying Corresponding Source.)
129
+
130
+ 5. Combined Libraries.
131
+
132
+ You may place library facilities that are a work based on the
133
+ Library side by side in a single library together with other library
134
+ facilities that are not Applications and are not covered by this
135
+ License, and convey such a combined library under terms of your
136
+ choice, if you do both of the following:
137
+
138
+ a) Accompany the combined library with a copy of the same work based
139
+ on the Library, uncombined with any other library facilities,
140
+ conveyed under the terms of this License.
141
+
142
+ b) Give prominent notice with the combined library that part of it
143
+ is a work based on the Library, and explaining where to find the
144
+ accompanying uncombined form of the same work.
145
+
146
+ 6. Revised Versions of the GNU Lesser General Public License.
147
+
148
+ The Free Software Foundation may publish revised and/or new versions
149
+ of the GNU Lesser General Public License from time to time. Such new
150
+ versions will be similar in spirit to the present version, but may
151
+ differ in detail to address new problems or concerns.
152
+
153
+ Each version is given a distinguishing version number. If the
154
+ Library as you received it specifies that a certain numbered version
155
+ of the GNU Lesser General Public License "or any later version"
156
+ applies to it, you have the option of following the terms and
157
+ conditions either of that published version or of any later version
158
+ published by the Free Software Foundation. If the Library as you
159
+ received it does not specify a version number of the GNU Lesser
160
+ General Public License, you may choose any version of the GNU Lesser
161
+ General Public License ever published by the Free Software Foundation.
162
+
163
+ If the Library as you received it specifies that a proxy can decide
164
+ whether future versions of the GNU Lesser General Public License shall
165
+ apply, that proxy's public statement of acceptance of any version is
166
+ permanent authorization for you to choose that version for the
167
+ Library.
@@ -0,0 +1,29 @@
1
+ # Colorlib
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'colorlib'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install colorlib
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'colorlib/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'colorlib'
8
+ spec.version = Colorlib::VERSION
9
+ spec.authors = ['Kilobyte']
10
+ spec.email = ['root@kilobyte22.de']
11
+ spec.description = 'Allows to easily colorize strings for all kinds of usages'
12
+ spec.summary = 'Colorize strings, currently supported are irc and tty (latter not fully yet though)'
13
+ spec.homepage = '' # TODO: set to github repo
14
+ spec.license = 'LGPL'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,8 @@
1
+ require 'colorlib/version'
2
+ require 'colorlib/colored_string'
3
+ require 'colorlib/color_builder'
4
+ require 'colorlib/irc_color_proc'
5
+
6
+ module Colorlib
7
+
8
+ end
@@ -0,0 +1,15 @@
1
+ module Colorlib
2
+ class ColorAttribute
3
+
4
+ attr_accessor :color, :bold, :underline, :italic
5
+
6
+ def initialize
7
+ @color = :default
8
+ @bold = false
9
+ @underline = false
10
+ @italic = false
11
+ end
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'colorlib/colored_compound'
2
+
3
+ module Colorlib
4
+ class ColorBuilder < ColoredCompound
5
+
6
+ def color(string, color)
7
+ self << string.color(color)
8
+ end
9
+
10
+ def red(text); color text, :red; end
11
+ def green(text); color text, :green; end
12
+ def blue(text); color text, :blue; end
13
+ def yellow(text); color text, :yellow; end
14
+ def black(text); color text, :black; end
15
+ def white(text); color text, :white; end
16
+
17
+ alias :raw :append
18
+
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module Colorlib
2
+ class ColoredCompound
3
+
4
+ @@makers = {}
5
+
6
+ def initialize
7
+ @strings = []
8
+ end
9
+
10
+ def append(whatever)
11
+ @strings << whatever.is_a?(ColoredString) ? whatever : ColoredString.new(whatever.to_s)
12
+ self # to return it
13
+ end
14
+
15
+ alias :<< :append
16
+
17
+ def make(target)
18
+ unless (maker = @@makers[target])
19
+ raise 'Invalid Target'
20
+ end
21
+ prev = ColorAttribute.new
22
+ ret = ''
23
+ @strings.each do |string|
24
+ ret += maker.call string, prev
25
+ end
26
+ ret
27
+ end
28
+
29
+ def self.register_maker(type, &block)
30
+ @@makers[type] = block
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ require 'colorlib/color_attribute'
2
+
3
+ module Colorlib
4
+ class ColoredString
5
+
6
+ attr_reader :attrib
7
+
8
+ def initialize(string)
9
+ @string = string
10
+ @attrib = ColorAttribute.new
11
+ end
12
+
13
+ def color(color)
14
+ @attrib.color = color
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'colorlib/colored_compound'
2
+
3
+ module Colorlib
4
+ module IRC
5
+ COLORS = {
6
+ red: '04',
7
+ green: '03',
8
+ blue: '02',
9
+ yellow: '08',
10
+ black: '01',
11
+ white: '00'
12
+ }
13
+ end
14
+ end
15
+
16
+ Colorlib::ColoredCompound.register_maker :irc do |text, prev|
17
+ ret = ''
18
+ if prev.color != text.attrib.color
19
+ ret += "\003"
20
+ unless text.attrib.color == :default
21
+ ret += Colorlib::IRC::COLORS[text.attrib.colo]
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ class String
2
+
3
+ def color(color)
4
+ ret = Colorlib::ColoredString.new self
5
+ ret.color color
6
+ ret
7
+ end
8
+
9
+ def red; color :red; end
10
+ def green; color :green; end
11
+ def blue; color :blue; end
12
+ def yellow; color :yellow; end
13
+ def black; color :black; end
14
+ def white; color :white; end
15
+ end
@@ -0,0 +1,5 @@
1
+ require 'colorlib/colored_compound'
2
+
3
+ Colorlib::ColoredCompound.register_maker :tty do |text, prev|
4
+
5
+ end
@@ -0,0 +1,3 @@
1
+ module Colorlib
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorlib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kilobyte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-22 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Allows to easily colorize strings for all kinds of usages
42
+ email:
43
+ - root@kilobyte22.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - colorlib.gemspec
54
+ - lib/colorlib.rb
55
+ - lib/colorlib/color_attribute.rb
56
+ - lib/colorlib/color_builder.rb
57
+ - lib/colorlib/colored_compound.rb
58
+ - lib/colorlib/colored_string.rb
59
+ - lib/colorlib/irc_color_proc.rb
60
+ - lib/colorlib/string_extension.rb
61
+ - lib/colorlib/tty_color_proc.rb
62
+ - lib/colorlib/version.rb
63
+ homepage: ''
64
+ licenses:
65
+ - LGPL
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Colorize strings, currently supported are irc and tty (latter not fully yet
87
+ though)
88
+ test_files: []
89
+ has_rdoc: