ansi-to-html 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/bin/ansi-to-html +6 -10
- data/lib/ansi/to/html.rb +29 -37
- data/lib/ansi/to/html/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6de44dd3141015a87cf2f4baa04e52191be1ca56
|
4
|
+
data.tar.gz: 36b30e5a8bd7ee6e93b0a20f19a26d1ee902db9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea73932e671fe416d6e390f0b9439bb7298dea8d3adaf5dd32c00d18cdaa86e06ef9bc7a6ddf81c29a3c5132169c6701172e1781802d8dbc9cbe31407eb2299
|
7
|
+
data.tar.gz: 1b8827dcc1e2f7a1fc12d57e1fcbff6fc83c81f5a33b7f696bb6848a01622041b3cc843de24ec6da294ea28b019f1319cfe3335d71c5e40800e1558c5026f527
|
data/README.md
CHANGED
@@ -4,6 +4,14 @@ ANSI color code sequence to HTML.
|
|
4
4
|
|
5
5
|
See `examples/` directory for a generated result.
|
6
6
|
|
7
|
+
This is almost deadcopy of [bcat](https://github.com/rtomayko/bcat/blob/master/lib/bcat/ansi.rb) :bow:
|
8
|
+
|
9
|
+
But some differences are:
|
10
|
+
|
11
|
+
- `\x1b[39m` (and `49m`) support
|
12
|
+
- bgcolor for 256color support
|
13
|
+
- generate whole `<html>` with default fg/bg color (via `-f`,`-b`)
|
14
|
+
|
7
15
|
## Installation
|
8
16
|
|
9
17
|
Add this line to your application's Gemfile:
|
@@ -25,6 +33,8 @@ Or install it yourself as:
|
|
25
33
|
$ cat /tmp/terminal | ansi-to-html > /tmp/bar.html
|
26
34
|
$ tmux capture-pane -S -10000 -e; tmux show-buffer | ansi-to-html > /tmp/baz.html
|
27
35
|
|
36
|
+
Specify default foreground/background color with `-f` and/or `-b` option such as `ansi-to-html -f '#fff' -b '#000'`.
|
37
|
+
|
28
38
|
## Contributing
|
29
39
|
|
30
40
|
1. Fork it
|
data/bin/ansi-to-html
CHANGED
@@ -15,9 +15,11 @@ opt = OptionParser.new
|
|
15
15
|
colors = {
|
16
16
|
:fg => "#fff",
|
17
17
|
:bg => "#000",
|
18
|
+
:pallete => :linux,
|
18
19
|
}
|
19
|
-
opt.on('-f', '--fg=VAL') {|v| colors[:fg] = v }
|
20
|
-
opt.on('-b', '--bg=VAL') {|v| colors[:bg] = v }
|
20
|
+
opt.on('-f VAL', '--fg=VAL') {|v| colors[:fg] = v }
|
21
|
+
opt.on('-b VAL', '--bg=VAL') {|v| colors[:bg] = v }
|
22
|
+
opt.on('-p VAL', '--pallete=VAL') {|v| colors[:pallete] = v.to_sym }
|
21
23
|
opt.parse! ARGV
|
22
24
|
|
23
25
|
if ARGF.to_io == STDIN && !File.pipe?(STDIN)
|
@@ -28,14 +30,8 @@ end
|
|
28
30
|
ansi = Ansi::To::Html.new(ARGF)
|
29
31
|
|
30
32
|
puts "<html><head><style>"
|
31
|
-
puts
|
32
|
-
body {
|
33
|
-
background-color: #{colors[:bg]};
|
34
|
-
color: #{colors[:fg]};
|
35
|
-
}
|
36
|
-
CSS
|
37
|
-
puts "</style></head><body>"
|
33
|
+
puts %Q!</style></head><body style="color:#{colors[:fg]};background-color:#{colors[:bg]}">!
|
38
34
|
puts "<pre>"
|
39
|
-
puts ansi.to_html
|
35
|
+
puts ansi.to_html(colors[:pallete])
|
40
36
|
puts "</pre>"
|
41
37
|
puts "</body></html>"
|
data/lib/ansi/to/html.rb
CHANGED
@@ -14,43 +14,30 @@ module Ansi
|
|
14
14
|
ESCAPE = "\x1b"
|
15
15
|
|
16
16
|
# Linux console palette
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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',
|
17
|
+
pallete = { # http://www.pixelbeat.org/scripts/ansi2html.sh
|
18
|
+
:solarized => %w(
|
19
|
+
073642 D30102 859900 B58900 268BD2 D33682 2AA198 EEE8D5 002B36 CB4B16 586E75 657B83 839496 6C71C4 93A1A1 FDF6E3
|
20
|
+
),
|
21
|
+
:linux => %w(
|
22
|
+
000 A00 0A0 A50 00A A0A 0AA AAA 555 F55 5F5 FF5 55F F5F 5FF FFF
|
23
|
+
),
|
24
|
+
:tango => %w(
|
25
|
+
262626 AF0000 5F8700 AF8700 0087FF AF005F 00AFAF E4E4E4 1C1C1C D75F00 585858 626262 808080 5F5FAF 8A8A8A FFFFD7
|
26
|
+
),
|
27
|
+
:xterm => %w(
|
28
|
+
000000 CD0000 00CD00 CDCD00 0000EE CD00CD 00CDCD E5E5E5 7F7F7F FF0000 00FF00 FFFF00 5C5CFF FF00FF 00FFFF FFFFFF
|
29
|
+
),
|
50
30
|
}
|
51
31
|
|
52
|
-
|
53
|
-
|
32
|
+
STYLES = {}
|
33
|
+
PALLETE = {}
|
34
|
+
pallete.each do |key, colors|
|
35
|
+
PALLETE[key] = {}
|
36
|
+
(0..15).each do |n|
|
37
|
+
PALLETE[key]["ef#{n}"] = "color:##{colors[n]};"
|
38
|
+
PALLETE[key]["eb#{n}"] = "background-color:##{colors[n]}"
|
39
|
+
end
|
40
|
+
end
|
54
41
|
|
55
42
|
(0..5).each do |red|
|
56
43
|
(0..5).each do |green|
|
@@ -84,8 +71,13 @@ module Ansi
|
|
84
71
|
@stack = []
|
85
72
|
end
|
86
73
|
|
87
|
-
def to_html
|
74
|
+
def to_html(pallete = :linux)
|
88
75
|
buf = []
|
76
|
+
if PALLETE.keys.include?(pallete)
|
77
|
+
@pallete = pallete
|
78
|
+
else
|
79
|
+
warn "--pallet=#{pallete} is unknown."
|
80
|
+
end
|
89
81
|
each { |chunk| buf << chunk }
|
90
82
|
buf.join
|
91
83
|
end
|
@@ -128,7 +120,7 @@ module Ansi
|
|
128
120
|
end
|
129
121
|
|
130
122
|
def push_tag(tag, style=nil)
|
131
|
-
style = STYLES[style] if style && !style.include?(':')
|
123
|
+
style = STYLES[style] || PALLETE[@pallete || :linux][style] if style && !style.include?(':')
|
132
124
|
@stack.push tag
|
133
125
|
[ "<#{tag}",
|
134
126
|
(" style='#{style}'" if style),
|
data/lib/ansi/to/html/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansi-to-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|