color_routes 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License
2
-
3
- Copyright (c) Nicolas Oga
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1
+ The MIT License
2
+
3
+ Copyright (c) Nicolas Oga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
- ColorRoutes
2
- ===========
3
-
4
- # DESCRIPTION
5
-
6
- ColorRoutes is just a little library bundled with the necessary code to turn the output of the rake routes command from the usable but dull white and black screen to something more vivid and full of nice colors :).
7
-
8
- Have fun with it!
9
-
10
- # DEMO!
11
-
12
- <img src="https://github.com/nicooga/color_routes/raw/master/doc/demo.png" title="Example output" alt="Example output" />
1
+ ColorRoutes
2
+ ===========
3
+
4
+ # DESCRIPTION
5
+
6
+ ColorRoutes is just a little library bundled with the necessary code to turn the output of the rake routes command from the usable but dull white and black screen to something more vivid and full of nice colors :).
7
+
8
+ Have fun with it!
9
+
10
+ # DEMO
11
+
12
+ rake routes normal output:
13
+ <img src="https://github.com/nicooga/color_routes/raw/master/doc/demo1.png" title="Example output" alt="Example output" />
14
+
15
+ rake color_routes output:
16
+ <img src="https://github.com/nicooga/color_routes/raw/master/doc/demo2.png" title="Example output" alt="Example output" />
data/Rakefile CHANGED
@@ -1,150 +1,150 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'date'
4
-
5
- #############################################################################
6
- #
7
- # Helper functions
8
- #
9
- #############################################################################
10
-
11
- def name
12
- @name ||= Dir['*.gemspec'].first.split('.').first
13
- end
14
-
15
- def version
16
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
- end
19
-
20
- def date
21
- Date.today.to_s
22
- end
23
-
24
- def rubyforge_project
25
- name
26
- end
27
-
28
- def gemspec_file
29
- "#{name}.gemspec"
30
- end
31
-
32
- def gem_file
33
- "#{name}-#{version}.gem"
34
- end
35
-
36
- def replace_header(head, header_name)
37
- head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
- end
39
-
40
- #############################################################################
41
- #
42
- # Standard tasks
43
- #
44
- #############################################################################
45
-
46
- task :default => :test
47
-
48
- require 'rake/testtask'
49
- Rake::TestTask.new(:test) do |test|
50
- test.libs << 'lib' << 'test'
51
- test.pattern = 'test/**/test_*.rb'
52
- test.verbose = true
53
- end
54
-
55
- desc "Generate RCov test coverage and open in your browser"
56
- task :coverage do
57
- require 'rcov'
58
- sh "rm -fr coverage"
59
- sh "rcov test/test_*.rb"
60
- sh "open coverage/index.html"
61
- end
62
-
63
- require 'rdoc/task'
64
- Rake::RDocTask.new do |rdoc|
65
- rdoc.rdoc_dir = 'rdoc'
66
- rdoc.title = "#{name} #{version}"
67
- rdoc.rdoc_files.include('README*')
68
- rdoc.rdoc_files.include('lib/**/*.rb')
69
- end
70
-
71
- desc "Open an irb session preloaded with this library"
72
- task :console do
73
- sh "irb -rubygems -r ./lib/#{name}.rb"
74
- end
75
-
76
- #############################################################################
77
- #
78
- # Custom tasks (add your own tasks here)
79
- #
80
- #############################################################################
81
-
82
-
83
-
84
- #############################################################################
85
- #
86
- # Packaging tasks
87
- #
88
- #############################################################################
89
-
90
- desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91
- task :release => :build do
92
- unless `git branch` =~ /^\* master$/
93
- puts "You must be on the master branch to release!"
94
- exit!
95
- end
96
- sh "git commit --allow-empty -a -m 'Release #{version}'"
97
- sh "git tag v#{version}"
98
- sh "git push origin master"
99
- sh "git push origin v#{version}"
100
- sh "gem push pkg/#{name}-#{version}.gem"
101
- end
102
-
103
- desc "Build #{gem_file} into the pkg directory"
104
- task :build => :gemspec do
105
- sh "mkdir -p pkg"
106
- sh "gem build #{gemspec_file}"
107
- sh "mv #{gem_file} pkg"
108
- end
109
-
110
- desc "Generate #{gemspec_file}"
111
- task :gemspec => :validate do
112
- # read spec file and split out manifest section
113
- spec = File.read(gemspec_file)
114
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
-
116
- # replace name version and date
117
- replace_header(head, :name)
118
- replace_header(head, :version)
119
- replace_header(head, :date)
120
- #comment this out if your rubyforge_project has a different name
121
- replace_header(head, :rubyforge_project)
122
-
123
- # determine file list from git ls-files
124
- files = `git ls-files`.
125
- split("\n").
126
- sort.
127
- reject { |file| file =~ /^\./ }.
128
- reject { |file| file =~ /^(rdoc|pkg)/ }.
129
- map { |file| " #{file}" }.
130
- join("\n")
131
-
132
- # piece file back together and write
133
- manifest = " s.files = %w[\n#{files}\n ]\n"
134
- spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
- File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
- puts "Updated #{gemspec_file}"
137
- end
138
-
139
- desc "Validate #{gemspec_file}"
140
- task :validate do
141
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142
- unless libfiles.empty?
143
- puts "Directory `lib` should only contain a `#{name}.rb` file and a `#{name}` dir."
144
- exit!
145
- end
146
- unless Dir['VERSION*'].empty?
147
- puts "A `VERSION` file at root level violates Gem best practices."
148
- exit!
149
- end
150
- end
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ require 'rdoc/task'
64
+ Rake::RDocTask.new do |rdoc|
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "#{name} #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
70
+
71
+ desc "Open an irb session preloaded with this library"
72
+ task :console do
73
+ sh "irb -rubygems -r ./lib/#{name}.rb"
74
+ end
75
+
76
+ #############################################################################
77
+ #
78
+ # Custom tasks (add your own tasks here)
79
+ #
80
+ #############################################################################
81
+
82
+
83
+
84
+ #############################################################################
85
+ #
86
+ # Packaging tasks
87
+ #
88
+ #############################################################################
89
+
90
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push origin v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ desc "Build #{gem_file} into the pkg directory"
104
+ task :build => :gemspec do
105
+ sh "mkdir -p pkg"
106
+ sh "gem build #{gemspec_file}"
107
+ sh "mv #{gem_file} pkg"
108
+ end
109
+
110
+ desc "Generate #{gemspec_file}"
111
+ task :gemspec => :validate do
112
+ # read spec file and split out manifest section
113
+ spec = File.read(gemspec_file)
114
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
115
+
116
+ # replace name version and date
117
+ replace_header(head, :name)
118
+ replace_header(head, :version)
119
+ replace_header(head, :date)
120
+ #comment this out if your rubyforge_project has a different name
121
+ replace_header(head, :rubyforge_project)
122
+
123
+ # determine file list from git ls-files
124
+ files = `git ls-files`.
125
+ split("\n").
126
+ sort.
127
+ reject { |file| file =~ /^\./ }.
128
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
129
+ map { |file| " #{file}" }.
130
+ join("\n")
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ desc "Validate #{gemspec_file}"
140
+ task :validate do
141
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142
+ unless libfiles.empty?
143
+ puts "Directory `lib` should only contain a `#{name}.rb` file and a `#{name}` dir."
144
+ exit!
145
+ end
146
+ unless Dir['VERSION*'].empty?
147
+ puts "A `VERSION` file at root level violates Gem best practices."
148
+ exit!
149
+ end
150
+ end
@@ -1,34 +1,36 @@
1
- Gem::Specification.new do |s|
2
- s.specification_version = 2 if s.respond_to? :specification_version=
3
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
- s.rubygems_version = '1.3.5'
5
-
6
- s.name = 'color_routes'
7
- s.version = '0.0.3'
8
- s.date = '2012-01-21'
9
- s.rubyforge_project = 'color_routes'
10
-
11
- s.summary = "Colorize rake routes output for rails."
12
- s.description = "Colorize rake routes output for rails."
13
-
14
- s.authors = ["Nicolas Oga"]
15
- s.email = '2112.oga@gmail.com'
16
- s.homepage = 'http://nicooga.github.com/color_routes'
17
-
18
- s.require_paths = %w[lib]
19
-
20
- s.rdoc_options = ["--charset=UTF-8"]
21
- s.extra_rdoc_files = %w[README.md LICENSE doc/demo.png]
22
-
23
- # = MANIFEST =
24
- s.files = %w[
25
- LICENSE
26
- README.md
27
- Rakefile
28
- color_routes.gemspec
29
- lib/color_routes.rb
30
- lib/color_routes/rails/tasks/color_routes.rake
31
- lib/color_routes/string_ansi.rb
32
- ]
33
- # = MANIFEST =
1
+
2
+ Gem::Specification.new do |s|
3
+ s.specification_version = 2 if s.respond_to? :specification_version=
4
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ s.rubygems_version = '1.3.5'
6
+
7
+ s.name = 'color_routes'
8
+ s.version = '1.0.0'
9
+ s.date = '2012-10-23'
10
+ s.rubyforge_project = 'color_routes'
11
+
12
+ s.summary = "Colorize rake routes output for rails."
13
+ s.description = "Colorize rake routes output for rails."
14
+
15
+ s.authors = ["Nicolas Oga"]
16
+ s.email = '2112.oga@gmail.com'
17
+ s.homepage = 'http://nicooga.github.com/NAME'
18
+
19
+ s.require_paths = %w[lib]
20
+
21
+ s.rdoc_options = ["--charset=UTF-8"]
22
+ s.extra_rdoc_files = %w[README.md LICENSE doc/demo1.png doc/demo2.png]
23
+
24
+ # = MANIFEST =
25
+ s.files = %w[
26
+ LICENSE
27
+ README.md
28
+ Rakefile
29
+ color_routes.gemspec
30
+ doc/demo1.png
31
+ doc/demo2.png
32
+ lib/color_routes.rb
33
+ lib/color_routes/rails/tasks/color_routes.rake
34
+ ]
35
+ # = MANIFEST =
34
36
  end
