harleytt-ansitags 0.1.4

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/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ coverage
3
+ rdoc
4
+ pkg
5
+ *~
6
+ tmp/*
7
+ *.swp
8
+ *.swo
9
+ *.gem
10
+
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm @ansitags --create
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ gem 'rspec', "~> 1.3.1"
3
+
data/Gemfile.lock ADDED
@@ -0,0 +1,10 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ rspec (1.3.2)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ rspec (~> 1.3.1)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 David Trasbo
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.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = ANSI Tags
2
+
3
+ Converts ANSI codes to HTML tags.
4
+
5
+ == Installation
6
+
7
+ sudo gem install harleytt-ansitags
8
+
9
+ == Usage
10
+
11
+ "\e[92m\e[1mgreen bold text\e[0m".ansi_to_html
12
+ => "<pre><span style="color: #00FF00"><span style="font-weight: bold;">green bold text</span></span></pre>"
13
+
14
+ That's basically it. ANSI Tags is capable of converting nearly all the ANSI
15
+ codes mentioned on Wikipedia[http://en.wikipedia.org/wiki/ANSI_escape_code]
16
+ under "SGR (Select Graphic Rendition) parameters" except "Intensity: Faint",
17
+ Blink: Slow", "Blink: Rapid", "Underline: Double", "Blink: off", and "Image:
18
+ Positive". But you won't need any of them, so that's fine.
19
+
20
+ == Contribution
21
+
22
+ 1. Fork the project.
23
+ 2. Make your feature addition or bug fix.
24
+ 3. Add tests for it. This is important so I don't break it in a
25
+ future version unintentionally.
26
+ 4. Commit, do not mess with rakefile, version, or history.
27
+ (if you want to have your own version, that is fine but
28
+ bump version in a commit by itself I can ignore when I pull)
29
+ 5. Send me a pull request. Bonus points for topic branches.
30
+
31
+ == Copyright
32
+
33
+ Copyright (c) 2010 David Trasbo. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+
6
+ #require 'spec/rake/spectask'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
data/ansitags.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'harleytt-ansitags'
5
+ s.version = "0.1.4"
6
+ s.authors = ["David Trasbo"]
7
+ s.description = "Converts ANSI codes to HTML tags"
8
+ s.summary = "#{s.name}-#{s.version}"
9
+ s.email = "harley.trung@gmail.com"
10
+ s.homepage = "http://github.com/harleyttd/#{s.name}"
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.rdoc_options = ["--charset=UTF-8"]
18
+ s.require_paths = ["lib"]
19
+ s.rubygems_version = "1.5.3"
20
+ end
21
+
data/bin/ansitags ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'ansitags'
5
+ ansi = STDIN.read
6
+ puts ansi.ansi_to_html
@@ -0,0 +1,40 @@
1
+ diff --git a/.gitignore b/.gitignore
2
+ index 00c0b86..750b2d4 100644
3
+ --- a/.gitignore
4
+ +++ b/.gitignore
5
+ @@ -1,5 +1,9 @@
6
+ -*.sw?
7
+ .DS_Store
8
+ coverage
9
+ rdoc
10
+ pkg
11
+ +*~
12
+ +tmp/*
13
+ +*.swp
14
+ +*.swo
15
+ +
16
+ diff --git a/bin/ansitags b/bin/ansitags
17
+ new file mode 100755
18
+ index 0000000..3f1c918
19
+ --- /dev/null
20
+ +++ b/bin/ansitags
21
+ @@ -0,0 +1,6 @@
22
+ +#!/usr/bin/env ruby
23
+ +$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
24
+ +
25
+ +require 'ansitags'
26
+ +ansi = STDIN.read
27
+ +puts ansi.ansi_to_html
28
+ diff --git a/lib/ansitags.rb b/lib/ansitags.rb
29
+ index 4e69627..d619a77 100644
30
+ --- a/lib/ansitags.rb
31
+ +++ b/lib/ansitags.rb
32
+ @@ -27,7 +27,7 @@ class String
33
+ current_foreground_color = low_intensity_colors[0]
34
+ current_background_color = high_intensity_colors[7]
35
+ 
36
+ - '<pre>' + self.gsub('&', '&amp;').gsub('"', '&quot;').gsub('<', '&lt;').gsub('>', '&gt;').gsub(/\\e\[(\d+)m/) do |ansi_code|
37
+ + '<pre>' + self.gsub('&', '&amp;').gsub('"', '&quot;').gsub('<', '&lt;').gsub('>', '&gt;').gsub(/\e\[(\d*)m/) do |ansi_code|
38
+ case $1.to_i
39
+ when 0 # reset to default values
40
+ end_tags = start_tags
@@ -0,0 +1,41 @@
1
+ <pre><span style="font-weight: bold;">diff --git a/.gitignore b/.gitignore</span>
2
+ <span style="font-weight: bold;">index 00c0b86..750b2d4 100644</span>
3
+ <span style="font-weight: bold;">--- a/.gitignore</span>
4
+ <span style="font-weight: bold;">+++ b/.gitignore</span>
5
+ <span style="color: #008080;">@@ -1,5 +1,9 @@</span>
6
+ <span style="color: #800000;">-*.sw?</span>
7
+ .DS_Store
8
+ coverage
9
+ rdoc
10
+ pkg
11
+ <span style="color: #008000;">+</span><span style="color: #008000;">*~</span>
12
+ <span style="color: #008000;">+</span><span style="color: #008000;">tmp/*</span>
13
+ <span style="color: #008000;">+</span><span style="color: #008000;">*.swp</span>
14
+ <span style="color: #008000;">+</span><span style="color: #008000;">*.swo</span>
15
+ <span style="background-color: #800000;">+</span>
16
+ <span style="font-weight: bold;">diff --git a/bin/ansitags b/bin/ansitags</span>
17
+ <span style="font-weight: bold;">new file mode 100755</span>
18
+ <span style="font-weight: bold;">index 0000000..3f1c918</span>
19
+ <span style="font-weight: bold;">--- /dev/null</span>
20
+ <span style="font-weight: bold;">+++ b/bin/ansitags</span>
21
+ <span style="color: #008080;">@@ -0,0 +1,6 @@</span>
22
+ <span style="color: #008000;">+</span><span style="color: #008000;">#!/usr/bin/env ruby</span>
23
+ <span style="color: #008000;">+</span><span style="color: #008000;">$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')</span>
24
+ <span style="color: #008000;">+</span>
25
+ <span style="color: #008000;">+</span><span style="color: #008000;">require 'ansitags'</span>
26
+ <span style="color: #008000;">+</span><span style="color: #008000;">ansi = STDIN.read</span>
27
+ <span style="color: #008000;">+</span><span style="color: #008000;">puts ansi.ansi_to_html</span>
28
+ <span style="font-weight: bold;">diff --git a/lib/ansitags.rb b/lib/ansitags.rb</span>
29
+ <span style="font-weight: bold;">index 4e69627..d619a77 100644</span>
30
+ <span style="font-weight: bold;">--- a/lib/ansitags.rb</span>
31
+ <span style="font-weight: bold;">+++ b/lib/ansitags.rb</span>
32
+ <span style="color: #008080;">@@ -27,7 +27,7 @@</span> class String
33
+ current_foreground_color = low_intensity_colors[0]
34
+ current_background_color = high_intensity_colors[7]
35
+
36
+ <span style="color: #800000;">- '&lt;pre&gt;' + self.gsub('&amp;', '&amp;amp;').gsub('&quot;', '&amp;quot;').gsub('&lt;', '&amp;lt;').gsub('&gt;', '&amp;gt;').gsub(/\\e\[(\d+)m/) do |ansi_code|</span>
37
+ <span style="color: #008000;">+</span><span style="color: #008000;"> '&lt;pre&gt;' + self.gsub('&amp;', '&amp;amp;').gsub('&quot;', '&amp;quot;').gsub('&lt;', '&amp;lt;').gsub('&gt;', '&amp;gt;').gsub(/\e\[(\d*)m/) do |ansi_code|</span>
38
+ case $1.to_i
39
+ when 0 # reset to default values
40
+ end_tags = start_tags
41
+ </pre>
data/lib/ansitags.rb ADDED
@@ -0,0 +1,91 @@
1
+ class String
2
+ def ansi_to_html
3
+ start_tags = 0
4
+
5
+ low_intensity_colors = [
6
+ '000000',
7
+ '800000',
8
+ '008000',
9
+ '808000',
10
+ '000080',
11
+ '000080',
12
+ '008080',
13
+ 'C0C0C0'
14
+ ]
15
+
16
+ high_intensity_colors = [
17
+ '808080',
18
+ 'FF0000',
19
+ '00FF00',
20
+ 'FFFF00',
21
+ '0000FF',
22
+ 'FF00FF',
23
+ '00FFFF',
24
+ 'FFFFFF'
25
+ ]
26
+
27
+ current_foreground_color = low_intensity_colors[0]
28
+ current_background_color = high_intensity_colors[7]
29
+
30
+ '<pre>' + self.gsub('&', '&amp;').gsub('"', '&quot;').gsub('<', '&lt;').gsub('>', '&gt;').gsub(/\e\[(\d*)m/) do |ansi_code|
31
+ case $1.to_i
32
+ when 0 # reset to default values
33
+ end_tags = start_tags
34
+ start_tags = 0
35
+ '</span>' * end_tags
36
+ when 1 # bold
37
+ start_tags += 1
38
+ '<span style="font-weight: bold;">'
39
+ when 3 # italic
40
+ start_tags += 1
41
+ '<span style="font-style: italic;">'
42
+ when 4 # underlined
43
+ start_tags += 1
44
+ '<span style="text-decoration: underline;">'
45
+ when 7 # swap foreground and background colors
46
+ start_tags += 1
47
+ new_foreground_color = current_background_color
48
+ new_background_color = current_foreground_color
49
+ current_foreground_color = new_foreground_color
50
+ current_background_color = new_background_color
51
+ "<span style=\"color: ##{new_foreground_color}; background-color: ##{new_background_color};\">"
52
+ when 8 # hidden
53
+ start_tags += 1
54
+ '<span style="visibility: hidden;">'
55
+ when 22 # normal weight
56
+ start_tags += 1
57
+ '<span style="font-weight: normal;">'
58
+ when 24 # not underlined
59
+ start_tags += 1
60
+ '<span style="text-decoration: none;">'
61
+ when 28 # not hidden
62
+ start_tags += 1
63
+ '<span style="visibility: visible;">'
64
+ when 30..37 # low intensity foreground colors
65
+ start_tags += 1
66
+ "<span style=\"color: ##{current_foreground_color = low_intensity_colors[$1.to_i - 30]};\">"
67
+ when 39 # reset foreground color to default low intensity color
68
+ start_tags += 1
69
+ "<span style=\"color: ##{current_foreground_color = low_intensity_colors[0]};\">"
70
+ when 40..47 # low intensity background colors
71
+ start_tags += 1
72
+ "<span style=\"background-color: ##{current_background_color = low_intensity_colors[$1.to_i - 40]};\">"
73
+ when 49 # reset background color to default low intensity color
74
+ start_tags += 1
75
+ "<span style=\"background-color: ##{current_background_color = low_intensity_colors[7]};\">"
76
+ when 90..97 # high intensity foreground colors
77
+ start_tags += 1
78
+ "<span style=\"color: ##{current_foreground_color = high_intensity_colors[$1.to_i - 90]};\">"
79
+ when 99 # reset foreground color to default high intensity color
80
+ start_tags += 1
81
+ "<span style=\"color: ##{current_foreground_color = high_intensity_colors[0]};\">"
82
+ when 100..107 # high intensity background colors
83
+ start_tags += 1
84
+ "<span style=\"background-color: ##{current_background_color = high_intensity_colors[$1.to_i - 100]};\">"
85
+ when 109 # reset background color to default high intensity color
86
+ start_tags += 1
87
+ "<span style=\"background-color: ##{current_background_color = high_intensity_colors[7]};\">"
88
+ end
89
+ end + '</span>' * start_tags + '</pre>'
90
+ end
91
+ end
@@ -0,0 +1,85 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe String do
4
+ describe '#ansi_to_html' do
5
+ it 'should wrap everything in <pre> tags' do
6
+ 'hello world'.ansi_to_html.should == '<pre>hello world</pre>'
7
+ end
8
+
9
+ it 'should escape HTML' do
10
+ '<>&"'.ansi_to_html.should == '<pre>&lt;&gt;&amp;&quot;</pre>'
11
+ end
12
+
13
+ it 'should set font weight to bold' do
14
+ "\e[1mbold text\e[0m".ansi_to_html.should == '<pre><span style="font-weight: bold;">bold text</span></pre>'
15
+ end
16
+
17
+ it 'should set font style to italic' do
18
+ "\e[3mitalic text\e[0m".ansi_to_html.should == '<pre><span style="font-style: italic;">italic text</span></pre>'
19
+ end
20
+
21
+ it 'should set text decoration to underline' do
22
+ "\e[4munderlined text\e[0m".ansi_to_html.should == '<pre><span style="text-decoration: underline;">underlined text</span></pre>'
23
+ end
24
+
25
+ it 'should swap foreground and background colors' do
26
+ "\e[32mgreen foreground color. \e[7mgreen background color.\e[0m".ansi_to_html.should == '<pre><span style="color: #008000;">green foreground color. <span style="color: #FFFFFF; background-color: #008000;">green background color.</span></span></pre>'
27
+ end
28
+
29
+ it 'should set visibility to hidden' do
30
+ "\e[8mhidden text\e[0m".ansi_to_html.should == '<pre><span style="visibility: hidden;">hidden text</span></pre>'
31
+ end
32
+
33
+ it 'should font weight to normal' do
34
+ "\e[22mnormal text\e[0m".ansi_to_html.should == '<pre><span style="font-weight: normal;">normal text</span></pre>'
35
+ end
36
+
37
+ it 'should set text decoration to none' do
38
+ "\e[24mnon-decorated text\e[0m".ansi_to_html.should == '<pre><span style="text-decoration: none;">non-decorated text</span></pre>'
39
+ end
40
+
41
+ it 'should not hide text' do
42
+ "\e[28mvisible text\e[0m".ansi_to_html.should == '<pre><span style="visibility: visible;">visible text</span></pre>'
43
+ end
44
+
45
+ it 'should set foreground color to a low intensity color' do
46
+ "\e[31mdark red text\e[0m".ansi_to_html.should == '<pre><span style="color: #800000;">dark red text</span></pre>'
47
+ end
48
+
49
+ it 'should set foreground color to the default low intensity color' do
50
+ "\e[39mblack text\e[0m".ansi_to_html == '<pre><span style="color: #000000;">black text</span></pre>'
51
+ end
52
+
53
+ it 'should set background color to a low intensity color' do
54
+ "\e[42mtext with green background\e[0m".ansi_to_html.should == '<pre><span style="background-color: #008000;">text with green background</span></pre>'
55
+ end
56
+
57
+ it 'should set background color to the default low intensity color' do
58
+ "\e[49mtext with white background\e[0m".ansi_to_html.should == '<pre><span style="background-color: #C0C0C0;">text with white background</span></pre>'
59
+ end
60
+
61
+ it 'should set foreground color to a high intensity color' do
62
+ "\e[93mvery bright yellow text\e[0m".ansi_to_html.should == '<pre><span style="color: #FFFF00;">very bright yellow text</span></pre>'
63
+ end
64
+
65
+ it 'should set foreground color to the default high intensity color' do
66
+ "\e[99mgray text\e[0m".ansi_to_html.should == '<pre><span style="color: #808080;">gray text</span></pre>'
67
+ end
68
+
69
+ it 'should set background color to a high intensity color' do
70
+ "\e[104mbright blue background\e[0m".ansi_to_html.should == '<pre><span style="background-color: #0000FF;">bright blue background</span></pre>'
71
+ end
72
+
73
+ it 'should set background color to the default high intensity color' do
74
+ "\e[109mtext with white background\e[0m".ansi_to_html.should == '<pre><span style="background-color: #FFFFFF;">text with white background</span></pre>'
75
+ end
76
+
77
+ it 'should close unclosed tags' do
78
+ "\e[92m\e[1mgreen bold text".ansi_to_html.should == '<pre><span style="color: #00FF00;"><span style="font-weight: bold;">green bold text</span></span></pre>'
79
+ end
80
+
81
+ it 'should remove unsupported codes' do
82
+ "\e[5mdo not make text blink. no, seriously".ansi_to_html.should == '<pre>do not make text blink. no, seriously</pre>'
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'ansitags'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harleytt-ansitags
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 4
9
+ version: 0.1.4
10
+ platform: ruby
11
+ authors:
12
+ - David Trasbo
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-01 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Converts ANSI codes to HTML tags
22
+ email: harley.trung@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .bundle/config
32
+ - .document
33
+ - .gitignore
34
+ - .rvmrc
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - ansitags.gemspec
42
+ - bin/ansitags
43
+ - examples/sample.diff
44
+ - examples/sample.diff.html
45
+ - lib/ansitags.rb
46
+ - spec/ansitags_spec.rb
47
+ - spec/spec_helper.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/harleyttd/harleytt-ansitags
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: harleytt-ansitags-0.1.4
80
+ test_files:
81
+ - spec/ansitags_spec.rb
82
+ - spec/spec_helper.rb