32
32
# Handle codes with combined attributes and color.
33
33
# Handle isolated <bold> attributes with css.
34
34
# Strip more terminal control codes.
35
- # V0.23, 28 Feb 2016
35
+ # V0.26, 16 Nov 2019
36
36
# http://github.com/pixelb/scripts/commits/master/scripts/ansi2html.sh
37
37
38
38
gawk --version > /dev/null || exit 1
39
39
40
40
if [ " $1 " = " --version" ]; then
41
- printf ' 0.23 \n' && exit
41
+ printf ' 0.26 \n' && exit
42
42
fi
43
43
44
44
usage ()
115
115
<head>
116
116
<meta http-equiv=\" Content-Type\" content=\" text/html; charset=utf-8\" />
117
117
<style type=\" text/css\" >
118
+ pre { white-space: pre-wrap; }
118
119
"
119
120
[ " $body_only " ] || printf " .ef0,.f0 { color: #$P0 ; } .eb0,.b0 { background-color: #$P0 ; }
120
121
.ef1,.f1 { color: #$P1 ; } .eb1,.b1 { background-color: #$P1 ; }
@@ -235,6 +236,12 @@ sed "
235
236
# escape HTML (ampersand and quote done above)
236
237
s#>#\>#g; s#<#\<#g;
237
238
239
+ # handle truecolor
240
+ s#${p} 38;2;\([0-9]\{1,3\}\);\([0-9]\{1,3\}\);\([0-9]\{1,3\}\)m#\
241
+ <span style=\" color:rgb(\1\,\2\,\3\)\" >#g
242
+ s#${p} 48;2;\([0-9]\{1,3\}\);\([0-9]\{1,3\}\);\([0-9]\{1,3\}\)m#\
243
+ <span style=\" background-color:rgb(\1\,\2\,\3\)\" >#g
244
+
238
245
# normalize SGR codes a little
239
246
240
247
# split 256 colors out and mark so that they're not
@@ -310,7 +317,7 @@ s#\x0F#\"T0;#g
310
317
gawk '
311
318
function dump_line(l,del,c,blanks,ret) {
312
319
for(c=1;c<maxX;c++) {
313
- if ((c SUBSEP l) in attr || length (cur)) {
320
+ if ((c SUBSEP l) in attr || alength (cur)) {
314
321
ret = ret blanks fixas(cur,attr[c,l])
315
322
if(del) delete attr[c,l]
316
323
blanks=""
@@ -321,7 +328,7 @@ function dump_line(l,del,c,blanks,ret) {
321
328
blanks=""
322
329
} else blanks=blanks " "
323
330
}
324
- if(length (cur)) ret=ret blanks
331
+ if(alength (cur)) ret=ret blanks
325
332
return ret
326
333
}
327
334
@@ -332,12 +339,18 @@ function dump_screen(l,ret) {
332
339
}
333
340
334
341
function atos(a,i,ret) {
335
- for(i=1;i<=length (a);i++) if(i in a) ret=ret a[i]
342
+ for(i=1;i<=alength (a);i++) if(i in a) ret=ret a[i]
336
343
return ret
337
344
}
338
345
346
+ function alength(a, i, k) {
347
+ k = 0
348
+ for(i in a) k++
349
+ return k
350
+ }
351
+
339
352
function fixas(a,s,spc,i,attr,rm,ret) {
340
- spc=length (a)
353
+ spc=alength (a)
341
354
l=split(s,attr,">")
342
355
for(i=1;i<=spc;i++) {
343
356
rm=rm?rm:(a[i]!=attr[i]">")
0 commit comments