├── .gitignore ├── .rspec ├── .rvmrc ├── COPYING ├── Gemfile ├── History.txt ├── README.rdoc ├── Rakefile ├── ansi2html.gemspec ├── bin └── ansi2html ├── examples ├── README.textile ├── summering_feil.html └── summering_feil.txt ├── lib └── ansi2html │ └── main.rb ├── npm_install_express.txt └── spec └── ansi2html └── main_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | pkg 3 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /.rvmrc: -------------------------------------------------------------------------------- 1 | rvm @ansi2html --create 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2011 Aslak Hellesøy 5 | Everyone is permitted to copy and distribute verbatim or modified 6 | copies of this license document, and changing it is allowed as long 7 | as the name is changed. 8 | 9 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 10 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 11 | 12 | 0. You just DO WHAT THE FUCK YOU WANT TO. 13 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | gemspec 3 | -------------------------------------------------------------------------------- /History.txt: -------------------------------------------------------------------------------- 1 | = 5.3.2 2 | 3 | Wah! Wah! Wah! Wah! Wah! Wah! -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = ansi2html 2 | 3 | You have class. You are a hipster. You ride a fixie bike to work and you are member of a Scotch Whisky club. 4 | When using a computer, you prefer minimalistic command line applications that output ANSI colours in your 5 | terminal that you have configured to have semi-transparent background with Frank Zappa background music and 6 | vim-like shortcuts that differentiates you from the common programmers. You are a big fish in a small pond. 7 | 8 | Your friends are not geeks like you, they have more important goals in their lives, but they admire you for being 9 | so smart, because you can write computer programs. Programs with ANSI colours even. And yet, they don't know how 10 | to use a terminal. 11 | 12 | You need a way to show your entourage the true power of ANSI colours. -A way that works with the iPad. 13 | 14 | You will just 15 | 16 | gem install ansi2html 17 | curl github.com/aslakhellesoy/ansi2html/raw/master/examples/summering_feil.txt | ansi2html --envelope > summering_feil.html 18 | open summering_feil.html 19 | 20 | OMG you have a LINUX machine so you will do {TODO WTF is the equivalent of open in LINUX} to open the file. 21 | ZOMFG you have WINDOWS. You'll figure out what to do. It works the same as a .htm file. 22 | 23 | HTML designers have a special option. Don't use --envelope. This will give you HTML with Scandinavian design instead. Just pump input in and 24 | stick the output in your new fancy
and
fancy page with CSS3 yo. (It will explode if you have rounded corners). Nobody 25 | does that anymore. Please. 26 | 27 | Let's tweet #ansi2html with links to pages that have ANSI in HTML now, ok? (I would, but my home page is under construction, besides 28 | I don't promote my own art because I am an artist). 29 | 30 | == HALP 31 | 32 | Send me a pull request if you fixed something. This will get you started (after you install ruby): 33 | 34 | gem install bundler && bundle install && rspec spec -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require 'rubygems' 3 | require 'bundler/setup' 4 | Bundler::GemHelper.install_tasks 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ansi2html.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'ansi2html' 5 | s.version = '5.3.4' 6 | s.authors = ["Aslak Hellesøy"] 7 | s.description = 'Convert ANSI escape sequences to styleable HTML markup' 8 | s.summary = "#{s.name}-#{s.version}" 9 | s.email = 'aslak.hellesoy@gmail.com' 10 | s.homepage = "http://github.com/aslakhellesoy/#{s.name}" 11 | 12 | s.add_development_dependency 'rspec', '~> 2.3.0' 13 | 14 | s.files = `git ls-files`.split("\n") 15 | s.test_files = `git ls-files -- {spec,features}/*`.split("\n") 16 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 17 | s.extra_rdoc_files = ["COPYING", "README.rdoc", "History.txt"] 18 | s.rdoc_options = ["--charset=UTF-8"] 19 | s.require_path = "lib" 20 | end 21 | 22 | -------------------------------------------------------------------------------- /bin/ansi2html: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib') 3 | 4 | require 'ansi2html/main' 5 | begin 6 | failure = ANSI2HTML::Main.execute 7 | Kernel.exit(1) if failure 8 | rescue SystemExit => e 9 | Kernel.exit(e.status) 10 | rescue Exception => e 11 | STDERR.puts("#{e.message} (#{e.class})") 12 | STDERR.puts(e.backtrace.join("\n")) 13 | Kernel.exit(1) 14 | end -------------------------------------------------------------------------------- /examples/README.textile: -------------------------------------------------------------------------------- 1 | h1. Examples 2 | 3 | When you have read the uber README you will know what to do. You should be able to recreate the .html file from the .txt file. 4 | That's an exercise for you. If you can't do it you should study harder. -------------------------------------------------------------------------------- /examples/summering_feil.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 37 | 38 |
Using the default profile...
39 | # language: no
40 | Egenskap: Summering
41 |   For å slippe å gjøre dumme feil
42 |   Som en regnskapsfører
43 |   Vil jeg kunne legge sammen
44 | 
45 |   Scenario: to tall              # examples/i18n/no/features/summering.feature:7
46 |     Gitt at jeg har tastet inn 5 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7
47 |     Og at jeg har tastet inn 7   # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7
48 |     Når jeg summerer             # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:11
49 |     Så skal resultatet være 12   # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:15
50 |       expected: 12,
51 |            got: 14 (using ==) (RSpec::Expectations::ExpectationNotMetError)
52 |       ./examples/i18n/no/features/step_definitons/kalkulator_steps.rb:16:in `/skal resultatet være (\d*)/'
53 |       examples/i18n/no/features/summering.feature:11:in `Så skal resultatet være 12'
54 | 
55 |   @iterasjon3
56 |   Scenario: tre tall             # examples/i18n/no/features/summering.feature:14
57 |     Gitt at jeg har tastet inn 5 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7
58 |     Og at jeg har tastet inn 7   # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7
59 |     Og at jeg har tastet inn 1   # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7
60 |     Når jeg summerer             # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:11
61 |     Så skal resultatet være 13   # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:15
62 |       expected: 13,
63 |            got: 16 (using ==) (RSpec::Expectations::ExpectationNotMetError)
64 |       ./examples/i18n/no/features/step_definitons/kalkulator_steps.rb:16:in `/skal resultatet være (\d*)/'
65 |       examples/i18n/no/features/summering.feature:19:in `Så skal resultatet være 13'
66 | 
67 | Failing Scenarios:
68 | cucumber examples/i18n/no/features/summering.feature:7 # Scenario: to tall
69 | cucumber examples/i18n/no/features/summering.feature:14 # Scenario: tre tall
70 | 
71 | 2 scenarios (2 failed)
72 | 9 steps (2 failed, 7 passed)
73 | 0m0.005s
74 | 
-------------------------------------------------------------------------------- /examples/summering_feil.txt: -------------------------------------------------------------------------------- 1 | Using the default profile... 2 | # language: no 3 | Egenskap: Summering 4 | For å slippe å gjøre dumme feil 5 | Som en regnskapsfører 6 | Vil jeg kunne legge sammen 7 | 8 | Scenario: to tall # examples/i18n/no/features/summering.feature:7 9 | Gitt at jeg har tastet inn 5 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7 10 | Og at jeg har tastet inn 7 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7 11 | Når jeg summerer # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:11 12 | Så skal resultatet være 12 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:15 13 |  expected: 12, 14 | got: 14 (using ==) (RSpec::Expectations::ExpectationNotMetError) 15 | ./examples/i18n/no/features/step_definitons/kalkulator_steps.rb:16:in `/skal resultatet være (\d*)/' 16 | examples/i18n/no/features/summering.feature:11:in `Så skal resultatet være 12' 17 | 18 | @iterasjon3 19 | Scenario: tre tall # examples/i18n/no/features/summering.feature:14 20 | Gitt at jeg har tastet inn 5 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7 21 | Og at jeg har tastet inn 7 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7 22 | Og at jeg har tastet inn 1 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:7 23 | Når jeg summerer # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:11 24 | Så skal resultatet være 13 # examples/i18n/no/features/step_definitons/kalkulator_steps.rb:15 25 |  expected: 13, 26 | got: 16 (using ==) (RSpec::Expectations::ExpectationNotMetError) 27 | ./examples/i18n/no/features/step_definitons/kalkulator_steps.rb:16:in `/skal resultatet være (\d*)/' 28 | examples/i18n/no/features/summering.feature:19:in `Så skal resultatet være 13' 29 | 30 | Failing Scenarios: 31 | cucumber examples/i18n/no/features/summering.feature:7 # Scenario: to tall 32 | cucumber examples/i18n/no/features/summering.feature:14 # Scenario: tre tall 33 | 34 | 2 scenarios (2 failed) 35 | 9 steps (2 failed, 7 passed) 36 | 0m0.005s 37 | -------------------------------------------------------------------------------- /lib/ansi2html/main.rb: -------------------------------------------------------------------------------- 1 | require 'strscan' 2 | 3 | module ANSI2HTML 4 | class Main 5 | COLOR = { 6 | '1' => 'bold', 7 | '30' => 'black', 8 | '31' => 'red', 9 | '32' => 'green', 10 | '33' => 'yellow', 11 | '34' => 'blue', 12 | '35' => 'magenta', 13 | '36' => 'cyan', 14 | '37' => 'white', 15 | '90' => 'grey' 16 | } 17 | 18 | def self.execute 19 | new(STDIN.read, STDOUT, ARGV.index('--envelope'), ARGV.index('--black')) 20 | end 21 | 22 | def initialize(ansi, out, envelope=false, black=false) 23 | if(envelope) 24 | background, color = black ? %w(black white) : %w(white black) 25 | out.print %{ 26 | 27 | 28 | 29 | 64 | 65 |
}
66 |       end
67 |       s = StringScanner.new(ansi.gsub("<", "<"))
68 |       while(!s.eos?)
69 |         if s.scan(/\e\[(3[0-7]|90|1)m/)
70 |           out.print(%{})
71 |         else
72 |           if s.scan(/\e\[0m/)
73 |             out.print(%{})
74 |           else
75 |             out.print(s.scan(/./m))
76 |           end
77 |         end
78 |       end
79 | 
80 |       if(envelope)
81 |         out.print %{
} 82 | end 83 | end 84 | end 85 | end -------------------------------------------------------------------------------- /npm_install_express.txt: -------------------------------------------------------------------------------- 1 | npm info it worked if it ends with ok 2 | npm info using npm@0.2.12-1 3 | npm info using node@v0.2.5 4 | npm info preinstall express@1.0.1 5 | npm info install express@1.0.1 6 | npm info postinstall express@1.0.1 7 | npm info predeactivate express@1.0.1 8 | npm info deactivate express@1.0.1 9 | npm info postdeactivate express@1.0.1 10 | npm info preactivate express@1.0.1 11 | npm info activate express@1.0.1 12 | npm info postactivate express@1.0.1 13 | npm info preupdatedependents express@1.0.1 14 | npm info not updating express@1.0.1 doesn't satisfy cukepatch-store@0.1.0 15 | npm info updatedependents express@1.0.1 16 | npm info postupdatedependents express@1.0.1 17 | npm info updated dependents [ 'express@1.0.1' ] 18 | npm info build Success: express@1.0.1 19 | npm ok 20 | -------------------------------------------------------------------------------- /spec/ansi2html/main_spec.rb: -------------------------------------------------------------------------------- 1 | require 'stringio' 2 | require 'ansi2html/main' 3 | 4 | module ANSI2HTML 5 | describe Main do 6 | it "prints non-ansi as-is" do 7 | out = StringIO.new 8 | Main.new("Hello", out) 9 | out.string.should == 'Hello' 10 | end 11 | 12 | it "prints simply red" do 13 | out = StringIO.new 14 | Main.new("\e[31mHello\e[0m", out) 15 | out.string.should == 'Hello' 16 | end 17 | 18 | it "prints simply yellow" do 19 | out = StringIO.new 20 | Main.new("\e[33mHello\e[0m", out) 21 | out.string.should == 'Hello' 22 | end 23 | 24 | it "prints simply blue" do 25 | out = StringIO.new 26 | Main.new("\e[34mHello\e[0m", out) 27 | out.string.should == 'Hello' 28 | end 29 | 30 | it "prints simply grey" do 31 | out = StringIO.new 32 | Main.new("\e[90mHello\e[0m", out) 33 | out.string.should == 'Hello' 34 | end 35 | 36 | it "white bold boys have more fun" do 37 | out = StringIO.new 38 | Main.new("\e[37m\e[1mHello\e[0m\e[0m", out) 39 | out.string.should == 'Hello' 40 | end 41 | end 42 | end --------------------------------------------------------------------------------