iron-term-ansicolor 0.0.5-universal-dotnet

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +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.
data/Rakefile ADDED
@@ -0,0 +1,112 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'fileutils'
4
+ require 'rake/rdoctask'
5
+ require 'lib/iron-term-ansicolor'
6
+ require 'spec/rake/spectask'
7
+ Spec::Rake::SpecTask.new(:spec) do |spec|
8
+ spec.libs << 'lib' << 'spec'
9
+ spec.spec_files = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
13
+ spec.libs << 'lib' << 'spec'
14
+ spec.pattern = 'spec/**/*_spec.rb'
15
+ spec.rcov = true
16
+ end
17
+
18
+
19
+ task :default => :spec
20
+
21
+
22
+ ##############################################################################
23
+ # OPTIONS
24
+ ##############################################################################
25
+
26
+ PKG_NAME = 'iron-term-ansicolor'
27
+ PKG_VERSION = if File.exist?('VERSION.yml')
28
+ config = YAML.load(File.read('VERSION.yml'))
29
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
30
+ else
31
+ version = IronTermAnsiColor::Version::STRING
32
+ end
33
+ PKG_PLATFORM = Gem::Platform.new(["universal", "dotnet"])
34
+ AUTHORS = ['Will Green', 'David Blackmon', 'Ivan Porto Carrero', 'Danny Coates']
35
+ EMAIL = "will@hotgazpacho.org"
36
+ HOMEPAGE = "http://github.com/hotgazpacho/iron-term-ansicolor"
37
+ SUMMARY = "iron-term-ansicolor brings color output to IronRuby on Windows"
38
+
39
+ # These are the common rdoc options that are shared between generation of
40
+ # rdoc files using BOTH 'rake rdoc' and the installation by users of a
41
+ # RubyGem version which builds rdoc's along with its installation. Any
42
+ # rdoc options that are ONLY for developers running 'rake rdoc' should be
43
+ # added in the 'Rake::RDocTask' block below.
44
+ RDOC_OPTIONS = [
45
+ "--quiet",
46
+ "--title", SUMMARY,
47
+ "--main", "README.rdoc",
48
+ "--line-numbers"
49
+ ]
50
+
51
+ # Extra files outside of the lib dir that should be included with the rdocs.
52
+ RDOC_FILES = (%w( README.rdoc)).sort
53
+
54
+ # The full file list used for rdocs, tarballs, gems, and for generating the xmpp4r.gemspec.
55
+ PKG_FILES = (%w( Rakefile iron-term-ansicolor.gemspec ) + RDOC_FILES + Dir["{lib,spec}/**/*"]).sort
56
+
57
+ TEST_FILES = Dir["spec/**/*"].sort
58
+
59
+ # RDOC
60
+ #######
61
+ Rake::RDocTask.new do |rd|
62
+
63
+ # which dir should rdoc files be installed in?
64
+ rd.rdoc_dir = 'rdoc'
65
+ rd.title = "iron-term-ansicolor #{PKG_VERSION}"
66
+
67
+ # the full list of files to be included
68
+ rd.rdoc_files.include('README*')
69
+ rd.rdoc_files.include(RDOC_FILES, "lib/**/*.rb")
70
+
71
+ # the full list of options that are common between gem build
72
+ # and 'rake rdoc' build of docs.
73
+ rd.options = RDOC_OPTIONS
74
+
75
+ # Devs Only : Uncomment to also document private methods in the rdocs
76
+ # Please don't check this change in to the source repo.
77
+ #rd.options << '--all'
78
+
79
+ # Devs Only : Uncomment to generate dot (graphviz) diagrams along with rdocs.
80
+ # This requires that graphiz (dot) be installed as a local binary and on your path.
81
+ # See : http://www.graphviz.org/
82
+ # Please don't check this change in to the source repo as it introduces a binary dependency.
83
+ #rd.options << '--diagram'
84
+ #rd.options << '--fileboxes'
85
+
86
+ end
87
+
88
+ begin
89
+ require 'jeweler'
90
+ Jeweler::Tasks.new do |gem|
91
+ gem.name = PKG_NAME
92
+ gem.summary = SUMMARY
93
+ gem.description = SUMMARY
94
+ gem.email = EMAIL
95
+ gem.homepage = HOMEPAGE
96
+ gem.authors = AUTHORS
97
+ gem.platform = PKG_PLATFORM
98
+ gem.required_ruby_version = ">= 1.8.6"
99
+ gem.add_dependency 'term-ansicolor', ">= 1.0.4"
100
+ gem.add_development_dependency 'rspec'
101
+ gem.files = PKG_FILES
102
+ gem.test_files = TEST_FILES
103
+ gem.has_rdoc = true
104
+ gem.extra_rdoc_files = RDOC_FILES
105
+ gem.rdoc_options = RDOC_OPTIONS
106
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
107
+ end
108
+ Jeweler::GemcutterTasks.new
109
+ rescue LoadError
110
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
111
+ end
112
+
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{iron-term-ansicolor}
8
+ s.version = "0.0.5"
9
+ s.platform = Gem::Platform.new(["universal", "dotnet", nil])
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Will Green", "David Blackmon", "Ivan Porto Carrero", "Danny Coates"]
13
+ s.date = %q{2010-03-29}
14
+ s.description = %q{iron-term-ansicolor brings color output to IronRuby on Windows}
15
+ s.email = %q{will@hotgazpacho.org}
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "iron-term-ansicolor.gemspec",
23
+ "lib/iron-term-ansicolor.rb",
24
+ "spec/iron-term-ansicolor_simple_background_spec.rb",
25
+ "spec/iron-term-ansicolor_simple_foreground_spec.rb",
26
+ "spec/spec_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/hotgazpacho/iron-term-ansicolor}
29
+ s.rdoc_options = ["--quiet", "--title", "iron-term-ansicolor brings color output to IronRuby on Windows", "--main", "README.rdoc", "--line-numbers"]
30
+ s.require_paths = ["lib"]
31
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
32
+ s.rubygems_version = %q{1.3.5}
33
+ s.summary = %q{iron-term-ansicolor brings color output to IronRuby on Windows}
34
+ s.test_files = [
35
+ "spec/iron-term-ansicolor_simple_background_spec.rb",
36
+ "spec/iron-term-ansicolor_simple_foreground_spec.rb",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<term-ansicolor>, [">= 1.0.4"])
46
+ s.add_development_dependency(%q<rspec>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<term-ansicolor>, [">= 1.0.4"])
49
+ s.add_dependency(%q<rspec>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<term-ansicolor>, [">= 1.0.4"])
53
+ s.add_dependency(%q<rspec>, [">= 0"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,97 @@
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
+
11
+ ANSI_REGEXP = /\e\[([1349][0-7][0-7]?|[01])m/
12
+
13
+ FGCOLORS = {
14
+ 30 => ConsoleColor.black,
15
+ 31 => ConsoleColor.dark_red,
16
+ 32 => ConsoleColor.dark_green,
17
+ 33 => ConsoleColor.dark_yellow,
18
+ 34 => ConsoleColor.dark_blue,
19
+ 35 => ConsoleColor.dark_magenta,
20
+ 36 => ConsoleColor.dark_cyan,
21
+ 37 => ConsoleColor.gray,
22
+ 90 => ConsoleColor.dark_gray,
23
+ 91 => ConsoleColor.red,
24
+ 92 => ConsoleColor.green,
25
+ 93 => ConsoleColor.yellow,
26
+ 94 => ConsoleColor.blue,
27
+ 95 => ConsoleColor.magenta,
28
+ 96 => ConsoleColor.cyan,
29
+ 97 => ConsoleColor.white
30
+ }
31
+
32
+ BGCOLORS = {
33
+ 40 => ConsoleColor.black,
34
+ 41 => ConsoleColor.dark_red,
35
+ 42 => ConsoleColor.dark_green,
36
+ 43 => ConsoleColor.dark_yellow,
37
+ 44 => ConsoleColor.dark_blue,
38
+ 45 => ConsoleColor.dark_magenta,
39
+ 46 => ConsoleColor.dark_cyan,
40
+ 47 => ConsoleColor.gray,
41
+ 100 => ConsoleColor.dark_gray,
42
+ 101 => ConsoleColor.red,
43
+ 102 => ConsoleColor.green,
44
+ 103 => ConsoleColor.yellow,
45
+ 104 => ConsoleColor.blue,
46
+ 105 => ConsoleColor.magenta,
47
+ 106 => ConsoleColor.cyan,
48
+ 107 => ConsoleColor.white
49
+ }
50
+
51
+ def set_color(num)
52
+ if num == 0
53
+ Console.reset_color
54
+ elsif num == 1
55
+ #since we can't do bold, invert the colors
56
+ bg = Console.background_color
57
+ Console.background_color = Console.foreground_color
58
+ Console.foreground_color = bg
59
+ else
60
+ Console.foreground_color = FGCOLORS[num] || Console.foreground_color
61
+ Console.background_color = BGCOLORS[num] || Console.background_color
62
+ end
63
+ end
64
+ end
65
+
66
+ class IO
67
+ include IronTermAnsiColor
68
+
69
+ def puts(*args)
70
+ if args.empty?
71
+ syswrite "\n"
72
+ else
73
+ args.each do |str|
74
+ write(str)
75
+ syswrite "\n"
76
+ end
77
+ end
78
+ nil
79
+ end
80
+
81
+ def write(str)
82
+ result = 0
83
+ str = str.to_s
84
+ match = ANSI_REGEXP.match(str)
85
+ if match.nil?
86
+ #no ansi code in string
87
+ result += syswrite str
88
+ else
89
+ #write what comes before the ansi code in the current color
90
+ result += syswrite str[0, match.begin(1) - 2]
91
+ set_color(match[1].to_i)
92
+ #write what comes after the ansi code in the new color
93
+ result += write(str[(match.end(1) + 1)..-1])
94
+ end
95
+ result
96
+ end
97
+ end
@@ -0,0 +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=).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
+
@@ -0,0 +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=).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
+
@@ -0,0 +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
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iron-term-ansicolor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: universal-dotnet
6
+ authors:
7
+ - Will Green
8
+ - David Blackmon
9
+ - Ivan Porto Carrero
10
+ - Danny Coates
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2010-03-29 00:00:00 -04:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: term-ansicolor
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.0.4
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ type: :development
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ version:
37
+ description: iron-term-ansicolor brings color output to IronRuby on Windows
38
+ email: will@hotgazpacho.org
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - README.rdoc
45
+ - Rakefile
46
+ - iron-term-ansicolor.gemspec
47
+ - lib/iron-term-ansicolor.rb
48
+ - spec/iron-term-ansicolor_simple_background_spec.rb
49
+ - spec/iron-term-ansicolor_simple_foreground_spec.rb
50
+ - spec/spec_helper.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/hotgazpacho/iron-term-ansicolor
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --quiet
57
+ - --title
58
+ - iron-term-ansicolor brings color output to IronRuby on Windows
59
+ - --main
60
+ - README.rdoc
61
+ - --line-numbers
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.6
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: iron-term-ansicolor brings color output to IronRuby on Windows
82
+ test_files:
83
+ - spec/iron-term-ansicolor_simple_background_spec.rb
84
+ - spec/iron-term-ansicolor_simple_foreground_spec.rb
85
+ - spec/spec_helper.rb