fronx-femto-string-colors 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -0
- data/Rakefile +40 -0
- data/lib/femto_string_colors/version.rb +13 -0
- data/lib/femto_string_colors.rb +24 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/femto_string_colors_test.rb +18 -0
- metadata +61 -0
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= FemtoStringColors
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Print colored text using console escape sequences.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
sudo gem install femto-string-colors
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
require 'femto_string_colors'
|
14
|
+
|
15
|
+
"Hallo".colorize(:green)
|
16
|
+
|
17
|
+
# => "\e\[32mHallo\e\[0m"
|
18
|
+
|
19
|
+
== License
|
20
|
+
|
21
|
+
Copyright (c) 2009 François Wurmus
|
22
|
+
|
23
|
+
Permission is hereby granted, free of charge, to any person
|
24
|
+
obtaining a copy of this software and associated documentation
|
25
|
+
files (the "Software"), to deal in the Software without
|
26
|
+
restriction, including without limitation the rights to use,
|
27
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
28
|
+
copies of the Software, and to permit persons to whom the
|
29
|
+
Software is furnished to do so, subject to the following
|
30
|
+
conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be
|
33
|
+
included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
36
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
37
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
38
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
39
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
40
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
41
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
42
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'lib/femto_string_colors/version'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
spec = Gem::Specification.new do |s|
|
10
|
+
s.name = 'femto-string-colors'
|
11
|
+
s.version = FemtoStringColors::Version.to_s
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
14
|
+
s.rdoc_options = %w(--main README.rdoc)
|
15
|
+
s.summary = "print colored text using console escape sequences"
|
16
|
+
s.author = 'François Wurmus'
|
17
|
+
s.email = 'fronx@wurmus.de'
|
18
|
+
s.homepage = 'http://fronx.wurmus.de'
|
19
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
20
|
+
# s.executables = ['femto_string_colors']
|
21
|
+
|
22
|
+
# s.add_dependency('gem_name', '~> 0.0.1')
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
26
|
+
pkg.gem_spec = spec
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::TestTask.new do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
32
|
+
t.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Generate the gemspec to serve this Gem from Github'
|
36
|
+
task :github do
|
37
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
38
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
39
|
+
puts "Created gemspec: #{file}"
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class String
|
2
|
+
COLOR_CODES = {
|
3
|
+
:default_color => "\e[0m",
|
4
|
+
:black => "\e[30m",
|
5
|
+
:red => "\e[31m",
|
6
|
+
:green => "\e[32m",
|
7
|
+
:yellow => "\e[33m",
|
8
|
+
:blue => "\e[34m",
|
9
|
+
:purple => "\e[35m",
|
10
|
+
:cyan => "\e[36m",
|
11
|
+
:white => "\e[37m"
|
12
|
+
}
|
13
|
+
|
14
|
+
def colorize(color)
|
15
|
+
raise ArgumentError, "Unknown color: '#{color}'" unless COLOR_CODES[color]
|
16
|
+
COLOR_CODES[color] + self + COLOR_CODES[:default_color]
|
17
|
+
end
|
18
|
+
|
19
|
+
COLOR_CODES.keys.each do |color|
|
20
|
+
define_method color do
|
21
|
+
self.__send__(:colorize, color)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class FemtoStringColorsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
describe "a colorizable string" do
|
6
|
+
it "should go green|red" do
|
7
|
+
"Hallo".colorize(:green).should == "\e\[32mHallo\e\[0m"
|
8
|
+
"Hallo".green.should == "\e\[32mHallo\e\[0m"
|
9
|
+
"Hallo".red.should == "\e\[31mHallo\e\[0m"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should reject invalid color codes" do
|
13
|
+
lambda { "Hallo".colorize(:magenta) }.should raise_error(ArgumentError)
|
14
|
+
lambda { "Hallo".colorize('green') }.should raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fronx-femto-string-colors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Fran\xC3\xA7ois Wurmus"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: fronx@wurmus.de
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/femto_string_colors
|
28
|
+
- lib/femto_string_colors/version.rb
|
29
|
+
- lib/femto_string_colors.rb
|
30
|
+
- test/test_helper.rb
|
31
|
+
- test/unit
|
32
|
+
- test/unit/femto_string_colors_test.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://fronx.wurmus.de
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --main
|
38
|
+
- README.rdoc
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: print colored text using console escape sequences
|
60
|
+
test_files: []
|
61
|
+
|