iron-term-ansicolor 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
- = iron-term-ansicolor
2
-
3
- iron-term-console is a library for IronRuby that makes use of the .Net framework
4
- System.Console and related classes to provide colored output for ANSI formatted
5
- strings.
6
-
7
- For the Ruby OneClick installer, a package called win32console exists to provide
8
- this functionality. It makes calls to the Win32 API, including bit twiddling,
9
- to provide colored console output for that Ruby distribution. In IronRuby, we
10
- have direct access to the .Net Base Class Library. Rather than writing C# code
11
- to create an IronRuby module to interact with a C++ API, this library directly
12
- uses the .Net BCL, and write the code directly in Ruby.
13
-
14
- == Copyright
15
-
16
- Copyright (c) 2009 Will Green, Ivan Porto Carrero, David Blackmon. See LICENSE for details.
1
+ = iron-term-ansicolor
2
+
3
+ iron-term-console is a library for IronRuby that makes use of the .Net framework
4
+ System.Console and related classes to provide colored output for ANSI formatted
5
+ strings.
6
+
7
+ For the Ruby OneClick installer, a package called win32console exists to provide
8
+ this functionality. It makes calls to the Win32 API, including bit twiddling,
9
+ to provide colored console output for that Ruby distribution. In IronRuby, we
10
+ have direct access to the .Net Base Class Library. Rather than writing C# code
11
+ to create an IronRuby module to interact with a C++ API, this library directly
12
+ uses the .Net BCL, and write the code directly in Ruby.
13
+
14
+ == Copyright
15
+
16
+ Copyright (c) 2009 Will Green, Ivan Porto Carrero, David Blackmon. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,226 +1,226 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'fileutils'
4
- require 'rake/rdoctask'
5
- require 'lib/iron-term-ansicolor'
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "iron-term-ansicolor"
10
- gem.summary = %Q{TODO}
11
- gem.email = "will@hotgazpacho.org"
12
- gem.homepage = "http://github.com/hotgazpacho/iron-term-ansicolor"
13
- gem.authors = ["hotgazpacho","casualjim"]
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
-
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
- end
20
-
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- end
26
-
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- end
32
-
33
-
34
- task :default => :spec
35
-
36
-
37
- ##############################################################################
38
- # OPTIONS
39
- ##############################################################################
40
-
41
- PKG_NAME = 'iron-term-ansicolor'
42
- PKG_VERSION = if File.exist?('VERSION.yml')
43
- config = YAML.load(File.read('VERSION.yml'))
44
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
- else
46
- version = IronTermAnsiColor::Version::STRING
47
- end
48
- AUTHORS = ['Will Green', 'David Blackmon', 'Ivan Porto Carrero']
49
- EMAIL = "will@hotgazpacho.org"
50
- HOMEPAGE = "http://github.com/hotgazpacho/iron-term-ansicolor"
51
- SUMMARY = "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby."
52
-
53
- # These are the common rdoc options that are shared between generation of
54
- # rdoc files using BOTH 'rake rdoc' and the installation by users of a
55
- # RubyGem version which builds rdoc's along with its installation. Any
56
- # rdoc options that are ONLY for developers running 'rake rdoc' should be
57
- # added in the 'Rake::RDocTask' block below.
58
- RDOC_OPTIONS = [
59
- "--quiet",
60
- "--title", SUMMARY,
61
- "--main", "README.rdoc",
62
- "--line-numbers",
63
- "--format","darkfish"
64
- ]
65
-
66
- # Extra files outside of the lib dir that should be included with the rdocs.
67
- RDOC_FILES = (%w( README.rdoc)).sort
68
-
69
- # The full file list used for rdocs, tarballs, gems, and for generating the xmpp4r.gemspec.
70
- PKG_FILES = (%w( Rakefile iron-term-ansicolor.gemspec ) + RDOC_FILES + Dir["{lib,spec}/**/*"]).sort
71
-
72
- # RDOC
73
- #######
74
- Rake::RDocTask.new do |rd|
75
-
76
- # which dir should rdoc files be installed in?
77
- rd.rdoc_dir = 'rdoc'
78
- rd.title = "iron-term-ansicolor #{PKG_VERSION}"
79
-
80
- # the full list of files to be included
81
- rd.rdoc_files.include('README*')
82
- rd.rdoc_files.include(RDOC_FILES, "lib/**/*.rb")
83
-
84
- # the full list of options that are common between gem build
85
- # and 'rake rdoc' build of docs.
86
- rd.options = RDOC_OPTIONS
87
-
88
- # Devs Only : Uncomment to also document private methods in the rdocs
89
- # Please don't check this change in to the source repo.
90
- #rd.options << '--all'
91
-
92
- # Devs Only : Uncomment to generate dot (graphviz) diagrams along with rdocs.
93
- # This requires that graphiz (dot) be installed as a local binary and on your path.
94
- # See : http://www.graphviz.org/
95
- # Please don't check this change in to the source repo as it introduces a binary dependency.
96
- #rd.options << '--diagram'
97
- #rd.options << '--fileboxes'
98
-
99
- end
100
-
101
- ##############################################################################
102
- # PACKAGING & INSTALLATION
103
- ##############################################################################
104
-
105
- # What files/dirs should 'rake clean' remove?
106
- #CLEAN.include ["*.gem", "pkg", "rdoc", "coverage"]
107
-
108
- begin
109
- require 'rake/gempackagetask'
110
-
111
- spec = Gem::Specification.new do |s|
112
- s.name = PKG_NAME
113
- s.version = PKG_VERSION
114
- s.authors = AUTHORS
115
- s.email = EMAIL
116
- s.homepage = HOMEPAGE
117
- s.rubyforge_project = PKG_NAME
118
- s.summary = SUMMARY
119
- s.description = s.summary
120
- s.platform = Gem::Platform::RUBY
121
- s.require_path = 'lib'
122
- s.executables = []
123
- s.files = PKG_FILES
124
- s.test_files = []
125
- s.has_rdoc = true
126
- s.extra_rdoc_files = RDOC_FILES
127
- s.rdoc_options = RDOC_OPTIONS
128
- s.required_ruby_version = ">= 1.8.6"
129
- s.add_dependency 'term-ansicolor', ">= 1.0.4"
130
- end
131
-
132
- Rake::GemPackageTask.new(spec) do |pkg|
133
- pkg.gem_spec = spec
134
- pkg.need_tar = true
135
- pkg.need_zip = true
136
- end
137
-
138
- namespace :gem do
139
-
140
- desc "Run :package and install the .gem locally"
141
- task :install => [:update_gemspec, :package] do
142
- sh %{sudo gem install --local pkg/#{PKG_NAME}-#{PKG_VERSION}.gem}
143
- end
144
-
145
- desc "Like gem:install but without ri or rdocs"
146
- task :install_fast => [:update_gemspec, :package] do
147
- sh %{sudo gem install --local pkg/#{PKG_NAME}-#{PKG_VERSION}.gem --no-rdoc --no-ri}
148
- end
149
-
150
- desc "Run :clean and uninstall the .gem"
151
- task :uninstall => :clean do
152
- sh %{sudo gem uninstall #{PKG_NAME}}
153
- end
154
-
155
- # Thanks to the Merb project for this code.
156
- desc "Update Github Gemspec"
157
- task :update_gemspec do
158
- skip_fields = %w(new_platform original_platform date)
159
-
160
- result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
161
- result << "# RUN : 'rake gem:update_gemspec'\n\n"
162
- result << "Gem::Specification.new do |s|\n"
163
- spec.instance_variables.sort.each do |ivar|
164
- value = spec.instance_variable_get(ivar)
165
- name = ivar.to_s.split("@").last
166
- next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
167
- if name == "dependencies"
168
- value.each do |d|
169
- dep, *ver = d.to_s.split(" ")
170
- result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "")}\n"
171
- end
172
- else
173
- case value
174
- when Array
175
- value = name != "files" ? value.inspect : value.sort.uniq.inspect.split(",").join(",\n")
176
- when String, Fixnum, true, false
177
- value = value.inspect
178
- else
179
- value = value.to_s.inspect
180
- end
181
- result << " s.#{name} = #{value}\n"
182
- end
183
- end
184
- result << "end"
185
- File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
186
- end
187
-
188
- end # namespace :gem
189
-
190
- # also keep the gemspec up to date each time we package a tarball or gem
191
- task :package => ['gem:update_gemspec']
192
- task :gem => ['gem:update_gemspec']
193
-
194
- rescue LoadError
195
- puts <<EOF
196
- ###
197
- Packaging Warning : RubyGems is apparently not installed on this
198
- system and any file add/remove/rename will not
199
- be auto-updated in the 'iron-term-ansicolor.gemspec' when you run any
200
- package tasks. All such file changes are recommended
201
- to be packaged on a system with RubyGems installed
202
- if you intend to push commits to the Git repo so the
203
- gemspec will also stay in sync for others.
204
- ###
205
- EOF
206
- end
207
-
208
- # we are apparently on a system that does not have RubyGems installed.
209
- # Lets try to provide only the basic tarball package tasks as a fallback.
210
- unless defined? Gem
211
- begin
212
- require 'rake/packagetask'
213
- Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |p|
214
- p.package_files = PKG_FILES
215
- p.need_tar = true
216
- p.need_zip = true
217
- end
218
- rescue LoadError
219
- puts <<EOF
220
- ###
221
- Warning : Unable to require the 'rake/packagetask'. Is Rake installed?
222
- ###
223
- EOF
224
- end
225
- end
226
-
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'fileutils'
4
+ require 'rake/rdoctask'
5
+ require 'lib/iron-term-ansicolor'
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "iron-term-ansicolor"
10
+ gem.summary = %Q{TODO}
11
+ gem.email = "will@hotgazpacho.org"
12
+ gem.homepage = "http://github.com/hotgazpacho/iron-term-ansicolor"
13
+ gem.authors = ["hotgazpacho","casualjim"]
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+
34
+ task :default => :spec
35
+
36
+
37
+ ##############################################################################
38
+ # OPTIONS
39
+ ##############################################################################
40
+
41
+ PKG_NAME = 'iron-term-ansicolor'
42
+ PKG_VERSION = if File.exist?('VERSION.yml')
43
+ config = YAML.load(File.read('VERSION.yml'))
44
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ else
46
+ version = IronTermAnsiColor::Version::STRING
47
+ end
48
+ AUTHORS = ['Will Green', 'David Blackmon', 'Ivan Porto Carrero']
49
+ EMAIL = "will@hotgazpacho.org"
50
+ HOMEPAGE = "http://github.com/hotgazpacho/iron-term-ansicolor"
51
+ SUMMARY = "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby."
52
+
53
+ # These are the common rdoc options that are shared between generation of
54
+ # rdoc files using BOTH 'rake rdoc' and the installation by users of a
55
+ # RubyGem version which builds rdoc's along with its installation. Any
56
+ # rdoc options that are ONLY for developers running 'rake rdoc' should be
57
+ # added in the 'Rake::RDocTask' block below.
58
+ RDOC_OPTIONS = [
59
+ "--quiet",
60
+ "--title", SUMMARY,
61
+ "--main", "README.rdoc",
62
+ "--line-numbers",
63
+ "--format","darkfish"
64
+ ]
65
+
66
+ # Extra files outside of the lib dir that should be included with the rdocs.
67
+ RDOC_FILES = (%w( README.rdoc)).sort
68
+
69
+ # The full file list used for rdocs, tarballs, gems, and for generating the xmpp4r.gemspec.
70
+ PKG_FILES = (%w( Rakefile iron-term-ansicolor.gemspec ) + RDOC_FILES + Dir["{lib,spec}/**/*"]).sort
71
+
72
+ # RDOC
73
+ #######
74
+ Rake::RDocTask.new do |rd|
75
+
76
+ # which dir should rdoc files be installed in?
77
+ rd.rdoc_dir = 'rdoc'
78
+ rd.title = "iron-term-ansicolor #{PKG_VERSION}"
79
+
80
+ # the full list of files to be included
81
+ rd.rdoc_files.include('README*')
82
+ rd.rdoc_files.include(RDOC_FILES, "lib/**/*.rb")
83
+
84
+ # the full list of options that are common between gem build
85
+ # and 'rake rdoc' build of docs.
86
+ rd.options = RDOC_OPTIONS
87
+
88
+ # Devs Only : Uncomment to also document private methods in the rdocs
89
+ # Please don't check this change in to the source repo.
90
+ #rd.options << '--all'
91
+
92
+ # Devs Only : Uncomment to generate dot (graphviz) diagrams along with rdocs.
93
+ # This requires that graphiz (dot) be installed as a local binary and on your path.
94
+ # See : http://www.graphviz.org/
95
+ # Please don't check this change in to the source repo as it introduces a binary dependency.
96
+ #rd.options << '--diagram'
97
+ #rd.options << '--fileboxes'
98
+
99
+ end
100
+
101
+ ##############################################################################
102
+ # PACKAGING & INSTALLATION
103
+ ##############################################################################
104
+
105
+ # What files/dirs should 'rake clean' remove?
106
+ #CLEAN.include ["*.gem", "pkg", "rdoc", "coverage"]
107
+
108
+ begin
109
+ require 'rake/gempackagetask'
110
+
111
+ spec = Gem::Specification.new do |s|
112
+ s.name = PKG_NAME
113
+ s.version = PKG_VERSION
114
+ s.authors = AUTHORS
115
+ s.email = EMAIL
116
+ s.homepage = HOMEPAGE
117
+ s.rubyforge_project = PKG_NAME
118
+ s.summary = SUMMARY
119
+ s.description = s.summary
120
+ s.platform = Gem::Platform::RUBY
121
+ s.require_path = 'lib'
122
+ s.executables = []
123
+ s.files = PKG_FILES
124
+ s.test_files = []
125
+ s.has_rdoc = true
126
+ s.extra_rdoc_files = RDOC_FILES
127
+ s.rdoc_options = RDOC_OPTIONS
128
+ s.required_ruby_version = ">= 1.8.6"
129
+ s.add_dependency 'term-ansicolor', ">= 1.0.4"
130
+ end
131
+
132
+ Rake::GemPackageTask.new(spec) do |pkg|
133
+ pkg.gem_spec = spec
134
+ pkg.need_tar = true
135
+ pkg.need_zip = true
136
+ end
137
+
138
+ namespace :gem do
139
+
140
+ desc "Run :package and install the .gem locally"
141
+ task :install => [:update_gemspec, :package] do
142
+ sh %{sudo gem install --local pkg/#{PKG_NAME}-#{PKG_VERSION}.gem}
143
+ end
144
+
145
+ desc "Like gem:install but without ri or rdocs"
146
+ task :install_fast => [:update_gemspec, :package] do
147
+ sh %{sudo gem install --local pkg/#{PKG_NAME}-#{PKG_VERSION}.gem --no-rdoc --no-ri}
148
+ end
149
+
150
+ desc "Run :clean and uninstall the .gem"
151
+ task :uninstall => :clean do
152
+ sh %{sudo gem uninstall #{PKG_NAME}}
153
+ end
154
+
155
+ # Thanks to the Merb project for this code.
156
+ desc "Update Github Gemspec"
157
+ task :update_gemspec do
158
+ skip_fields = %w(new_platform original_platform date)
159
+
160
+ result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
161
+ result << "# RUN : 'rake gem:update_gemspec'\n\n"
162
+ result << "Gem::Specification.new do |s|\n"
163
+ spec.instance_variables.sort.each do |ivar|
164
+ value = spec.instance_variable_get(ivar)
165
+ name = ivar.to_s.split("@").last
166
+ next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
167
+ if name == "dependencies"
168
+ value.each do |d|
169
+ dep, *ver = d.to_s.split(" ")
170
+ result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "")}\n"
171
+ end
172
+ else
173
+ case value
174
+ when Array
175
+ value = name != "files" ? value.inspect : value.sort.uniq.inspect.split(",").join(",\n")
176
+ when String, Fixnum, true, false
177
+ value = value.inspect
178
+ else
179
+ value = value.to_s.inspect
180
+ end
181
+ result << " s.#{name} = #{value}\n"
182
+ end
183
+ end
184
+ result << "end"
185
+ File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
186
+ end
187
+
188
+ end # namespace :gem
189
+
190
+ # also keep the gemspec up to date each time we package a tarball or gem
191
+ task :package => ['gem:update_gemspec']
192
+ task :gem => ['gem:update_gemspec']
193
+
194
+ rescue LoadError
195
+ puts <<EOF
196
+ ###
197
+ Packaging Warning : RubyGems is apparently not installed on this
198
+ system and any file add/remove/rename will not
199
+ be auto-updated in the 'iron-term-ansicolor.gemspec' when you run any
200
+ package tasks. All such file changes are recommended
201
+ to be packaged on a system with RubyGems installed
202
+ if you intend to push commits to the Git repo so the
203
+ gemspec will also stay in sync for others.
204
+ ###
205
+ EOF
206
+ end
207
+
208
+ # we are apparently on a system that does not have RubyGems installed.
209
+ # Lets try to provide only the basic tarball package tasks as a fallback.
210
+ unless defined? Gem
211
+ begin
212
+ require 'rake/packagetask'
213
+ Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |p|
214
+ p.package_files = PKG_FILES
215
+ p.need_tar = true
216
+ p.need_zip = true
217
+ end
218
+ rescue LoadError
219
+ puts <<EOF
220
+ ###
221
+ Warning : Unable to require the 'rake/packagetask'. Is Rake installed?
222
+ ###
223
+ EOF
224
+ end
225
+ end
226
+
@@ -1,32 +1,32 @@
1
- # WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
2
- # RUN : 'rake gem:update_gemspec'
3
-
4
- Gem::Specification.new do |s|
5
- s.authors = ["Will Green", "David Blackmon", "Ivan Porto Carrero"]
6
- s.bindir = "bin"
7
- s.add_dependency "term-ansicolor", ">= 1.0.4"
8
- s.description = "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby."
9
- s.email = "will@hotgazpacho.org"
10
- s.extra_rdoc_files = ["README.rdoc"]
11
- s.files = ["README.rdoc",
12
- "Rakefile",
13
- "iron-term-ansicolor.gemspec",
14
- "lib/iron-term-ansicolor.rb",
15
- "spec/iron-term-ansicolor_simple_background_spec.rb",
16
- "spec/iron-term-ansicolor_simple_foreground_spec.rb",
17
- "spec/spec_helper.rb"]
18
- s.has_rdoc = true
19
- s.homepage = "http://github.com/hotgazpacho/iron-term-ansicolor"
20
- s.loaded = false
21
- s.name = "iron-term-ansicolor"
22
- s.platform = "ruby"
23
- s.rdoc_options = ["--quiet", "--title", "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby.", "--main", "README.rdoc", "--line-numbers", "--format", "darkfish"]
24
- s.require_paths = ["lib"]
25
- s.required_ruby_version = ">= 1.8.6"
26
- s.required_rubygems_version = ">= 0"
27
- s.rubyforge_project = "iron-term-ansicolor"
28
- s.rubygems_version = "1.3.5"
29
- s.specification_version = 3
30
- s.summary = "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby."
31
- s.version = "0.0.1"
1
+ # WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
2
+ # RUN : 'rake gem:update_gemspec'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.authors = ["Will Green", "David Blackmon", "Ivan Porto Carrero"]
6
+ s.bindir = "bin"
7
+ s.add_dependency "term-ansicolor", ">= 1.0.4, runtime"
8
+ s.description = "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby."
9
+ s.email = "will@hotgazpacho.org"
10
+ s.extra_rdoc_files = ["README.rdoc"]
11
+ s.files = ["README.rdoc",
12
+ "Rakefile",
13
+ "iron-term-ansicolor.gemspec",
14
+ "lib/iron-term-ansicolor.rb",
15
+ "spec/iron-term-ansicolor_simple_background_spec.rb",
16
+ "spec/iron-term-ansicolor_simple_foreground_spec.rb",
17
+ "spec/spec_helper.rb"]
18
+ s.has_rdoc = true
19
+ s.homepage = "http://github.com/hotgazpacho/iron-term-ansicolor"
20
+ s.loaded = false
21
+ s.name = "iron-term-ansicolor"
22
+ s.platform = "ruby"
23
+ s.rdoc_options = ["--quiet", "--title", "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby.", "--main", "README.rdoc", "--line-numbers", "--format", "darkfish"]
24
+ s.require_paths = ["lib"]
25
+ s.required_ruby_version = ">= 1.8.6"
26
+ s.required_rubygems_version = ">= 0"
27
+ s.rubyforge_project = "iron-term-ansicolor"
28
+ s.rubygems_version = "1.3.5"
29
+ s.specification_version = 3
30
+ s.summary = "iron-term-ansicolor brings color output for RSpec and the likes to IronRuby."
31
+ s.version = "0.0.2"
32
32
  end
@@ -1,73 +1,103 @@
1
- require 'mscorlib'
2
- require 'term/ansicolor'
3
-
4
- ## add the trailing m because some of the rspec output spans multiple lines
5
- ANSI_REGEXP = /\e\[(.+?)m(.+?)(?=(\e\[0m|\z))/m
6
- SsC=System::ConsoleColor
7
- SC = System::Console
8
-
9
- class String
10
- include Term::ANSIColor
11
- end
12
-
13
- module IronTermAnsiColor
14
- module Version
15
- MAJOR=0
16
- MINOR=0
17
- PATCH=1
18
- STRING="#{MAJOR}.#{MINOR}.#{PATCH}"
19
- end
20
- end
21
-
22
- class IO
23
- alias_method :original_write, :write
24
- alias_method :original_puts, :puts
25
-
26
- def puts(*args)
27
- rewrite(*args) { |text| original_puts text }
28
- nil
29
- end
30
-
31
- def write(*args)
32
- rewrite(*args) { |text| original_write text }
33
- end
34
-
35
- private
36
- def extract_ansi_data(clr, txt)
37
- fg_color_map = Hash[30,SsC.black,31,SsC.red,32,SsC.dark_green,33,SsC.dark_yellow,34,SsC.dark_blue,35,SsC.dark_magenta,
38
- 36,SsC.dark_cyan,37,SsC.gray]
39
- bg_color_map = Hash[40,SsC.black,41,SsC.dark_red,42,SsC.dark_green,43,SsC.dark_yellow,44,SsC.dark_blue,45,SsC.dark_magenta,
40
- 46,SsC.dark_cyan,47,SsC.gray]
41
-
42
- #matches = ANSI_REGEXP.match(arg)
43
-
44
- fg_color = fg_color_map[clr] || SC.foreground_color
45
- bg_color = bg_color_map[clr] || SC.background_color
46
-
47
- { :foreground => fg_color, :background => bg_color,:text => txt}
48
- end
49
-
50
- def rewrite(*args, &b)
51
- raise ArgumentError, "needs a block" unless b
52
- result=0
53
- args.each do |arg|
54
- fg_color = SC.foreground_color
55
- bg_color = SC.background_color
56
-
57
- ##dkb
58
- data = if ANSI_REGEXP =~ arg
59
- extract_ansi_data($1.to_i, $2)
60
- else
61
- {:text => arg}
62
- end
63
-
64
- SC.foreground_color = data[:foreground] || fg_color
65
- SC.background_color = data[:background] || bg_color
66
- result = b.call data[:text]
67
- SC.background_color = bg_color
68
- SC.foreground_color = fg_color
69
- end
70
- result
71
- end
72
-
73
- end
1
+ require 'mscorlib'
2
+ require 'term/ansicolor'
3
+
4
+ class String
5
+ include Term::ANSIColor
6
+ end
7
+
8
+ module IronTermAnsiColor
9
+ include System
10
+ module Version
11
+ MAJOR=0
12
+ MINOR=0
13
+ PATCH=3
14
+ STRING="#{MAJOR}.#{MINOR}.#{PATCH}"
15
+ end
16
+
17
+ ANSI_REGEXP = /\e\[([1349][0-7][0-7]?|[01])m/
18
+
19
+ FGCOLORS = {
20
+ 30 => ConsoleColor.black,
21
+ 31 => ConsoleColor.dark_red,
22
+ 32 => ConsoleColor.dark_green,
23
+ 33 => ConsoleColor.dark_yellow,
24
+ 34 => ConsoleColor.dark_blue,
25
+ 35 => ConsoleColor.dark_magenta,
26
+ 36 => ConsoleColor.dark_cyan,
27
+ 37 => ConsoleColor.gray,
28
+ 90 => ConsoleColor.dark_gray,
29
+ 91 => ConsoleColor.red,
30
+ 92 => ConsoleColor.green,
31
+ 93 => ConsoleColor.yellow,
32
+ 94 => ConsoleColor.blue,
33
+ 95 => ConsoleColor.magenta,
34
+ 96 => ConsoleColor.cyan,
35
+ 97 => ConsoleColor.white
36
+ }
37
+
38
+ BGCOLORS = {
39
+ 40 => ConsoleColor.black,
40
+ 41 => ConsoleColor.dark_red,
41
+ 42 => ConsoleColor.dark_green,
42
+ 43 => ConsoleColor.dark_yellow,
43
+ 44 => ConsoleColor.dark_blue,
44
+ 45 => ConsoleColor.dark_magenta,
45
+ 46 => ConsoleColor.dark_cyan,
46
+ 47 => ConsoleColor.gray,
47
+ 100 => ConsoleColor.dark_gray,
48
+ 101 => ConsoleColor.red,
49
+ 102 => ConsoleColor.green,
50
+ 103 => ConsoleColor.yellow,
51
+ 104 => ConsoleColor.blue,
52
+ 105 => ConsoleColor.magenta,
53
+ 106 => ConsoleColor.cyan,
54
+ 107 => ConsoleColor.white
55
+ }
56
+
57
+ def set_color(num)
58
+ if num == 0
59
+ Console.reset_color
60
+ elsif num == 1
61
+ #since we can't do bold, invert the colors
62
+ bg = Console.background_color
63
+ Console.background_color = Console.foreground_color
64
+ Console.foreground_color = bg
65
+ else
66
+ Console.foreground_color = FGCOLORS[num] || Console.foreground_color
67
+ Console.background_color = BGCOLORS[num] || Console.background_color
68
+ end
69
+ end
70
+ end
71
+
72
+ class IO
73
+ include IronTermAnsiColor
74
+
75
+ def puts(*args)
76
+ if args.empty?
77
+ syswrite "\n"
78
+ else
79
+ args.each do |str|
80
+ write(str)
81
+ syswrite "\n"
82
+ end
83
+ end
84
+ nil
85
+ end
86
+
87
+ def write(str)
88
+ result = 0
89
+ str = str.to_s
90
+ match = ANSI_REGEXP.match(str)
91
+ if match.nil?
92
+ #no ansi code in string
93
+ result += syswrite str
94
+ else
95
+ #write what comes before the ansi code in the current color
96
+ result += syswrite str[0, match.begin(1) - 2]
97
+ set_color(match[1].to_i)
98
+ #write what comes after the ansi code in the new color
99
+ result += write(str[(match.end(1) + 1)..-1])
100
+ end
101
+ result
102
+ end
103
+ end
@@ -1,73 +1,65 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "IronTermANSIColor", "when given a string with ANSI background color control characters" do
4
-
5
- before(:all) do
6
- @original_bgcolor = System::ConsoleColor.Gray
7
- end
8
-
9
- it "should set the background color to black when doing a puts of a string with only black background ANSI control code and reset the background color after" do
10
- string = "Black".on_black
11
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
12
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.Black)
13
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
14
- puts string
15
- end
16
-
17
- it "should set the background color to dark red when doing a puts of a string with only red background ANSI control code and reset the background color after" do
18
- string = "Red".on_red
19
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
20
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkRed)
21
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
22
- puts string
23
- end
24
-
25
- it "should set the background color to dark green when doing a puts of a string with only green background ANSI control code and reset the background color after" do
26
- string = "Green".on_green
27
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
28
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkGreen)
29
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
30
- puts string
31
- end
32
-
33
- it "should set the background color to dark yellow when doing a puts of a string with only yellow background ANSI control code and reset the background color after" do
34
- string = "Yellow".on_yellow
35
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
36
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkYellow)
37
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
38
- puts string
39
- end
40
-
41
- it "should set the background color to dark blue when doing a puts of a string with only blue background ANSI control code and reset the background color after" do
42
- string = "Blue".on_blue
43
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
44
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkBlue)
45
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
46
- puts string
47
- end
48
-
49
- it "should set the background color to dark magenta when doing a puts of a string with only magenta background ANSI control code and reset the background color after" do
50
- string = "Magenta".on_magenta
51
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
52
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkMagenta)
53
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
54
- puts string
55
- end
56
-
57
- it "should set the background color to dark cyan when doing a puts of a string with only cyan background ANSI control code and reset the background color after" do
58
- string = "Cyan".on_cyan
59
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
60
- System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkCyan)
61
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
62
- puts string
63
- end
64
-
65
- it "should set the background color to gray when doing a puts of a string with only white background ANSI control code and reset the background color after" do
66
- string = "Gray".on_white
67
- System::Console.should_receive(:background_color).at_least(:once).and_return(@original_bgcolor)
68
- System::Console.should_receive(:background_color=).exactly(3).times.with(System::ConsoleColor.Gray)
69
- System::Console.should_receive(:background_color=).at_least(:once).with(@original_bgcolor)
70
- puts string
71
- end
72
- end
73
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "IronTermANSIColor", "when given a string with ANSI background color control characters" do
4
+
5
+ before(:all) do
6
+ @original_bgcolor = System::ConsoleColor.Gray
7
+ end
8
+
9
+ it "should set the background color to black when doing a puts of a string with only black background ANSI control code and reset the background color after" do
10
+ string = "Black".on_black
11
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.Black)
12
+ System::Console.should_receive(:reset_color).at_least(:once)
13
+ puts string
14
+ end
15
+
16
+ it "should set the background color to dark red when doing a puts of a string with only red background ANSI control code and reset the background color after" do
17
+ string = "Red".on_red
18
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkRed)
19
+ System::Console.should_receive(:reset_color).at_least(:once)
20
+ puts string
21
+ end
22
+
23
+ it "should set the background color to dark green when doing a puts of a string with only green background ANSI control code and reset the background color after" do
24
+ string = "Green".on_green
25
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkGreen)
26
+ System::Console.should_receive(:reset_color).at_least(:once)
27
+ puts string
28
+ end
29
+
30
+ it "should set the background color to dark yellow when doing a puts of a string with only yellow background ANSI control code and reset the background color after" do
31
+ string = "Yellow".on_yellow
32
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkYellow)
33
+ System::Console.should_receive(:reset_color).at_least(:once)
34
+ puts string
35
+ end
36
+
37
+ it "should set the background color to dark blue when doing a puts of a string with only blue background ANSI control code and reset the background color after" do
38
+ string = "Blue".on_blue
39
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkBlue)
40
+ System::Console.should_receive(:reset_color).at_least(:once)
41
+ puts string
42
+ end
43
+
44
+ it "should set the background color to dark magenta when doing a puts of a string with only magenta background ANSI control code and reset the background color after" do
45
+ string = "Magenta".on_magenta
46
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkMagenta)
47
+ System::Console.should_receive(:reset_color).at_least(:once)
48
+ puts string
49
+ end
50
+
51
+ it "should set the background color to dark cyan when doing a puts of a string with only cyan background ANSI control code and reset the background color after" do
52
+ string = "Cyan".on_cyan
53
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.DarkCyan)
54
+ System::Console.should_receive(:reset_color).at_least(:once)
55
+ puts string
56
+ end
57
+
58
+ it "should set the background color to gray when doing a puts of a string with only white background ANSI control code and reset the background color after" do
59
+ string = "Gray".on_white
60
+ System::Console.should_receive(:background_color=).once.with(System::ConsoleColor.Gray)
61
+ System::Console.should_receive(:reset_color).at_least(:once)
62
+ puts string
63
+ end
64
+ end
65
+
@@ -1,73 +1,65 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "IronTermANSIColor", "when given a string with ANSI foreground color control characters" do
4
-
5
- before(:all) do
6
- @original_fgcolor = System::ConsoleColor.Gray
7
- end
8
-
9
- it "should set the foreground color to black when doing a puts of a string with only blackforeground ANSI control code and reset the foreground color after" do
10
- string = "Black".black
11
- System::Console.should_receive(:foreground_color).twice.and_return(@original_fgcolor)
12
- System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.black)
13
- System::Console.should_receive(:foreground_color=).at_least(3).times.with(@original_fgcolor)
14
- puts string
15
- end
16
-
17
- it "should set the foreground color to dark red when doing a puts of a string with only redforeground ANSI control code and reset the foreground color after" do
18
- string = "Red".red
19
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
20
- System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.red)
21
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
22
- puts string
23
- end
24
-
25
- it "should set the foreground color to dark green when doing a puts of a string with only greenforeground ANSI control code and reset the foreground color after" do
26
- string = "Green".green
27
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
28
- System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.dark_green)
29
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
30
- puts string
31
- end
32
-
33
- it "should set the foreground color to dark yellow when doing a puts of a string with only yellowforeground ANSI control code and reset the foreground color after" do
34
- string = "Yellow".yellow
35
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
36
- System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.DarkYellow)
37
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
38
- puts string
39
- end
40
-
41
- it "should set the foreground color to dark blue when doing a puts of a string with only blueforeground ANSI control code and reset the foreground color after" do
42
- string = "Blue".blue
43
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
44
- System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.DarkBlue)
45
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
46
- puts string
47
- end
48
-
49
- it "should set the foreground color to dark magenta when doing a puts of a string with only magentaforeground ANSI control code and reset the foreground color after" do
50
- string = "Magenta".magenta
51
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
52
- System::Console.should_receive(:foreground_color=).at_least(:once).with(System::ConsoleColor.DarkMagenta)
53
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
54
- puts string
55
- end
56
-
57
- it "should set the foreground color to dark cyan when doing a puts of a string with only cyanforeground ANSI control code and reset the foreground color after" do
58
- string = "Cyan".cyan
59
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
60
- System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.DarkCyan)
61
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
62
- puts string
63
- end
64
-
65
- it "should set the foreground color to gray when doing a puts of a string with only whiteforeground ANSI control code and reset the foreground color after" do
66
- string = "Gray".white
67
- System::Console.should_receive(:foreground_color).at_least(:once).and_return(@original_fgcolor)
68
- System::Console.should_receive(:foreground_color=).at_least(:once).with(System::ConsoleColor.Gray)
69
- System::Console.should_receive(:foreground_color=).at_least(:once).with(@original_fgcolor)
70
- puts string
71
- end
72
- end
73
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "IronTermANSIColor", "when given a string with ANSI foreground color control characters" do
4
+
5
+ before(:all) do
6
+ @original_fgcolor = System::ConsoleColor.Gray
7
+ end
8
+
9
+ it "should set the foreground color to black when doing a puts of a string with only blackforeground ANSI control code and reset the foreground color after" do
10
+ string = "Black".black
11
+ System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.black)
12
+ System::Console.should_receive(:reset_color).at_least(:once)
13
+ puts string
14
+ end
15
+
16
+ it "should set the foreground color to dark red when doing a puts of a string with only redforeground ANSI control code and reset the foreground color after" do
17
+ string = "Red".red
18
+ System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.dark_red)
19
+ System::Console.should_receive(:reset_color).at_least(:once)
20
+ puts string
21
+ end
22
+
23
+ it "should set the foreground color to dark green when doing a puts of a string with only greenforeground ANSI control code and reset the foreground color after" do
24
+ string = "Green".green
25
+ System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.dark_green)
26
+ System::Console.should_receive(:reset_color).at_least(:once)
27
+ puts string
28
+ end
29
+
30
+ it "should set the foreground color to dark yellow when doing a puts of a string with only yellowforeground ANSI control code and reset the foreground color after" do
31
+ string = "Yellow".yellow
32
+ System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.DarkYellow)
33
+ System::Console.should_receive(:reset_color).at_least(:once)
34
+ puts string
35
+ end
36
+
37
+ it "should set the foreground color to dark blue when doing a puts of a string with only blueforeground ANSI control code and reset the foreground color after" do
38
+ string = "Blue".blue
39
+ System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.DarkBlue)
40
+ System::Console.should_receive(:reset_color).at_least(:once)
41
+ puts string
42
+ end
43
+
44
+ it "should set the foreground color to dark magenta when doing a puts of a string with only magentaforeground ANSI control code and reset the foreground color after" do
45
+ string = "Magenta".magenta
46
+ System::Console.should_receive(:foreground_color=).at_least(:once).with(System::ConsoleColor.DarkMagenta)
47
+ System::Console.should_receive(:reset_color).at_least(:once)
48
+ puts string
49
+ end
50
+
51
+ it "should set the foreground color to dark cyan when doing a puts of a string with only cyanforeground ANSI control code and reset the foreground color after" do
52
+ string = "Cyan".cyan
53
+ System::Console.should_receive(:foreground_color=).once.with(System::ConsoleColor.DarkCyan)
54
+ System::Console.should_receive(:reset_color).at_least(:once)
55
+ puts string
56
+ end
57
+
58
+ it "should set the foreground color to gray when doing a puts of a string with only whiteforeground ANSI control code and reset the foreground color after" do
59
+ string = "Gray".white
60
+ System::Console.should_receive(:foreground_color=).at_least(:once).with(System::ConsoleColor.Gray)
61
+ System::Console.should_receive(:reset_color).at_least(:once)
62
+ puts string
63
+ end
64
+ end
65
+
@@ -1,10 +1,10 @@
1
- require 'spec'
2
-
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- require 'rubygems'
6
- require 'iron-term-ansicolor'
7
-
8
- Spec::Runner.configure do |config|
9
-
10
- end
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'rubygems'
6
+ require 'iron-term-ansicolor'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron-term-ansicolor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Green
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2009-10-30 00:00:00 -04:00
13
+ date: 2010-03-02 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  version_requirement:
20
20
  version_requirements: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - '>='
22
+ - - ">="
23
23
  - !ruby/object:Gem::Version
24
24
  version: 1.0.4
25
25
  version:
@@ -54,15 +54,15 @@ require_paths:
54
54
  - lib
55
55
  required_ruby_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - '>='
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 1.8.6
60
60
  version:
61
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - '>='
63
+ - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: !str 0
65
+ version: "0"
66
66
  version:
67
67
  requirements: []
68
68
  rubyforge_project: iron-term-ansicolor