ansi_colors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ group :development do
5
+ gem 'redcarpet'
6
+ gem 'github-markup'
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ github-markup (0.5.3)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ redcarpet (1.17.2)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ github-markup
19
+ jeweler (~> 1.6.4)
20
+ redcarpet
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Roberto Esposito
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.
data/README.markdown ADDED
@@ -0,0 +1,11 @@
1
+ Ansi Colors
2
+ ===========
3
+
4
+ This gem adds methods to colorize string using ansi escape codes.
5
+
6
+ Usage:
7
+
8
+ require 'ansi_colors'
9
+
10
+ puts "red coloured string".ansi_red
11
+ puts "white and bold string".ansi_white.ansi_bold
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ansi_colors"
18
+ gem.homepage = "http://github.com/boborbt@gmail.com/ansi_colors"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Adds methods to add ansi colors escape codes to the standard String class}
21
+ gem.description = %Q{Adds methods to add ansi colors escape codes to the standard String class}
22
+ gem.email = "boborbt@gmail.com"
23
+ gem.authors = ["Roberto Esposito"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ansi_colors}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roberto Esposito"]
12
+ s.date = %q{2011-08-26}
13
+ s.description = %q{Adds methods to add ansi colors escape codes to the standard String class}
14
+ s.email = %q{boborbt@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "ansi_colors.gemspec",
28
+ "lib/ansi_colors.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/boborbt@gmail.com/ansi_colors}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.5.0}
34
+ s.summary = %q{Adds methods to add ansi colors escape codes to the standard String class}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<redcarpet>, [">= 0"])
41
+ s.add_development_dependency(%q<github-markup>, [">= 0"])
42
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
43
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
44
+ else
45
+ s.add_dependency(%q<redcarpet>, [">= 0"])
46
+ s.add_dependency(%q<github-markup>, [">= 0"])
47
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<redcarpet>, [">= 0"])
52
+ s.add_dependency(%q<github-markup>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,83 @@
1
+ # Adds several useful methods to strings
2
+ class String
3
+ # The color commands understood by the overridden method_missing method.
4
+ ANSI_CMDS = {
5
+ :reset => 0,
6
+ :bright => 1,
7
+ :bold => 1,
8
+ :faint => 2,
9
+ :italic => 3,
10
+ :underline => 4,
11
+ :blink_slow => 5,
12
+ :blink_rapid => 6,
13
+ :inverse => 7,
14
+ :conceal => 8,
15
+ :crossed_out => 9,
16
+ :underline2 => 21,
17
+ :normal => 22,
18
+ :black => 30,
19
+ :red => 31,
20
+ :green => 32,
21
+ :yellow => 33,
22
+ :blue => 34,
23
+ :magenta => 35,
24
+ :cyan => 36,
25
+ :white => 37,
26
+ :default_color => 39,
27
+ :bck_black => 40,
28
+ :bck_red => 41,
29
+ :bck_green => 42,
30
+ :bck_yellow => 43,
31
+ :bck_blue => 44,
32
+ :bck_magenta => 45,
33
+ :bck_cyan => 46,
34
+ :bck_white => 47,
35
+ :default_background => 49
36
+ }
37
+
38
+ # Returns a quoted version of the string)
39
+ def quote
40
+ %Q{"#{self}"}
41
+ end
42
+
43
+ # Unquote a quoted string (e.g. "'test'".quote => 'test'
44
+ def unquote
45
+ match = /"(.*)"/.match(self)
46
+ match ? match[1] : self
47
+ end
48
+
49
+ # Adds escape chars to the string so that it appears coloured when printed on an
50
+ # ansi compliant terminal (non-ansi terminals will display the string surrounded
51
+ # by garbage-like stuff). col_code specifies the color to be used.
52
+ def colorize(col_code)
53
+ "\033[#{col_code}m#{self}\033[0m"
54
+ end
55
+
56
+ # Override method_missing in order to add methods to colorize the string. The
57
+ # supported methods starts with the string 'ansi_' followed by the color to be
58
+ # used. Some examples:
59
+ # - str.ansi_blue will change the foreground color of string 'str' to blue
60
+ # - str.ansi_bck_red will change the background color of string 'str' to red
61
+ # see ANSI_CMDS for a list of available commands. Combination are possible. Some
62
+ # examples:
63
+ # - str.ansi_blue.ansi_bck_red.ansi_bold will change str so to appear as a bold blue text on a red background
64
+ def method_missing symbol, *others
65
+ if symbol.to_s !~ /\Aansi_.*\Z/
66
+ return super
67
+ end
68
+
69
+ clr_id = ANSI_CMDS[symbol.to_s[5..-1].to_sym]
70
+ if clr_id
71
+ colorize(clr_id)
72
+ else
73
+ raise "Unknown ansi code"
74
+ end
75
+ end
76
+
77
+ # returns true if the stripped version of the string has zero lenght (i.e.,
78
+ # if the string is empty or contains only space characters)
79
+ def blank?
80
+ self.strip.size == 0
81
+ end
82
+
83
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansi_colors
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Roberto Esposito
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-26 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: redcarpet
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: github-markup
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.6.4
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ description: Adds methods to add ansi colors escape codes to the standard String class
61
+ email: boborbt@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - LICENSE.txt
68
+ - README.markdown
69
+ files:
70
+ - .document
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE.txt
74
+ - README.markdown
75
+ - Rakefile
76
+ - VERSION
77
+ - ansi_colors.gemspec
78
+ - lib/ansi_colors.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/boborbt@gmail.com/ansi_colors
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3561104019310490159
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.5.0
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Adds methods to add ansi colors escape codes to the standard String class
110
+ test_files: []
111
+