Binary file
Binary file
@@ -1,11 +1,11 @@
1
- module ColorRoutes
2
- VERSION="0.0.2"
3
-
4
- module Rails
5
- class Railtie < ::Rails::Railtie
6
- rake_tasks do
7
- load "color_routes/rails/tasks/color_routes.rake"
8
- end
9
- end
10
- end
1
+ module ColorRoutes
2
+ VERSION="1.0.0"
3
+
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ rake_tasks do
7
+ load "color_routes/rails/tasks/color_routes.rake"
8
+ end
9
+ end
10
+ end
11
11
  end
@@ -1,61 +1,36 @@
1
- desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
2
- task :color_routes => :environment do
3
-
4
- Rails.application.reload_routes!
5
- all_routes = Rails.application.routes.routes
6
-
7
- if ENV['CONTROLLER']
8
- all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
9
- end
10
-
11
- routes = all_routes.collect do |route|
12
- reqs = route.requirements.dup
13
- reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
14
- {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
15
- end
16
-
17
- # Skip the route if it's internal info route
18
- routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
19
-
20
- route_rows = routes.map do |r|
21
- [
22
- r[:name].presence || "-",
23
- r[:verb].presence || "-",
24
- r[:path].presence || "-",
25
- r[:reqs]
26
- ]
27
- end
28
-
29
- # concede ruby strings ANSI superpowers!
30
- require 'color_routes/string_ansi'
31
-
32
- # TODO: Extract table creation to a separate class.
33
- route_rows.group_by { |table| table[3][:controller] }.each do |controller, route_table|
34
- puts((controller ? controller.camelize : "No Specific Controller").color(:red))
35
-
36
- route_table.map! do |row|
37
- name = row[0]
38
- verb = row[1].color(:red)
39
- path = row[2].gsub(/(:[^\(\)\/]+)/) do $1.color(:cyan) end
40
- path = path.gsub(/([\/\.\(\)])/) do $1.color(:brown) end
41
- reqs = "{".color(:blue) + " #{row[3].map { |k, v| "#{k.inspect.color(:magenta)} #{"=>".color(:blue)} #{v.inspect.color(:white)}" }.sort.reverse.join(", ") }" + " }".color(:blue)
42
- [name, verb, path, reqs]
43
- end
44
-
45
- widths = [
46
- route_table.map{ |r| r[0].ansi_length }.max,
47
- route_table.map{ |r| r[1].ansi_length }.max,
48
- route_table.map{ |r| r[2].ansi_length }.max,
49
- route_table.map{ |r| r[3].ansi_length }.max
50
- ]
51
- widths.map! do |w| w < 6 ? 6 : w end
52
-
53
- puts "+#{'-'*(widths[0]+2)}+#{'-'*(widths[1]+2)}+#{'-'*(widths[2]+2)}+#{'-'*(widths[3]-4)}+"
54
- route_table.each do |r|
55
- puts "| #{r[0].ansi_rjust(widths[0])} | #{r[1].ansi_ljust(widths[1])} | #{r[2].ansi_ljust(widths[2])} | #{r[3].ansi_ljust(widths[3])} |"
56
- end
57
- puts "+#{'-'*(widths[0]+2)}+#{'-'*(widths[1]+2)}+#{'-'*(widths[2]+2)}+#{'-'*(widths[3]-4)}+"
58
-
59
- puts
60
- end
1
+ desc 'Pretty version on rails rake routes.'
2
+
3
+ EMK="\033[1;30m"
4
+ EMR="\033[1;31m"
5
+ EMG="\033[1;32m"
6
+ EMY="\033[1;33m"
7
+ EMB="\033[1;34m"
8
+ EMM="\033[1;35m"
9
+ EMC="\033[1;36m"
10
+ EMW="\033[1;37m"
11
+ NOCOLOR = "\033[0m"
12
+
13
+ task :color_routes => :environment do
14
+ Rails.application.reload_routes!
15
+ all_routes = Rails.application.routes.routes.to_a
16
+ all_routes.reject! {|route| route.verb == nil or route.path.spec.to_s == '/assets'}
17
+
18
+ names_max_width = all_routes.map {|route| route.name.to_s.length}.max
19
+ verbs_max_width = 6
20
+ paths_max_width = all_routes.map {|route| route.path.spec.to_s.length}.max
21
+ controllers_max_width = all_routes.map {|route| route.defaults[:controller].length}.max
22
+ actions_max_width = all_routes.map {|route| route.defaults[:action].length}.max
23
+
24
+ all_routes.group_by {|route| route.defaults[:controller]}.each_value do |group|
25
+ puts EMK + "\nCONTROLLER: " + EMW + group.first.defaults[:controller] + NOCOLOR
26
+ group.each do |route|
27
+ name = EMC + route.name.to_s.rjust(names_max_width) + NOCOLOR
28
+ verb = EMY + route.verb.inspect.gsub(/^.{2}|.{2}$/,"").center(verbs_max_width) + NOCOLOR
29
+ path = EMR + route.path.spec.to_s.ljust(paths_max_width).gsub(/(\.?:[^\(\)\/]+)/){EMB + $1 + EMR} + NOCOLOR
30
+ action = EMW + route.defaults[:action].ljust(actions_max_width) + NOCOLOR
31
+
32
+ puts "|#{name}|#{verb}|#{path}|#{action}"
33
+ end
34
+ end
35
+
61
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-21 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Colorize rake routes output for rails.
15
15
  email: 2112.oga@gmail.com
@@ -18,17 +18,18 @@ extensions: []
18
18
  extra_rdoc_files:
19
19
  - README.md
20
20
  - LICENSE
21
- - doc/demo.png
21
+ - doc/demo1.png
22
+ - doc/demo2.png
22
23
  files:
23
24
  - LICENSE
24
25
  - README.md
25
26
  - Rakefile
26
27
  - color_routes.gemspec
28
+ - doc/demo1.png
29
+ - doc/demo2.png
27
30
  - lib/color_routes.rb
28
31
  - lib/color_routes/rails/tasks/color_routes.rake
29
- - lib/color_routes/string_ansi.rb
30
- - doc/demo.png
31
- homepage: http://nicooga.github.com/color_routes
32
+ homepage: http://nicooga.github.com/NAME
32
33
  licenses: []
33
34
  post_install_message:
34
35
  rdoc_options:
@@ -49,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  version: '0'
50
51
  requirements: []
51
52
  rubyforge_project: color_routes
52
- rubygems_version: 1.8.11
53
+ rubygems_version: 1.8.24
53
54
  signing_key:
54
55
  specification_version: 2
55
56
  summary: Colorize rake routes output for rails.
Binary file
@@ -1,41 +0,0 @@
1
- module ColorRoutes
2
-
3
- # Some extensions to String to deal with ANSI colors.
4
- module StringANSI
5
-
6
- COLORS = {
7
- :black => 30,
8
- :red => 31,
9
- :green => 32,
10
- :brown => 33,
11
- :blue => 34,
12
- :magenta => 35,
13
- :cyan => 36,
14
- :gray => 37
15
- }
16
-
17
- def color(color)
18
- code = "\033[#{COLORS[color]}m"
19
- end_code = "\033[0m"
20
- "#{code}#{self}#{end_code}"
21
- end
22
-
23
- def ansi_length
24
- gsub(/\033\[\d+m/, "").length
25
- end
26
-
27
- def ansi_ljust(n)
28
- ljust(n + length - ansi_length)
29
- end
30
-
31
- def ansi_rjust(n)
32
- rjust(n + length - ansi_length)
33
- end
34
-
35
- end
36
-
37
- end
38
-
39
- class String
40
- include ColorRoutes::StringANSI
41
- end