ansi-to-html 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f9e7dbe4d083c0b74ee77285f47f2daec616d7b
4
+ data.tar.gz: 01879dc879674b42e8bc6368ab55cad6e3dcc1b2
5
+ SHA512:
6
+ metadata.gz: 78d03393a40ed88a098831dae72dd536874f5fb80c49cdf599b42441b5ea4577191063f50c4f59a29393eac4bb8c4c7a673483cd3c11813d3c9c75f5b5a93fcf
7
+ data.tar.gz: 6e08bc41732b59fea71a61f9b49fec7a6c5a2b7adbd659b9223434518287193779ed3a6139e71886356e166defac73b9eeab575f2311fd39e979e78623436435
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ansi-to-html.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 uu59
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # Ansi::To::Html
2
+
3
+ ANSI color code sequence to HTML.
4
+
5
+ See `examples/` directory for a generated result.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'ansi-to-html'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ansi-to-html
20
+
21
+ ## Usage
22
+
23
+ $ tmux capture-pane -S -10000 -e; tmux show-buffer > /tmp/terminal
24
+ $ ansi-to-html /tmp/terminal > /tmp/foo.html
25
+ $ cat /tmp/terminal | ansi-to-html > /tmp/bar.html
26
+ $ tmux capture-pane -S -10000 -e; tmux show-buffer | ansi-to-html > /tmp/baz.html
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ansi/to/html/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ansi-to-html"
8
+ spec.version = Ansi::To::Html::VERSION
9
+ spec.authors = ["uu59"]
10
+ spec.email = ["k@uu59.org"]
11
+ spec.description = %q{ANSI color sequence to HTML}
12
+ spec.summary = %q{ANSI color sequence to HTML}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: set ft=ruby:
3
+
4
+ # Usage:
5
+ # $ tmux capture-pane -S -10000 -e; tmux show-buffer > /tmp/terminal
6
+ # $ ansi-to-html /tmp/terminal > /tmp/foo.html
7
+ # $ cat /tmp/terminal | ansi-to-html > /tmp/bar.html
8
+ # $ tmux capture-pane -S -10000 -e; tmux show-buffer | ansi-to-html > /tmp/baz.html
9
+
10
+ require File.expand_path("../../lib/ansi-to-html.rb", __FILE__)
11
+ require "optparse"
12
+
13
+ opt = OptionParser.new
14
+
15
+ colors = {
16
+ :fg => "#fff",
17
+ :bg => "#000",
18
+ }
19
+ opt.on('-f', '--fg=VAL') {|v| colors[:fg] = v }
20
+ opt.on('-b', '--bg=VAL') {|v| colors[:bg] = v }
21
+ opt.parse! ARGV
22
+
23
+ if ARGF.to_io == STDIN && !File.pipe?(STDIN)
24
+ warn "any file or stdin needed."
25
+ exit
26
+ end
27
+
28
+ ansi = Ansi::To::Html.new(ARGF)
29
+
30
+ puts "<html><head><style>"
31
+ puts <<-CSS
32
+ body {
33
+ background-color: #{colors[:bg]};
34
+ color: #{colors[:fg]};
35
+ }
36
+ CSS
37
+ puts "</style></head><body>"
38
+ puts "<pre>"
39
+ puts ansi.to_html
40
+ puts "</pre>"
41
+ puts "</body></html>"
@@ -0,0 +1,50 @@
1
+ <html><head><style>
2
+ body {
3
+ background-color: #000;
4
+ color: #fff;
5
+ }
6
+ </style></head><body>
7
+ <pre>
8
+
9
+ nyaran<span style='color:#d7ffaf'>@xubuntu1224</span>:~/works/ansi-to-html <span style='color:#a8a8a8'>(ruby-2.0.0-p353)</span> $ colorcheck
10
+ \\033[0;38;05;XXXm Text \\033[0m
11
+ <span style='color:#000'>000</span> <span style='color:#A00'>001</span> <span style='color:#0A0'>002</span> <span style='color:#A50'>003</span> <span style='color:#00A'>004</span> <span style='color:#A0A'>005</span> <span style='color:#0AA'>006</span> <span style='color:#AAA'>007</span> <span style='color:#555'>008</span> <span style='color:#F55'>009</span> <span style='color:#5F5'>010</span> <span style='color:#FF5'>011</span> <span style='color:#55F'>012</span> <span style='color:#F5F'>013</span> <span style='color:#5FF'>014</span> <span style='color:#FFF'>015</span> <span style='color:#000000'>016</span> <span style='color:#00005f'>017</span> <span style='color:#000087'>018</span> <span style='color:#0000af'>019</span> <span style='color:#0000d7'>020</span> <span style='color:#0000ff'>021</span> <span style='color:#005f00'>022</span> <span style='color:#005f5f'>023</span> <span style='color:#005f87'>024</span> <span style='color:#005faf'>025</span> <span style='color:#005fd7'>026</span> <span style='color:#005fff'>027</span> <span style='color:#008700'>028</span> <span style='color:#00875f'>029</span> <span style='color:#008787'>030</span> <span style='color:#0087af'>031</span> <span style='color:#0087d7'>032</span> <span style='color:#0087ff'>033</span> <span style='color:#00af00'>034</span>
12
+ <span style='color:#00af5f'>035</span> <span style='color:#00af87'>036</span> <span style='color:#00afaf'>037</span> <span style='color:#00afd7'>038</span> <span style='color:#00afff'>039</span> <span style='color:#00d700'>040</span> <span style='color:#00d75f'>041</span> <span style='color:#00d787'>042</span> <span style='color:#00d7af'>043</span> <span style='color:#00d7d7'>044</span> <span style='color:#00d7ff'>045</span> <span style='color:#00ff00'>046</span> <span style='color:#00ff5f'>047</span> <span style='color:#00ff87'>048</span> <span style='color:#00ffaf'>049</span> <span style='color:#00ffd7'>050</span> <span style='color:#00ffff'>051</span> <span style='color:#5f0000'>052</span> <span style='color:#5f005f'>053</span> <span style='color:#5f0087'>054</span> <span style='color:#5f00af'>055</span> <span style='color:#5f00d7'>056</span> <span style='color:#5f00ff'>057</span> <span style='color:#5f5f00'>058</span> <span style='color:#5f5f5f'>059</span> <span style='color:#5f5f87'>060</span> <span style='color:#5f5faf'>061</span> <span style='color:#5f5fd7'>062</span> <span style='color:#5f5fff'>063</span> <span style='color:#5f8700'>064</span> <span style='color:#5f875f'>065</span> <span style='color:#5f8787'>066</span> <span style='color:#5f87af'>067</span> <span style='color:#5f87d7'>068</span> <span style='color:#5f87ff'>069</span>
13
+ <span style='color:#5faf00'>070</span> <span style='color:#5faf5f'>071</span> <span style='color:#5faf87'>072</span> <span style='color:#5fafaf'>073</span> <span style='color:#5fafd7'>074</span> <span style='color:#5fafff'>075</span> <span style='color:#5fd700'>076</span> <span style='color:#5fd75f'>077</span> <span style='color:#5fd787'>078</span> <span style='color:#5fd7af'>079</span> <span style='color:#5fd7d7'>080</span> <span style='color:#5fd7ff'>081</span> <span style='color:#5fff00'>082</span> <span style='color:#5fff5f'>083</span> <span style='color:#5fff87'>084</span> <span style='color:#5fffaf'>085</span> <span style='color:#5fffd7'>086</span> <span style='color:#5fffff'>087</span> <span style='color:#870000'>088</span> <span style='color:#87005f'>089</span> <span style='color:#870087'>090</span> <span style='color:#8700af'>091</span> <span style='color:#8700d7'>092</span> <span style='color:#8700ff'>093</span> <span style='color:#875f00'>094</span> <span style='color:#875f5f'>095</span> <span style='color:#875f87'>096</span> <span style='color:#875faf'>097</span> <span style='color:#875fd7'>098</span> <span style='color:#875fff'>099</span> <span style='color:#878700'>100</span> <span style='color:#87875f'>101</span> <span style='color:#878787'>102</span> <span style='color:#8787af'>103</span> <span style='color:#8787d7'>104</span>
14
+ <span style='color:#8787ff'>105</span> <span style='color:#87af00'>106</span> <span style='color:#87af5f'>107</span> <span style='color:#87af87'>108</span> <span style='color:#87afaf'>109</span> <span style='color:#87afd7'>110</span> <span style='color:#87afff'>111</span> <span style='color:#87d700'>112</span> <span style='color:#87d75f'>113</span> <span style='color:#87d787'>114</span> <span style='color:#87d7af'>115</span> <span style='color:#87d7d7'>116</span> <span style='color:#87d7ff'>117</span> <span style='color:#87ff00'>118</span> <span style='color:#87ff5f'>119</span> <span style='color:#87ff87'>120</span> <span style='color:#87ffaf'>121</span> <span style='color:#87ffd7'>122</span> <span style='color:#87ffff'>123</span> <span style='color:#af0000'>124</span> <span style='color:#af005f'>125</span> <span style='color:#af0087'>126</span> <span style='color:#af00af'>127</span> <span style='color:#af00d7'>128</span> <span style='color:#af00ff'>129</span> <span style='color:#af5f00'>130</span> <span style='color:#af5f5f'>131</span> <span style='color:#af5f87'>132</span> <span style='color:#af5faf'>133</span> <span style='color:#af5fd7'>134</span> <span style='color:#af5fff'>135</span> <span style='color:#af8700'>136</span> <span style='color:#af875f'>137</span> <span style='color:#af8787'>138</span> <span style='color:#af87af'>139</span>
15
+ <span style='color:#af87d7'>140</span> <span style='color:#af87ff'>141</span> <span style='color:#afaf00'>142</span> <span style='color:#afaf5f'>143</span> <span style='color:#afaf87'>144</span> <span style='color:#afafaf'>145</span> <span style='color:#afafd7'>146</span> <span style='color:#afafff'>147</span> <span style='color:#afd700'>148</span> <span style='color:#afd75f'>149</span> <span style='color:#afd787'>150</span> <span style='color:#afd7af'>151</span> <span style='color:#afd7d7'>152</span> <span style='color:#afd7ff'>153</span> <span style='color:#afff00'>154</span> <span style='color:#afff5f'>155</span> <span style='color:#afff87'>156</span> <span style='color:#afffaf'>157</span> <span style='color:#afffd7'>158</span> <span style='color:#afffff'>159</span> <span style='color:#d70000'>160</span> <span style='color:#d7005f'>161</span> <span style='color:#d70087'>162</span> <span style='color:#d700af'>163</span> <span style='color:#d700d7'>164</span> <span style='color:#d700ff'>165</span> <span style='color:#d75f00'>166</span> <span style='color:#d75f5f'>167</span> <span style='color:#d75f87'>168</span> <span style='color:#d75faf'>169</span> <span style='color:#d75fd7'>170</span> <span style='color:#d75fff'>171</span> <span style='color:#d78700'>172</span> <span style='color:#d7875f'>173</span> <span style='color:#d78787'>174</span>
16
+ <span style='color:#d787af'>175</span> <span style='color:#d787d7'>176</span> <span style='color:#d787ff'>177</span> <span style='color:#d7af00'>178</span> <span style='color:#d7af5f'>179</span> <span style='color:#d7af87'>180</span> <span style='color:#d7afaf'>181</span> <span style='color:#d7afd7'>182</span> <span style='color:#d7afff'>183</span> <span style='color:#d7d700'>184</span> <span style='color:#d7d75f'>185</span> <span style='color:#d7d787'>186</span> <span style='color:#d7d7af'>187</span> <span style='color:#d7d7d7'>188</span> <span style='color:#d7d7ff'>189</span> <span style='color:#d7ff00'>190</span> <span style='color:#d7ff5f'>191</span> <span style='color:#d7ff87'>192</span> <span style='color:#d7ffaf'>193</span> <span style='color:#d7ffd7'>194</span> <span style='color:#d7ffff'>195</span> <span style='color:#ff0000'>196</span> <span style='color:#ff005f'>197</span> <span style='color:#ff0087'>198</span> <span style='color:#ff00af'>199</span> <span style='color:#ff00d7'>200</span> <span style='color:#ff00ff'>201</span> <span style='color:#ff5f00'>202</span> <span style='color:#ff5f5f'>203</span> <span style='color:#ff5f87'>204</span> <span style='color:#ff5faf'>205</span> <span style='color:#ff5fd7'>206</span> <span style='color:#ff5fff'>207</span> <span style='color:#ff8700'>208</span> <span style='color:#ff875f'>209</span>
17
+ <span style='color:#ff8787'>210</span> <span style='color:#ff87af'>211</span> <span style='color:#ff87d7'>212</span> <span style='color:#ff87ff'>213</span> <span style='color:#ffaf00'>214</span> <span style='color:#ffaf5f'>215</span> <span style='color:#ffaf87'>216</span> <span style='color:#ffafaf'>217</span> <span style='color:#ffafd7'>218</span> <span style='color:#ffafff'>219</span> <span style='color:#ffd700'>220</span> <span style='color:#ffd75f'>221</span> <span style='color:#ffd787'>222</span> <span style='color:#ffd7af'>223</span> <span style='color:#ffd7d7'>224</span> <span style='color:#ffd7ff'>225</span> <span style='color:#ffff00'>226</span> <span style='color:#ffff5f'>227</span> <span style='color:#ffff87'>228</span> <span style='color:#ffffaf'>229</span> <span style='color:#ffffd7'>230</span> <span style='color:#ffffff'>231</span> <span style='color:#080808'>232</span> <span style='color:#121212'>233</span> <span style='color:#1c1c1c'>234</span> <span style='color:#262626'>235</span> <span style='color:#303030'>236</span> <span style='color:#3a3a3a'>237</span> <span style='color:#444444'>238</span> <span style='color:#4e4e4e'>239</span> <span style='color:#585858'>240</span> <span style='color:#626262'>241</span> <span style='color:#6c6c6c'>242</span> <span style='color:#767676'>243</span> <span style='color:#808080'>244</span>
18
+ <span style='color:#8a8a8a'>245</span> <span style='color:#949494'>246</span> <span style='color:#9e9e9e'>247</span> <span style='color:#a8a8a8'>248</span> <span style='color:#b2b2b2'>249</span> <span style='color:#bcbcbc'>250</span> <span style='color:#c6c6c6'>251</span> <span style='color:#d0d0d0'>252</span> <span style='color:#dadada'>253</span> <span style='color:#e4e4e4'>254</span> <span style='color:#eeeeee'>255</span>
19
+ \\033[48;05;XXXm Text \\033[0m
20
+ <span style='background-color:#000'>000</span> <span style='background-color:#A00'>001</span> <span style='background-color:#0A0'>002</span> <span style='background-color:#A50'>003</span> <span style='background-color:#00A'>004</span> <span style='background-color:#A0A'>005</span> <span style='background-color:#0AA'>006</span> <span style='background-color:#AAA'>007</span> <span style='background-color:#555'>008</span> <span style='background-color:#F55'>009</span> <span style='background-color:#5F5'>010</span> <span style='background-color:#FF5'>011</span> <span style='background-color:#55F'>012</span> <span style='background-color:#F5F'>013</span> <span style='background-color:#5FF'>014</span> <span style='background-color:#FFF'>015</span> <span style='background-color:#000000'>016</span> <span style='background-color:#00005f'>017</span> <span style='background-color:#000087'>018</span> <span style='background-color:#0000af'>019</span> <span style='background-color:#0000d7'>020</span> <span style='background-color:#0000ff'>021</span> <span style='background-color:#005f00'>022</span> <span style='background-color:#005f5f'>023</span> <span style='background-color:#005f87'>024</span> <span style='background-color:#005faf'>025</span> <span style='background-color:#005fd7'>026</span> <span style='background-color:#005fff'>027</span>
21
+ <span style='background-color:#008700'>028</span> <span style='background-color:#00875f'>029</span> <span style='background-color:#008787'>030</span> <span style='background-color:#0087af'>031</span> <span style='background-color:#0087d7'>032</span> <span style='background-color:#0087ff'>033</span> <span style='background-color:#00af00'>034</span> <span style='background-color:#00af5f'>035</span> <span style='background-color:#00af87'>036</span> <span style='background-color:#00afaf'>037</span> <span style='background-color:#00afd7'>038</span> <span style='background-color:#00afff'>039</span> <span style='background-color:#00d700'>040</span> <span style='background-color:#00d75f'>041</span> <span style='background-color:#00d787'>042</span> <span style='background-color:#00d7af'>043</span> <span style='background-color:#00d7d7'>044</span> <span style='background-color:#00d7ff'>045</span> <span style='background-color:#00ff00'>046</span> <span style='background-color:#00ff5f'>047</span> <span style='background-color:#00ff87'>048</span> <span style='background-color:#00ffaf'>049</span> <span style='background-color:#00ffd7'>050</span> <span style='background-color:#00ffff'>051</span> <span style='background-color:#5f0000'>052</span> <span style='background-color:#5f005f'>053</span> <span style='background-color:#5f0087'>054</span> <span style='background-color:#5f00af'>055</span>
22
+ <span style='background-color:#5f00d7'>056</span> <span style='background-color:#5f00ff'>057</span> <span style='background-color:#5f5f00'>058</span> <span style='background-color:#5f5f5f'>059</span> <span style='background-color:#5f5f87'>060</span> <span style='background-color:#5f5faf'>061</span> <span style='background-color:#5f5fd7'>062</span> <span style='background-color:#5f5fff'>063</span> <span style='background-color:#5f8700'>064</span> <span style='background-color:#5f875f'>065</span> <span style='background-color:#5f8787'>066</span> <span style='background-color:#5f87af'>067</span> <span style='background-color:#5f87d7'>068</span> <span style='background-color:#5f87ff'>069</span> <span style='background-color:#5faf00'>070</span> <span style='background-color:#5faf5f'>071</span> <span style='background-color:#5faf87'>072</span> <span style='background-color:#5fafaf'>073</span> <span style='background-color:#5fafd7'>074</span> <span style='background-color:#5fafff'>075</span> <span style='background-color:#5fd700'>076</span> <span style='background-color:#5fd75f'>077</span> <span style='background-color:#5fd787'>078</span> <span style='background-color:#5fd7af'>079</span> <span style='background-color:#5fd7d7'>080</span> <span style='background-color:#5fd7ff'>081</span> <span style='background-color:#5fff00'>082</span> <span style='background-color:#5fff5f'>083</span>
23
+ <span style='background-color:#5fff87'>084</span> <span style='background-color:#5fffaf'>085</span> <span style='background-color:#5fffd7'>086</span> <span style='background-color:#5fffff'>087</span> <span style='background-color:#870000'>088</span> <span style='background-color:#87005f'>089</span> <span style='background-color:#870087'>090</span> <span style='background-color:#8700af'>091</span> <span style='background-color:#8700d7'>092</span> <span style='background-color:#8700ff'>093</span> <span style='background-color:#875f00'>094</span> <span style='background-color:#875f5f'>095</span> <span style='background-color:#875f87'>096</span> <span style='background-color:#875faf'>097</span> <span style='background-color:#875fd7'>098</span> <span style='background-color:#875fff'>099</span> <span style='background-color:#878700'>100</span> <span style='background-color:#87875f'>101</span> <span style='background-color:#878787'>102</span> <span style='background-color:#8787af'>103</span> <span style='background-color:#8787d7'>104</span> <span style='background-color:#8787ff'>105</span> <span style='background-color:#87af00'>106</span> <span style='background-color:#87af5f'>107</span> <span style='background-color:#87af87'>108</span> <span style='background-color:#87afaf'>109</span> <span style='background-color:#87afd7'>110</span> <span style='background-color:#87afff'>111</span>
24
+ <span style='background-color:#87d700'>112</span> <span style='background-color:#87d75f'>113</span> <span style='background-color:#87d787'>114</span> <span style='background-color:#87d7af'>115</span> <span style='background-color:#87d7d7'>116</span> <span style='background-color:#87d7ff'>117</span> <span style='background-color:#87ff00'>118</span> <span style='background-color:#87ff5f'>119</span> <span style='background-color:#87ff87'>120</span> <span style='background-color:#87ffaf'>121</span> <span style='background-color:#87ffd7'>122</span> <span style='background-color:#87ffff'>123</span> <span style='background-color:#af0000'>124</span> <span style='background-color:#af005f'>125</span> <span style='background-color:#af0087'>126</span> <span style='background-color:#af00af'>127</span> <span style='background-color:#af00d7'>128</span> <span style='background-color:#af00ff'>129</span> <span style='background-color:#af5f00'>130</span> <span style='background-color:#af5f5f'>131</span> <span style='background-color:#af5f87'>132</span> <span style='background-color:#af5faf'>133</span> <span style='background-color:#af5fd7'>134</span> <span style='background-color:#af5fff'>135</span> <span style='background-color:#af8700'>136</span> <span style='background-color:#af875f'>137</span> <span style='background-color:#af8787'>138</span> <span style='background-color:#af87af'>139</span>
25
+ <span style='background-color:#af87d7'>140</span> <span style='background-color:#af87ff'>141</span> <span style='background-color:#afaf00'>142</span> <span style='background-color:#afaf5f'>143</span> <span style='background-color:#afaf87'>144</span> <span style='background-color:#afafaf'>145</span> <span style='background-color:#afafd7'>146</span> <span style='background-color:#afafff'>147</span> <span style='background-color:#afd700'>148</span> <span style='background-color:#afd75f'>149</span> <span style='background-color:#afd787'>150</span> <span style='background-color:#afd7af'>151</span> <span style='background-color:#afd7d7'>152</span> <span style='background-color:#afd7ff'>153</span> <span style='background-color:#afff00'>154</span> <span style='background-color:#afff5f'>155</span> <span style='background-color:#afff87'>156</span> <span style='background-color:#afffaf'>157</span> <span style='background-color:#afffd7'>158</span> <span style='background-color:#afffff'>159</span> <span style='background-color:#d70000'>160</span> <span style='background-color:#d7005f'>161</span> <span style='background-color:#d70087'>162</span> <span style='background-color:#d700af'>163</span> <span style='background-color:#d700d7'>164</span> <span style='background-color:#d700ff'>165</span> <span style='background-color:#d75f00'>166</span> <span style='background-color:#d75f5f'>167</span>
26
+ <span style='background-color:#d75f87'>168</span> <span style='background-color:#d75faf'>169</span> <span style='background-color:#d75fd7'>170</span> <span style='background-color:#d75fff'>171</span> <span style='background-color:#d78700'>172</span> <span style='background-color:#d7875f'>173</span> <span style='background-color:#d78787'>174</span> <span style='background-color:#d787af'>175</span> <span style='background-color:#d787d7'>176</span> <span style='background-color:#d787ff'>177</span> <span style='background-color:#d7af00'>178</span> <span style='background-color:#d7af5f'>179</span> <span style='background-color:#d7af87'>180</span> <span style='background-color:#d7afaf'>181</span> <span style='background-color:#d7afd7'>182</span> <span style='background-color:#d7afff'>183</span> <span style='background-color:#d7d700'>184</span> <span style='background-color:#d7d75f'>185</span> <span style='background-color:#d7d787'>186</span> <span style='background-color:#d7d7af'>187</span> <span style='background-color:#d7d7d7'>188</span> <span style='background-color:#d7d7ff'>189</span> <span style='background-color:#d7ff00'>190</span> <span style='background-color:#d7ff5f'>191</span> <span style='background-color:#d7ff87'>192</span> <span style='background-color:#d7ffaf'>193</span> <span style='background-color:#d7ffd7'>194</span> <span style='background-color:#d7ffff'>195</span>
27
+ <span style='background-color:#ff0000'>196</span> <span style='background-color:#ff005f'>197</span> <span style='background-color:#ff0087'>198</span> <span style='background-color:#ff00af'>199</span> <span style='background-color:#ff00d7'>200</span> <span style='background-color:#ff00ff'>201</span> <span style='background-color:#ff5f00'>202</span> <span style='background-color:#ff5f5f'>203</span> <span style='background-color:#ff5f87'>204</span> <span style='background-color:#ff5faf'>205</span> <span style='background-color:#ff5fd7'>206</span> <span style='background-color:#ff5fff'>207</span> <span style='background-color:#ff8700'>208</span> <span style='background-color:#ff875f'>209</span> <span style='background-color:#ff8787'>210</span> <span style='background-color:#ff87af'>211</span> <span style='background-color:#ff87d7'>212</span> <span style='background-color:#ff87ff'>213</span> <span style='background-color:#ffaf00'>214</span> <span style='background-color:#ffaf5f'>215</span> <span style='background-color:#ffaf87'>216</span> <span style='background-color:#ffafaf'>217</span> <span style='background-color:#ffafd7'>218</span> <span style='background-color:#ffafff'>219</span> <span style='background-color:#ffd700'>220</span> <span style='background-color:#ffd75f'>221</span> <span style='background-color:#ffd787'>222</span> <span style='background-color:#ffd7af'>223</span>
28
+ <span style='background-color:#ffd7d7'>224</span> <span style='background-color:#ffd7ff'>225</span> <span style='background-color:#ffff00'>226</span> <span style='background-color:#ffff5f'>227</span> <span style='background-color:#ffff87'>228</span> <span style='background-color:#ffffaf'>229</span> <span style='background-color:#ffffd7'>230</span> <span style='background-color:#ffffff'>231</span> <span style='background-color:#080808'>232</span> <span style='background-color:#121212'>233</span> <span style='background-color:#1c1c1c'>234</span> <span style='background-color:#262626'>235</span> <span style='background-color:#303030'>236</span> <span style='background-color:#3a3a3a'>237</span> <span style='background-color:#444444'>238</span> <span style='background-color:#4e4e4e'>239</span> <span style='background-color:#585858'>240</span> <span style='background-color:#626262'>241</span> <span style='background-color:#6c6c6c'>242</span> <span style='background-color:#767676'>243</span> <span style='background-color:#808080'>244</span> <span style='background-color:#8a8a8a'>245</span> <span style='background-color:#949494'>246</span> <span style='background-color:#9e9e9e'>247</span> <span style='background-color:#a8a8a8'>248</span> <span style='background-color:#b2b2b2'>249</span> <span style='background-color:#bcbcbc'>250</span> <span style='background-color:#c6c6c6'>251</span>
29
+ <span style='background-color:#d0d0d0'>252</span> <span style='background-color:#dadada'>253</span> <span style='background-color:#e4e4e4'>254</span> <span style='background-color:#eeeeee'>255</span>
30
+ nyaran<span style='color:#d7ffaf'>@xubuntu1224</span>:~/works/ansi-to-html <span style='color:#a8a8a8'>(ruby-2.0.0-p353)</span> $ tmux capture-pane -S -10000 -e; tmux show-buffer | ansi-to-html > /tmp/aa.html
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ </pre>
50
+ </body></html>
@@ -0,0 +1,4 @@
1
+ # -- coding: utf-8
2
+
3
+ require File.expand_path("../ansi/to/html.rb", __FILE__)
4
+
@@ -0,0 +1,179 @@
1
+ require "ansi/to/html/version"
2
+
3
+ # Based on a part of bcat
4
+ # https://github.com/rtomayko/bcat/blob/master/lib/bcat/ansi.rb
5
+
6
+ # changes:
7
+ # - \x1b[39m (and 49m) support
8
+ # - xterm256b(bgcolor for 256color) support
9
+ # - generate whole <html> with default fg/bg color (via `-f`,`-b`)
10
+
11
+ module Ansi
12
+ module To
13
+ class Html
14
+ ESCAPE = "\x1b"
15
+
16
+ # Linux console palette
17
+ STYLES = {
18
+ 'ef0' => 'color:#000',
19
+ 'ef1' => 'color:#A00',
20
+ 'ef2' => 'color:#0A0',
21
+ 'ef3' => 'color:#A50',
22
+ 'ef4' => 'color:#00A',
23
+ 'ef5' => 'color:#A0A',
24
+ 'ef6' => 'color:#0AA',
25
+ 'ef7' => 'color:#AAA',
26
+ 'ef8' => 'color:#555',
27
+ 'ef9' => 'color:#F55',
28
+ 'ef10' => 'color:#5F5',
29
+ 'ef11' => 'color:#FF5',
30
+ 'ef12' => 'color:#55F',
31
+ 'ef13' => 'color:#F5F',
32
+ 'ef14' => 'color:#5FF',
33
+ 'ef15' => 'color:#FFF',
34
+ 'eb0' => 'background-color:#000',
35
+ 'eb1' => 'background-color:#A00',
36
+ 'eb2' => 'background-color:#0A0',
37
+ 'eb3' => 'background-color:#A50',
38
+ 'eb4' => 'background-color:#00A',
39
+ 'eb5' => 'background-color:#A0A',
40
+ 'eb6' => 'background-color:#0AA',
41
+ 'eb7' => 'background-color:#AAA',
42
+ 'eb8' => 'background-color:#555',
43
+ 'eb9' => 'background-color:#F55',
44
+ 'eb10' => 'background-color:#5F5',
45
+ 'eb11' => 'background-color:#FF5',
46
+ 'eb12' => 'background-color:#55F',
47
+ 'eb13' => 'background-color:#F5F',
48
+ 'eb14' => 'background-color:#5FF',
49
+ 'eb15' => 'background-color:#FFF',
50
+ }
51
+
52
+ ##
53
+ # The default xterm 256 colour palette
54
+
55
+ (0..5).each do |red|
56
+ (0..5).each do |green|
57
+ (0..5).each do |blue|
58
+ c = 16 + (red * 36) + (green * 6) + blue
59
+ r = red > 0 ? red * 40 + 55 : 0
60
+ g = green > 0 ? green * 40 + 55 : 0
61
+ b = blue > 0 ? blue * 40 + 55 : 0
62
+ STYLES["ef#{c}"] = "color:#%2.2x%2.2x%2.2x" % [r, g, b]
63
+ STYLES["eb#{c}"] = "background-color:#%2.2x%2.2x%2.2x" % [r, g, b]
64
+ end
65
+ end
66
+ end
67
+
68
+ (0..23).each do |gray|
69
+ c = gray+232
70
+ l = gray*10 + 8
71
+ STYLES["ef#{c}"] = "color:#%2.2x%2.2x%2.2x" % [l, l, l]
72
+ STYLES["eb#{c}"] = "background-color:#%2.2x%2.2x%2.2x" % [l, l, l]
73
+ end
74
+
75
+ def initialize(input)
76
+ @input =
77
+ if input.respond_to?(:to_str)
78
+ [input]
79
+ elsif !input.respond_to?(:each)
80
+ raise ArgumentError, "input must respond to each"
81
+ else
82
+ input
83
+ end
84
+ @stack = []
85
+ end
86
+
87
+ def to_html
88
+ buf = []
89
+ each { |chunk| buf << chunk }
90
+ buf.join
91
+ end
92
+
93
+ def each
94
+ buf = ''
95
+ @input.each do |chunk|
96
+ buf << chunk
97
+ tokenize(buf) do |tok, data|
98
+ case tok
99
+ when :text
100
+ yield data
101
+ when :display
102
+ case code = data
103
+ when 0,39,49 ; yield reset_styles if @stack.any? # NOTE: 39/49 is reset for fg/bg color only
104
+ when 1 ; yield push_tag("b") # bright
105
+ when 2 ; #dim
106
+ when 3, 4 ; yield push_tag("u")
107
+ when 5, 6 ; yield push_tag("blink")
108
+ when 7 ; #reverse
109
+ when 8 ; yield push_style("display:none")
110
+ when 9 ; yield push_tag("strike")
111
+ when 30..37 ; yield push_style("ef#{code - 30}")
112
+ when 40..47 ; yield push_style("eb#{code - 40}")
113
+ when 90..97 ; yield push_style("ef#{8 + code - 90}")
114
+ when 100..107 ; yield push_style("eb#{8 + code - 100}")
115
+ end
116
+ when :xterm256f
117
+ code = data
118
+ yield push_style("ef#{code}")
119
+ when :xterm256b
120
+ code = data
121
+ yield push_style("eb#{code}")
122
+ end
123
+ end
124
+ end
125
+ yield buf if !buf.empty?
126
+ yield reset_styles if @stack.any?
127
+ self
128
+ end
129
+
130
+ def push_tag(tag, style=nil)
131
+ style = STYLES[style] if style && !style.include?(':')
132
+ @stack.push tag
133
+ [ "<#{tag}",
134
+ (" style='#{style}'" if style),
135
+ ">"
136
+ ].join
137
+ end
138
+
139
+ def push_style(style)
140
+ push_tag "span", style
141
+ end
142
+
143
+ def reset_styles
144
+ stack, @stack = @stack, []
145
+ stack.reverse.map { |tag| "</#{tag}>" }.join
146
+ end
147
+
148
+ def tokenize(text)
149
+ tokens = [
150
+ # characters to remove completely
151
+ [/\A\x08+/, lambda { |m| '' }],
152
+
153
+ [/\A\x1b\[38;5;(\d+)m/, lambda { |m| yield :xterm256f, $1.to_i; '' } ],
154
+ [/\A\x1b\[48;5;(\d+)m/, lambda { |m| yield :xterm256b, $1.to_i; '' } ],
155
+
156
+ # ansi escape sequences that mess with the display
157
+ [/\A\x1b\[((?:\d{1,3};?)+|)m/, lambda { |m|
158
+ m = '0' if m.strip.empty?
159
+ m.chomp(';').split(';').
160
+ each { |code| yield :display, code.to_i };
161
+ '' }],
162
+
163
+ # malformed sequences
164
+ [/\A\x1b\[?[\d;]{0,3}/, lambda { |m| '' }],
165
+
166
+ # real text
167
+ [/\A([^\x1b\x08]+)/m, lambda { |m| yield :text, m; '' }]
168
+ ]
169
+
170
+ while (size = text.size) > 0
171
+ tokens.each do |pattern, sub|
172
+ break if text.sub!(pattern) { sub.call($1) }
173
+ end
174
+ break if text.size == size
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,7 @@
1
+ module Ansi
2
+ module To
3
+ class Html
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansi-to-html
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - uu59
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ANSI color sequence to HTML
56
+ email:
57
+ - k@uu59.org
58
+ executables:
59
+ - ansi-to-html
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - ansi-to-html.gemspec
69
+ - bin/ansi-to-html
70
+ - examples/sample1.html
71
+ - lib/ansi-to-html.rb
72
+ - lib/ansi/to/html.rb
73
+ - lib/ansi/to/html/version.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.14
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: ANSI color sequence to HTML
98
+ test_files: []