ansi_sgr_to_html 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ansi_sgr_to_html.rb +457 -0
- metadata +50 -0
@@ -0,0 +1,457 @@
|
|
1
|
+
# This is generated by ragel - write me a mail if you are interested in the main source.
|
2
|
+
# Its not included, currently, as I dont want the gem to depend on ragel, for installation.
|
3
|
+
class ANSI_SGR_To_HTML
|
4
|
+
@@HTML_escapes = {'&'=>'&','"'=>'"','<'=>'<','>'=>'>',"\r"=>"\r","\n"=>"\n"} # newlines controlled by option
|
5
|
+
@@Col_tab_256 = [
|
6
|
+
'000000','800000','008000','808000','000080','800080','008080','c0c0c0',
|
7
|
+
'808080','ff0000','00ff00','ffff00','0000ff','ff00ff','00ffff','ffffff',
|
8
|
+
'000000','00005f','000087','0000af','0000df','0000ff','005f00','005f5f',
|
9
|
+
'005f87','005faf','005fdf','005fff','008700','00875f','008787','0087af',
|
10
|
+
'0087df','0087ff','00af00','00af5f','00af87','00afaf','00afdf','00afff',
|
11
|
+
'00df00','00df5f','00df87','00dfaf','00dfdf','00dfff','00ff00','00ff5f',
|
12
|
+
'00ff87','00ffaf','00ffdf','00ffff','5f0000','5f005f','5f0087','5f00af',
|
13
|
+
'5f00df','5f00ff','5f5f00','5f5f5f','5f5f87','5f5faf','5f5fdf','5f5fff',
|
14
|
+
'5f8700','5f875f','5f8787','5f87af','5f87df','5f87ff','5faf00','5faf5f',
|
15
|
+
'5faf87','5fafaf','5fafdf','5fafff','5fdf00','5fdf5f','5fdf87','5fdfaf',
|
16
|
+
'5fdfdf','5fdfff','5fff00','5fff5f','5fff87','5fffaf','5fffdf','5fffff',
|
17
|
+
'870000','87005f','870087','8700af','8700df','8700ff','875f00','875f5f',
|
18
|
+
'875f87','875faf','875fdf','875fff','878700','87875f','878787','8787af',
|
19
|
+
'8787df','8787ff','87af00','87af5f','87af87','87afaf','87afdf','87afff',
|
20
|
+
'87df00','87df5f','87df87','87dfaf','87dfdf','87dfff','87ff00','87ff5f',
|
21
|
+
'87ff87','87ffaf','87ffdf','87ffff','af0000','af005f','af0087','af00af',
|
22
|
+
'af00df','af00ff','af5f00','af5f5f','af5f87','af5faf','af5fdf','af5fff',
|
23
|
+
'af8700','af875f','af8787','af87af','af87df','af87ff','afaf00','afaf5f',
|
24
|
+
'afaf87','afafaf','afafdf','afafff','afdf00','afdf5f','afdf87','afdfaf',
|
25
|
+
'afdfdf','afdfff','afff00','afff5f','afff87','afffaf','afffdf','afffff',
|
26
|
+
'df0000','df005f','df0087','df00af','df00df','df00ff','df5f00','df5f5f',
|
27
|
+
'df5f87','df5faf','df5fdf','df5fff','df8700','df875f','df8787','df87af',
|
28
|
+
'df87df','df87ff','dfaf00','dfaf5f','dfaf87','dfafaf','dfafdf','dfafff',
|
29
|
+
'dfdf00','dfdf5f','dfdf87','dfdfaf','dfdfdf','dfdfff','dfff00','dfff5f',
|
30
|
+
'dfff87','dfffaf','dfffdf','dfffff','ff0000','ff005f','ff0087','ff00af',
|
31
|
+
'ff00df','ff00ff','ff5f00','ff5f5f','ff5f87','ff5faf','ff5fdf','ff5fff',
|
32
|
+
'ff8700','ff875f','ff8787','ff87af','ff87df','ff87ff','ffaf00','ffaf5f',
|
33
|
+
'ffaf87','ffafaf','ffafdf','ffafff','ffdf00','ffdf5f','ffdf87','ffdfaf',
|
34
|
+
'ffdfdf','ffdfff','ffff00','ffff5f','ffff87','ffffaf','ffffdf','ffffff',
|
35
|
+
'080808','121212','1c1c1c','262626','303030','3a3a3a','444444','4e4e4e',
|
36
|
+
'585858','606060','666666','767676','808080','8a8a8a','949494','9e9e9e',
|
37
|
+
'a8a8a8','b2b2b2','bcbcbc','c6c6c6','d0d0d0','dadada','e4e4e4','eeeeee'
|
38
|
+
]
|
39
|
+
@@Col_tabs_16 = {
|
40
|
+
:xterm => ['000000', 'CD0000', '00CD00', 'CDCD00', '0000EE', 'CD00CD', '00CDCD', 'E5E5E5', '7F7F7F', 'FF0000', '00FF00', 'FFFF00', '5C5CFF', 'FF00FF', '00FFFF', 'FFFFFF'],
|
41
|
+
:vga => ['000000', 'AA0000', '00AA00', 'AA5500', '0000AA', 'AA00AA', '00AAAA', 'AAAAAA', '555555', 'FF5555', '55FF55', 'FFFF55', '5555FF', 'FF55FF', '55FFFF', 'FFFFFF'],
|
42
|
+
:cmd => ['000000', '800000', '008000', '808000', '000080', '800080', '008080', 'C0C0C0', '808080', 'FF0000', '00FF00', 'FFFF00', '0000FF', 'FF00FF', '00FFFF', 'FFFFFF'],
|
43
|
+
:osx_term => ['000000', 'C23621', '25BC24', 'ADAD27', '492EE1', 'D338D3', '33BBC8', 'CBCCCD', '818383', 'FC391F', '31E722', 'EAEC23', '5833FF', 'F935F8', '14F0F0', 'E9EBEB']
|
44
|
+
}
|
45
|
+
@@CSS_blink_keyframes = '<style>@keyframes term_blink { 0%,50% { opacity: 1; } 51%,100% { opacity: 0; } }</style>'
|
46
|
+
def initialize(font_styles = [nil]*10, k_21_is_double_underline = true, k_1_is_bold_and_bright = true, k_turn_eol_into_br = false, col_tab_16 = :xterm)
|
47
|
+
@k_21_is_double_underline = k_21_is_double_underline;
|
48
|
+
@k_1_is_bold_and_bright = k_1_is_bold_and_bright;
|
49
|
+
@k_turn_eol_into_br = k_turn_eol_into_br;
|
50
|
+
col_tab_16 = @@Col_tabs_16[col_tab_16] if(col_tab_16.class == Symbol)
|
51
|
+
@locol = col_tab_16[0,8]
|
52
|
+
@hicol = col_tab_16[8,8]
|
53
|
+
@curcol = @locol
|
54
|
+
@font_styles = font_styles
|
55
|
+
@html_escapes = @@HTML_escapes.clone
|
56
|
+
@html_escapes["\r"], @html_escapes["\n"] = '', '<br/>' if(@k_turn_eol_into_br)
|
57
|
+
@prv_css = {}
|
58
|
+
@cur_css = {}
|
59
|
+
@inv = false # Inverted mode on?
|
60
|
+
@putblnk = false # Wrote blink tag keyframes? Guard to write them only once, when needed.
|
61
|
+
@fsm_stack = []
|
62
|
+
@fsm_top = 0
|
63
|
+
class << self
|
64
|
+
attr_accessor :_ansi_sgr_to_html_actions
|
65
|
+
private :_ansi_sgr_to_html_actions, :_ansi_sgr_to_html_actions=
|
66
|
+
end
|
67
|
+
self._ansi_sgr_to_html_actions = [
|
68
|
+
0, 1, 0, 1, 1, 1, 2, 1,
|
69
|
+
3, 1, 4, 1, 5, 1, 6, 1,
|
70
|
+
7, 1, 8, 1, 9, 1, 10, 1,
|
71
|
+
11, 1, 12, 1, 13, 1, 14, 1,
|
72
|
+
15, 1, 16, 1, 17, 1, 18, 1,
|
73
|
+
19, 1, 20, 1, 21, 1, 22, 1,
|
74
|
+
23, 1, 24, 1, 25, 1, 26, 1,
|
75
|
+
27, 1, 28, 1, 29, 1, 30, 1,
|
76
|
+
31, 1, 32, 2, 2, 1, 2, 4,
|
77
|
+
1, 2, 6, 1, 2, 8, 1, 2,
|
78
|
+
10, 1, 2, 11, 1, 2, 13, 1,
|
79
|
+
2, 15, 1, 2, 17, 1, 2, 29,
|
80
|
+
1
|
81
|
+
]
|
82
|
+
class << self
|
83
|
+
attr_accessor :_ansi_sgr_to_html_key_offsets
|
84
|
+
private :_ansi_sgr_to_html_key_offsets, :_ansi_sgr_to_html_key_offsets=
|
85
|
+
end
|
86
|
+
self._ansi_sgr_to_html_key_offsets = [
|
87
|
+
0, 0, 7, 8, 20, 22, 26, 37,
|
88
|
+
49, 55, 56, 58, 59, 63, 66, 67,
|
89
|
+
71, 74, 75, 79, 83, 87, 94, 102,
|
90
|
+
110, 121, 127, 128, 130, 131, 135, 138,
|
91
|
+
144, 147, 148, 152, 156, 167, 178, 181,
|
92
|
+
187, 190, 191, 195
|
93
|
+
]
|
94
|
+
class << self
|
95
|
+
attr_accessor :_ansi_sgr_to_html_trans_keys
|
96
|
+
private :_ansi_sgr_to_html_trans_keys, :_ansi_sgr_to_html_trans_keys=
|
97
|
+
end
|
98
|
+
self._ansi_sgr_to_html_trans_keys = [
|
99
|
+
10, 13, 27, 34, 38, 60, 62, 91,
|
100
|
+
48, 49, 50, 51, 52, 53, 54, 55,
|
101
|
+
56, 57, 59, 109, 59, 109, 59, 109,
|
102
|
+
48, 57, 49, 50, 51, 52, 53, 54,
|
103
|
+
55, 56, 57, 59, 109, 48, 49, 50,
|
104
|
+
51, 52, 53, 54, 55, 56, 57, 59,
|
105
|
+
109, 56, 57, 59, 109, 48, 55, 59,
|
106
|
+
50, 53, 59, 49, 50, 48, 57, 59,
|
107
|
+
48, 57, 59, 49, 50, 48, 57, 59,
|
108
|
+
48, 57, 59, 49, 50, 48, 57, 59,
|
109
|
+
109, 48, 57, 59, 109, 48, 57, 53,
|
110
|
+
59, 109, 48, 52, 54, 57, 54, 55,
|
111
|
+
56, 57, 59, 109, 48, 53, 54, 55,
|
112
|
+
56, 57, 59, 109, 48, 53, 49, 50,
|
113
|
+
51, 52, 53, 54, 55, 56, 57, 59,
|
114
|
+
109, 56, 57, 59, 109, 48, 55, 59,
|
115
|
+
50, 53, 59, 49, 50, 48, 57, 59,
|
116
|
+
48, 57, 53, 59, 48, 52, 54, 57,
|
117
|
+
59, 48, 53, 59, 49, 50, 48, 57,
|
118
|
+
59, 109, 48, 57, 49, 50, 51, 52,
|
119
|
+
53, 54, 55, 56, 57, 59, 109, 49,
|
120
|
+
50, 51, 52, 53, 54, 55, 56, 57,
|
121
|
+
59, 109, 59, 48, 57, 53, 59, 48,
|
122
|
+
52, 54, 57, 59, 48, 53, 59, 49,
|
123
|
+
50, 48, 57, 10, 13, 27, 34, 38,
|
124
|
+
60, 62, 0
|
125
|
+
]
|
126
|
+
class << self
|
127
|
+
attr_accessor :_ansi_sgr_to_html_single_lengths
|
128
|
+
private :_ansi_sgr_to_html_single_lengths, :_ansi_sgr_to_html_single_lengths=
|
129
|
+
end
|
130
|
+
self._ansi_sgr_to_html_single_lengths = [
|
131
|
+
0, 7, 1, 12, 2, 2, 11, 12,
|
132
|
+
4, 1, 2, 1, 2, 1, 1, 2,
|
133
|
+
1, 1, 2, 2, 2, 3, 6, 6,
|
134
|
+
11, 4, 1, 2, 1, 2, 1, 2,
|
135
|
+
1, 1, 2, 2, 11, 11, 1, 2,
|
136
|
+
1, 1, 2, 7
|
137
|
+
]
|
138
|
+
class << self
|
139
|
+
attr_accessor :_ansi_sgr_to_html_range_lengths
|
140
|
+
private :_ansi_sgr_to_html_range_lengths, :_ansi_sgr_to_html_range_lengths=
|
141
|
+
end
|
142
|
+
self._ansi_sgr_to_html_range_lengths = [
|
143
|
+
0, 0, 0, 0, 0, 1, 0, 0,
|
144
|
+
1, 0, 0, 0, 1, 1, 0, 1,
|
145
|
+
1, 0, 1, 1, 1, 2, 1, 1,
|
146
|
+
0, 1, 0, 0, 0, 1, 1, 2,
|
147
|
+
1, 0, 1, 1, 0, 0, 1, 2,
|
148
|
+
1, 0, 1, 0
|
149
|
+
]
|
150
|
+
class << self
|
151
|
+
attr_accessor :_ansi_sgr_to_html_index_offsets
|
152
|
+
private :_ansi_sgr_to_html_index_offsets, :_ansi_sgr_to_html_index_offsets=
|
153
|
+
end
|
154
|
+
self._ansi_sgr_to_html_index_offsets = [
|
155
|
+
0, 0, 8, 10, 23, 26, 30, 42,
|
156
|
+
55, 61, 63, 66, 68, 72, 75, 77,
|
157
|
+
81, 84, 86, 90, 94, 98, 104, 112,
|
158
|
+
120, 132, 138, 140, 143, 145, 149, 152,
|
159
|
+
157, 160, 162, 166, 170, 182, 194, 197,
|
160
|
+
202, 205, 207, 211
|
161
|
+
]
|
162
|
+
class << self
|
163
|
+
attr_accessor :_ansi_sgr_to_html_trans_targs
|
164
|
+
private :_ansi_sgr_to_html_trans_targs, :_ansi_sgr_to_html_trans_targs=
|
165
|
+
end
|
166
|
+
self._ansi_sgr_to_html_trans_targs = [
|
167
|
+
43, 43, 2, 43, 43, 43, 43, 1,
|
168
|
+
3, 0, 4, 5, 7, 8, 25, 35,
|
169
|
+
23, 24, 36, 37, 3, 43, 0, 3,
|
170
|
+
43, 0, 3, 43, 6, 0, 5, 7,
|
171
|
+
8, 25, 35, 23, 24, 36, 37, 3,
|
172
|
+
43, 0, 6, 6, 6, 6, 6, 6,
|
173
|
+
6, 6, 6, 6, 3, 43, 0, 9,
|
174
|
+
6, 3, 43, 6, 0, 10, 0, 11,
|
175
|
+
41, 0, 12, 0, 30, 31, 13, 0,
|
176
|
+
15, 14, 0, 15, 0, 38, 39, 16,
|
177
|
+
0, 18, 17, 0, 18, 0, 20, 21,
|
178
|
+
19, 0, 3, 43, 6, 0, 3, 43,
|
179
|
+
19, 0, 22, 3, 43, 19, 6, 0,
|
180
|
+
23, 24, 36, 37, 3, 43, 6, 0,
|
181
|
+
23, 24, 36, 37, 3, 43, 6, 0,
|
182
|
+
5, 7, 8, 25, 35, 23, 24, 36,
|
183
|
+
37, 3, 43, 0, 26, 6, 3, 43,
|
184
|
+
6, 0, 27, 0, 28, 33, 0, 29,
|
185
|
+
0, 30, 31, 13, 0, 15, 13, 0,
|
186
|
+
32, 15, 13, 14, 0, 15, 14, 0,
|
187
|
+
34, 0, 20, 21, 19, 0, 3, 43,
|
188
|
+
6, 0, 5, 7, 8, 25, 35, 23,
|
189
|
+
24, 36, 37, 3, 43, 0, 5, 7,
|
190
|
+
8, 25, 35, 23, 24, 36, 37, 3,
|
191
|
+
43, 0, 18, 16, 0, 40, 18, 16,
|
192
|
+
17, 0, 18, 17, 0, 42, 0, 20,
|
193
|
+
21, 19, 0, 43, 43, 2, 43, 43,
|
194
|
+
43, 43, 1, 0
|
195
|
+
]
|
196
|
+
class << self
|
197
|
+
attr_accessor :_ansi_sgr_to_html_trans_actions
|
198
|
+
private :_ansi_sgr_to_html_trans_actions, :_ansi_sgr_to_html_trans_actions=
|
199
|
+
end
|
200
|
+
self._ansi_sgr_to_html_trans_actions = [
|
201
|
+
61, 61, 1, 61, 61, 61, 61, 63,
|
202
|
+
0, 0, 59, 0, 0, 0, 0, 0,
|
203
|
+
0, 0, 0, 0, 59, 94, 0, 0,
|
204
|
+
3, 0, 5, 67, 55, 0, 0, 0,
|
205
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
206
|
+
3, 0, 57, 7, 11, 15, 19, 25,
|
207
|
+
65, 29, 33, 37, 9, 70, 0, 0,
|
208
|
+
51, 13, 73, 39, 0, 0, 0, 0,
|
209
|
+
0, 0, 0, 0, 47, 47, 47, 0,
|
210
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
211
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
212
|
+
0, 0, 0, 3, 0, 0, 0, 3,
|
213
|
+
0, 0, 0, 0, 3, 0, 0, 0,
|
214
|
+
0, 0, 0, 0, 0, 3, 0, 0,
|
215
|
+
23, 23, 23, 23, 23, 82, 65, 0,
|
216
|
+
27, 27, 27, 27, 27, 27, 27, 27,
|
217
|
+
27, 27, 85, 0, 0, 53, 17, 76,
|
218
|
+
41, 0, 0, 0, 0, 0, 0, 0,
|
219
|
+
0, 49, 49, 49, 0, 0, 0, 0,
|
220
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
221
|
+
0, 0, 45, 45, 45, 0, 21, 79,
|
222
|
+
65, 0, 31, 31, 31, 31, 31, 31,
|
223
|
+
31, 31, 31, 31, 88, 0, 35, 35,
|
224
|
+
35, 35, 35, 35, 35, 35, 35, 35,
|
225
|
+
91, 0, 0, 0, 0, 0, 0, 0,
|
226
|
+
0, 0, 0, 0, 0, 0, 0, 43,
|
227
|
+
43, 43, 0, 61, 61, 1, 61, 61,
|
228
|
+
61, 61, 63, 0
|
229
|
+
]
|
230
|
+
class << self
|
231
|
+
attr_accessor :ansi_sgr_to_html_start
|
232
|
+
end
|
233
|
+
self.ansi_sgr_to_html_start = 43;
|
234
|
+
class << self
|
235
|
+
attr_accessor :ansi_sgr_to_html_first_final
|
236
|
+
end
|
237
|
+
self.ansi_sgr_to_html_first_final = 43;
|
238
|
+
class << self
|
239
|
+
attr_accessor :ansi_sgr_to_html_error
|
240
|
+
end
|
241
|
+
self.ansi_sgr_to_html_error = 0;
|
242
|
+
class << self
|
243
|
+
attr_accessor :ansi_sgr_to_html_en_main
|
244
|
+
end
|
245
|
+
self.ansi_sgr_to_html_en_main = 43;
|
246
|
+
end
|
247
|
+
def convert(i, o=nil) # i is string, o can be anything with <<
|
248
|
+
o = '' unless o
|
249
|
+
begin
|
250
|
+
p ||= 0
|
251
|
+
pe ||= i.length
|
252
|
+
@fsm_cs = ansi_sgr_to_html_start
|
253
|
+
end
|
254
|
+
begin
|
255
|
+
_klen, _trans, _keys, _acts, _nacts = nil
|
256
|
+
_goto_level = 0
|
257
|
+
_resume = 10
|
258
|
+
_eof_trans = 15
|
259
|
+
_again = 20
|
260
|
+
_test_eof = 30
|
261
|
+
_out = 40
|
262
|
+
while true
|
263
|
+
_trigger_goto = false
|
264
|
+
if _goto_level <= 0
|
265
|
+
if p == pe
|
266
|
+
_goto_level = _test_eof
|
267
|
+
next
|
268
|
+
end
|
269
|
+
if @fsm_cs == 0
|
270
|
+
_goto_level = _out
|
271
|
+
next
|
272
|
+
end
|
273
|
+
end
|
274
|
+
if _goto_level <= _resume
|
275
|
+
_keys = _ansi_sgr_to_html_key_offsets[ @fsm_cs]
|
276
|
+
_trans = _ansi_sgr_to_html_index_offsets[ @fsm_cs]
|
277
|
+
_klen = _ansi_sgr_to_html_single_lengths[ @fsm_cs]
|
278
|
+
_break_match = false
|
279
|
+
begin
|
280
|
+
if _klen > 0
|
281
|
+
_lower = _keys
|
282
|
+
_upper = _keys + _klen - 1
|
283
|
+
loop do
|
284
|
+
break if _upper < _lower
|
285
|
+
_mid = _lower + ( (_upper - _lower) >> 1 )
|
286
|
+
if i[p].ord < _ansi_sgr_to_html_trans_keys[_mid]
|
287
|
+
_upper = _mid - 1
|
288
|
+
elsif i[p].ord > _ansi_sgr_to_html_trans_keys[_mid]
|
289
|
+
_lower = _mid + 1
|
290
|
+
else
|
291
|
+
_trans += (_mid - _keys)
|
292
|
+
_break_match = true
|
293
|
+
break
|
294
|
+
end
|
295
|
+
end # loop
|
296
|
+
break if _break_match
|
297
|
+
_keys += _klen
|
298
|
+
_trans += _klen
|
299
|
+
end
|
300
|
+
_klen = _ansi_sgr_to_html_range_lengths[ @fsm_cs]
|
301
|
+
if _klen > 0
|
302
|
+
_lower = _keys
|
303
|
+
_upper = _keys + (_klen << 1) - 2
|
304
|
+
loop do
|
305
|
+
break if _upper < _lower
|
306
|
+
_mid = _lower + (((_upper-_lower) >> 1) & ~1)
|
307
|
+
if i[p].ord < _ansi_sgr_to_html_trans_keys[_mid]
|
308
|
+
_upper = _mid - 2
|
309
|
+
elsif i[p].ord > _ansi_sgr_to_html_trans_keys[_mid+1]
|
310
|
+
_lower = _mid + 2
|
311
|
+
else
|
312
|
+
_trans += ((_mid - _keys) >> 1)
|
313
|
+
_break_match = true
|
314
|
+
break
|
315
|
+
end
|
316
|
+
end # loop
|
317
|
+
break if _break_match
|
318
|
+
_trans += _klen
|
319
|
+
end
|
320
|
+
end while false
|
321
|
+
@fsm_cs = _ansi_sgr_to_html_trans_targs[_trans]
|
322
|
+
if _ansi_sgr_to_html_trans_actions[_trans] != 0
|
323
|
+
_acts = _ansi_sgr_to_html_trans_actions[_trans]
|
324
|
+
_nacts = _ansi_sgr_to_html_actions[_acts]
|
325
|
+
_acts += 1
|
326
|
+
while _nacts > 0
|
327
|
+
_nacts -= 1
|
328
|
+
_acts += 1
|
329
|
+
case _ansi_sgr_to_html_actions[_acts - 1]
|
330
|
+
when 0 then
|
331
|
+
begin
|
332
|
+
end
|
333
|
+
when 1 then
|
334
|
+
begin
|
335
|
+
if(@cur_css != @prv_css) then o<<('</span>') if(@prv_css != {}); if(!@putblnk && @cur_css['animation']) then @putblnk=true; o<<@@CSS_blink_keyframes; end; o<<('<span style="'+@cur_css.map{|k,v|"#{k}:#{v}" if(v)}.compact.join(';')+'">') if(@cur_css != {}); end; @prv_css = @cur_css.clone; end
|
336
|
+
when 2 then
|
337
|
+
begin
|
338
|
+
@cur_css['font-weight'] = 'bold'; if(@k_1_is_bold_and_bright) then @curcol=@hicol; if(@cur_css['color']) then k = @locol.index(@cur_css['color'][1,6]); @cur_css['color'] = '#'+@curcol[k] if(k); end; end; end
|
339
|
+
when 3 then
|
340
|
+
begin
|
341
|
+
if(@k_21_is_double_underline) then @cur_css.delete('text-decoration'); @cur_css['border-bottom'] = '3px double'; else @cur_css.delete('font-weight'); @curcol = @locol; end; end
|
342
|
+
when 4 then
|
343
|
+
begin
|
344
|
+
@cur_css['font-weight'] = 'lighter'; end
|
345
|
+
when 5 then
|
346
|
+
begin
|
347
|
+
@cur_css.delete('font-weight'); end
|
348
|
+
when 6 then
|
349
|
+
begin
|
350
|
+
@cur_css['font-style'] = 'italic'; end
|
351
|
+
when 7 then
|
352
|
+
begin
|
353
|
+
@cur_css.delete('font-style'); end
|
354
|
+
when 8 then
|
355
|
+
begin
|
356
|
+
@cur_css.delete('border-bottom'); @cur_css['text-decoration'] = 'underline'; end
|
357
|
+
when 9 then
|
358
|
+
begin
|
359
|
+
@cur_css.delete('text-decoration'); @cur_css.delete('border-bottom'); end
|
360
|
+
when 10 then
|
361
|
+
begin
|
362
|
+
@cur_css['animation'] = 'term_blink normal 1.2s infinite ease-in-out'; end
|
363
|
+
when 11 then
|
364
|
+
begin
|
365
|
+
@cur_css['animation'] = 'term_blink normal 0.7s infinite ease-in-out'; end
|
366
|
+
when 12 then
|
367
|
+
begin
|
368
|
+
@cur_css.delete('animation'); end
|
369
|
+
when 13 then
|
370
|
+
begin
|
371
|
+
@cur_css['color'],@cur_css['background-color'] = @cur_css['background-color'],@cur_css['color'] unless(@inv); @inv = true; end
|
372
|
+
when 14 then
|
373
|
+
begin
|
374
|
+
@cur_css['color'],@cur_css['background-color'] = @cur_css['background-color'],@cur_css['color'] if(@inv); @inv = false; end
|
375
|
+
when 15 then
|
376
|
+
begin
|
377
|
+
end
|
378
|
+
when 16 then
|
379
|
+
begin
|
380
|
+
end
|
381
|
+
when 17 then
|
382
|
+
begin
|
383
|
+
@cur_css['text-decoration-line'] = 'line-through'; end
|
384
|
+
when 18 then
|
385
|
+
begin
|
386
|
+
@cur_css.delete('text-decoration-line'); end
|
387
|
+
when 19 then
|
388
|
+
begin
|
389
|
+
@cur_css['color'] = '#'+@curcol[ i[p].ord-0x30]; end
|
390
|
+
when 20 then
|
391
|
+
begin
|
392
|
+
@cur_css['background-color'] = '#'+@locol[ i[p].ord-0x30]; end
|
393
|
+
when 21 then
|
394
|
+
begin
|
395
|
+
@cur_css['color'] = '#'+@@Col_tab_256[i[p,3].to_i]; end
|
396
|
+
when 22 then
|
397
|
+
begin
|
398
|
+
@cur_css['background-color'] = '#'+@@Col_tab_256[i[p,3].to_i]; end
|
399
|
+
when 23 then
|
400
|
+
begin
|
401
|
+
@cur_css['color'] = 'rgb('+i[p,11].match(/(\d+);(\d+);(\d+)/)[1,3].join(',')+')'; end
|
402
|
+
when 24 then
|
403
|
+
begin
|
404
|
+
@cur_css['background-color'] = 'rgb('+i[p,11].match(/(\d+);(\d+);(\d+)/)[1,3].join(',')+')'; end
|
405
|
+
when 25 then
|
406
|
+
begin
|
407
|
+
@cur_css.delete('color'); end
|
408
|
+
when 26 then
|
409
|
+
begin
|
410
|
+
@cur_css.delete('background-color'); end
|
411
|
+
when 27 then
|
412
|
+
begin
|
413
|
+
if( i[p].ord == 0x30) then @cur_css.delete('font-family'); else @cur_css['font-family'] = @font_styles[ i[p].ord-0x30]; end; end
|
414
|
+
when 28 then
|
415
|
+
begin
|
416
|
+
@cur_css['font-family'] = @font_styles[10] end
|
417
|
+
when 29 then
|
418
|
+
begin
|
419
|
+
@cur_css = {}; @curcol = @locol end
|
420
|
+
when 30 then
|
421
|
+
begin
|
422
|
+
o<<(@html_escapes[ i[p].ord.chr]); end
|
423
|
+
when 31 then
|
424
|
+
begin
|
425
|
+
o<<( i[p].ord.chr); end
|
426
|
+
when 32 then
|
427
|
+
begin
|
428
|
+
end
|
429
|
+
end # action switch
|
430
|
+
end
|
431
|
+
end
|
432
|
+
if _trigger_goto
|
433
|
+
next
|
434
|
+
end
|
435
|
+
end
|
436
|
+
if _goto_level <= _again
|
437
|
+
if @fsm_cs == 0
|
438
|
+
_goto_level = _out
|
439
|
+
next
|
440
|
+
end
|
441
|
+
p += 1
|
442
|
+
if p != pe
|
443
|
+
_goto_level = _resume
|
444
|
+
next
|
445
|
+
end
|
446
|
+
end
|
447
|
+
if _goto_level <= _test_eof
|
448
|
+
end
|
449
|
+
if _goto_level <= _out
|
450
|
+
break
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
o << '</span>' if(@prv_css != {})
|
455
|
+
o
|
456
|
+
end
|
457
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ansi_sgr_to_html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tassilo Philipp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Converter for complete ANSI SGR codes to HTML. Similar to ansitags gem,
|
15
|
+
but smaller output (no nested spans), faster (converts everything in one pass),
|
16
|
+
more flexible (init options to specify palette, line ending conversion, etc.) and
|
17
|
+
better SGR code support (handles ';'-separated code-sequences, fonts, blink(!) and
|
18
|
+
more than 16 colors).
|
19
|
+
email: tphilipp@potion-studios.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/ansi_sgr_to_html.rb
|
25
|
+
homepage:
|
26
|
+
licenses:
|
27
|
+
- ISC
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.9.1
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.29
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: Converts strings with ANSI SGR codes to HTML
|
50
|
+
test_files: []
|