Skip to content

Commit 00a44a8

Browse files
authored
Convert CSV output to table & fix CI (#11)
1 parent 51b8ddd commit 00a44a8

File tree

11 files changed

+170
-112
lines changed

11 files changed

+170
-112
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,7 @@ jobs:
117117
cache: false
118118

119119
- name: Get project dependencies
120-
run: |
121-
# we do not cross-compile this.
122-
GOOS=linux GOARCH=amd64 GOARM="" GOBIN="$PWD/bin/" go install github.com/jessevdk/go-assets-builder@latest
123-
$PWD/bin/go-assets-builder assets -o assets.go
124-
# download the modules.
125-
go mod download
120+
run: go mod download
126121

127122
- name: Build notebook
128123
run: go build -o rz-notebook-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm }} -ldflags "-X main.NBVERSION=$(git rev-list -1 HEAD)"

.github/workflows/ci.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ jobs:
2727
cache: false
2828

2929
- name: Get project dependencies
30-
run: |
31-
# we do not cross-compile this.
32-
GOOS=linux GOARCH=amd64 GOARM="" GOBIN="$PWD/bin/" go install github.com/jessevdk/go-assets-builder@latest
33-
$PWD/bin/go-assets-builder assets -o assets.go
34-
# download the modules.
35-
go mod download
30+
run: go mod download
3631

3732
- name: Build notebook
3833
run: go build -o rz-notebook -ldflags "-X main.NBVERSION=$(git rev-list -1 HEAD)"

assets/templates/about.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
99
<style type="text/css">
10-
.spacing-top { margin: 3px 0px 0px 0px; }
11-
.spacing-left { margin: 0px 3px 0px 0px; }
10+
.spacing-top { margin: 3px 0px 0px 0px !important; }
11+
.spacing-left { margin: 0px 3px 0px 0px !important; }
1212
.align-center { text-align: center; }
1313
.pipe { color: #e85600; border-color: #e85600; }
1414
.pipe:hover { background: #e85600; border-color: #e85600; }

assets/templates/error.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="stylesheet" href="{{ .root }}static/spectre.min.css">
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
99
<style type="text/css">
10-
.spacing-top { margin: 3px 0px 0px 0px; }
11-
.spacing-left { margin: 0px 3px 0px 0px; }
10+
.spacing-top { margin: 3px 0px 0px 0px !important; }
11+
.spacing-left { margin: 0px 3px 0px 0px !important; }
1212
.align-center { text-align: center; }
1313
</style>
1414
</head>

assets/templates/output.tmpl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,34 @@
2222
@font-face { font-family: 'Inconsolata'; src: URL('{{ .root }}static/inconsolata.ttf') format('truetype'); }
2323
html, body { width: 100%; height: 100%; background-color: #4b4b4b; color: #eeeeee; font-family: Inconsolata; }
2424
pre { width: 100%; height: 100%; margin: 5px; background-color: inherit; color: inherit; line-height: 10px; }
25+
table {
26+
border-collapse: separate;
27+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
28+
background-color: inherit;
29+
color: inherit;
30+
height: 100%;
31+
text-align: left;
32+
}
33+
th {
34+
font-family: sans-serif;
35+
text-align: left;
36+
}
37+
td, th {
38+
padding: 3px 10px;
39+
}
40+
tbody tr {
41+
border-bottom: 1px solid #dddddd;
42+
}
43+
tbody tr:nth-of-type(even) {
44+
-webkit-backdrop-filter: invert(40%);
45+
backdrop-filter: invert(40%);
46+
}
47+
tbody tr:last-of-type {
48+
border-bottom: 2px solid #009879;
49+
}
2550
</style>
2651
</head>
2752
<body>
28-
<pre>{{ .output | raw }}</pre>
53+
{{ .output | raw }}
2954
</body>
3055
</html>

assets/templates/page-new.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
99
<style type="text/css">
10-
.spacing-top { margin: 3px 0px 0px 0px; }
11-
.spacing-left { margin: 0px 3px 0px 0px; }
10+
.spacing-top { margin: 3px 0px 0px 0px !important; }
11+
.spacing-left { margin: 0px 3px 0px 0px !important; }
1212
.navbar-fixed-height { height: 32px; }
1313
.icon-height { height: 20px; }
1414
iframe { border: 0px; width: 100%; height: 100% }

assets/templates/page-view.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
99
<style type="text/css">
1010
@font-face { font-family: 'Inconsolata'; src: URL('{{ .root }}static/inconsolata.ttf') format('truetype'); }
11-
.spacing-top { margin: 3px 0px 0px 0px; }
12-
.spacing-left { margin: 0px 3px 0px 0px; }
11+
.spacing-top { margin: 3px 0px 0px 0px !important; }
12+
.spacing-left { margin: 0px 3px 0px 0px !important; }
1313
.align-center { text-align: center; }
1414
.navbar-fixed-height { height: 32px; }
1515
.icon-height { height: 20px; }

assets/templates/settings-edit.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
99
<style type="text/css">
10-
.spacing-top { margin: 3px 0px 0px 0px; }
11-
.spacing-left { margin: 0px 3px 0px 0px; }
10+
.spacing-top { margin: 3px 0px 0px 0px !important; }
11+
.spacing-left { margin: 0px 3px 0px 0px !important; }
1212
.navbar-fixed-height { height: 32px; }
1313
.inline { display: inline; }
1414
.icon-height { height: 20px; }

assets/templates/settings.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
88
<meta name="viewport" content="width=device-width, initial-scale=1" />
99
<style type="text/css">
10-
.spacing-top { margin: 3px 0px 0px 0px; }
11-
.spacing-left { margin: 0px 3px 0px 0px; }
10+
.spacing-top { margin: 3px 0px 0px 0px !important; }
11+
.spacing-left { margin: 0px 3px 0px 0px !important; }
1212
.height-32px { height: 32px; }
1313
.align-center { text-align: center; }
1414
.pipe { color: #e85600; border-color: #e85600; }

output.go

Lines changed: 78 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package main
22

33
import (
4+
"encoding/csv"
45
"fmt"
6+
"html"
7+
"io"
58
"regexp"
69
"strconv"
710
"strings"
@@ -288,13 +291,42 @@ var color265 = map[string]string{
288291
}
289292

290293
var col256 = regexp.MustCompile(`^\[([34]8);5;(\d+)m`)
291-
var colrgb = regexp.MustCompile(`^\[([34]8);2;(\d+);(\d+);(\d+)m`)
292-
var escape = regexp.MustCompile(`^\[(\d+;)?(\d+;)?(\d+;)?(\d+;)?(\d+)([A-Za-z])`)
294+
var colrgb = regexp.MustCompile(`^\[([34]8|1);2;(\d+);(\d+);(\d+)m`)
295+
var escape = regexp.MustCompile(`^\[(;?\d+)+([A-Za-z])`)
293296

294-
func toHtml(raw []byte) []byte {
297+
func fromRawToString(raw []byte) string {
295298
var output = strings.TrimSuffix(string(raw), "\x00")
296299
output = strings.ReplaceAll(output, "\r", "")
297-
output = strings.Trim(output, "\n")
300+
return strings.Trim(output, "\n")
301+
}
302+
303+
func toCsv(output string) ([]byte, bool) {
304+
reader := csv.NewReader(strings.NewReader(output))
305+
reader.Comma = ','
306+
307+
var htmlStr = "<table>\n"
308+
for i := 0; ; i++ {
309+
record, err := reader.Read()
310+
if err == io.EOF {
311+
break
312+
} else if err != nil || (i == 0 && len(record) < 2) {
313+
return nil, false
314+
}
315+
316+
htmlStr += "<tr>"
317+
for _, elem := range record {
318+
htmlStr += "\n<td>"
319+
htmlStr += html.EscapeString(elem)
320+
htmlStr += "</td>"
321+
}
322+
htmlStr += "\n</tr>\n"
323+
}
324+
325+
htmlStr += "</table>"
326+
return []byte(htmlStr), true
327+
}
328+
329+
func toHtml(output string) []byte {
298330
if output == "" {
299331
return []byte{}
300332
}
@@ -303,20 +335,21 @@ func toHtml(raw []byte) []byte {
303335
output = strings.ReplaceAll(output, ">", "&gt;")
304336
output = strings.ReplaceAll(output, "\"", "&quot;")
305337
output = strings.ReplaceAll(output, "'", "&apos;")
306-
var html = ""
338+
var htmlStr = ""
307339
tokens := strings.Split(output, "\x1b")
308340
for _, token := range tokens {
309341
if token == "" {
310342
continue
311343
}
344+
312345
if strings.HasPrefix(token, "[H") ||
313346
strings.HasPrefix(token, "[s") ||
314347
strings.HasPrefix(token, "[u") ||
315348
strings.HasPrefix(token, "[J") ||
316349
strings.HasPrefix(token, "[K") {
317-
html += token[2:]
350+
htmlStr += token[2:]
318351
} else if strings.HasPrefix(token, "[#;#R") {
319-
html += token[5:]
352+
htmlStr += token[5:]
320353
} else if strings.HasPrefix(token, "[#") ||
321354
strings.HasPrefix(token, "[0m") ||
322355
strings.HasPrefix(token, "[0J") ||
@@ -326,41 +359,41 @@ func toHtml(raw []byte) []byte {
326359
strings.HasPrefix(token, "[1K") ||
327360
strings.HasPrefix(token, "[2K") ||
328361
strings.HasPrefix(token, "[6n") {
329-
html += token[3:]
362+
htmlStr += token[3:]
330363
} else if strings.HasPrefix(token, "[1m") ||
331364
strings.HasPrefix(token, "[2m") {
332-
html += "<b>"
333-
html += token[3:]
334-
html += "</b>"
365+
htmlStr += "<b>"
366+
htmlStr += token[3:]
367+
htmlStr += "</b>"
335368
} else if strings.HasPrefix(token, "[3m") {
336-
html += "<i>"
337-
html += token[3:]
338-
html += "</i>"
369+
htmlStr += "<i>"
370+
htmlStr += token[3:]
371+
htmlStr += "</i>"
339372
} else if strings.HasPrefix(token, "[4m") {
340-
html += "<ins>"
341-
html += token[3:]
342-
html += "</ins>"
373+
htmlStr += "<ins>"
374+
htmlStr += token[3:]
375+
htmlStr += "</ins>"
343376
} else if strings.HasPrefix(token, "[5m") {
344-
html += "<blink>"
345-
html += token[3:]
346-
html += "</blink>"
377+
htmlStr += "<blink>"
378+
htmlStr += token[3:]
379+
htmlStr += "</blink>"
347380
} else if strings.HasPrefix(token, "[7m") ||
348381
strings.HasPrefix(token, "[8m") {
349-
html += token[3:]
382+
htmlStr += token[3:]
350383
} else if strings.HasPrefix(token, "[9m") {
351-
html += "<strike>"
352-
html += token[3:]
353-
html += "</strike>"
384+
htmlStr += "<strike>"
385+
htmlStr += token[3:]
386+
htmlStr += "</strike>"
354387
} else if strings.HasPrefix(token, "[22m") ||
355388
strings.HasPrefix(token, "[23m") ||
356389
strings.HasPrefix(token, "[24m") ||
357390
strings.HasPrefix(token, "[25m") ||
358391
strings.HasPrefix(token, "[28m") ||
359392
strings.HasPrefix(token, "[27m") ||
360393
strings.HasPrefix(token, "[29m") {
361-
html += token[4:]
394+
htmlStr += token[4:]
362395
} else if token == "7" || token == "8" {
363-
html += token[1:]
396+
htmlStr += token[1:]
364397
} else {
365398
var btok = []byte(token)
366399
var found = col256.FindSubmatch(btok)
@@ -371,14 +404,14 @@ func toHtml(raw []byte) []byte {
371404
color, ok := color265[string(found[2])]
372405
if ok {
373406
if string(found[1]) == "48" {
374-
html += fmt.Sprintf("<span style=\"background-color: %s\">", color)
407+
htmlStr += fmt.Sprintf("<span style=\"background-color: %s\">", color)
375408
} else {
376-
html += fmt.Sprintf("<span style=\"color: %s\">", color)
409+
htmlStr += fmt.Sprintf("<span style=\"color: %s\">", color)
377410
}
378411
}
379-
html += token[len(found[0]):]
412+
htmlStr += token[len(found[0]):]
380413
if ok {
381-
html += "</span>"
414+
htmlStr += "</span>"
382415
}
383416
continue
384417
}
@@ -395,21 +428,21 @@ func toHtml(raw []byte) []byte {
395428
g &= 0xFF
396429
b &= 0xFF
397430
if string(found[1]) == "48" {
398-
html += fmt.Sprintf("<span style=\"background-color: #%02x%02x%02x\">", r, g, b)
431+
htmlStr += fmt.Sprintf("<span style=\"background-color: #%02x%02x%02x\">", r, g, b)
399432
} else {
400-
html += fmt.Sprintf("<span style=\"color: #%02x%02x%02x\">", r, g, b)
433+
htmlStr += fmt.Sprintf("<span style=\"color: #%02x%02x%02x\">", r, g, b)
401434
}
402-
html += token[len(found[0]):]
403-
html += "</span>"
435+
htmlStr += token[len(found[0]):]
436+
htmlStr += "</span>"
404437
continue
405438
}
406439

407440
found = escape.FindSubmatch(btok)
408441
if len(found) < 1 {
409-
html += token
442+
htmlStr += token
410443
continue
411444
} else if string(found[len(found)-1]) != "m" {
412-
html += token[len(found[0]):]
445+
htmlStr += token[len(found[0]):]
413446
continue
414447
} else if len(token) == len(found[0]) {
415448
continue
@@ -424,30 +457,30 @@ func toHtml(raw []byte) []byte {
424457
e = e[:len(e)-1]
425458
}
426459
if e == "0" {
427-
html += tags
460+
htmlStr += tags
428461
tags = ""
429462
continue
430463
} else if tag, ok := tagMap[e]; ok {
431-
html += fmt.Sprintf("<%s>", tag)
464+
htmlStr += fmt.Sprintf("<%s>", tag)
432465
tags += fmt.Sprintf("</%s>", tag)
433466
} else if len(e) == 2 && (e[0] == '3' || e[0] == '4' || e[0] == '9') && e[1] != '8' {
434467
color, _ := colMap[string(e[1])]
435468
if e[0] == '4' {
436-
html += fmt.Sprintf("<span style=\"background-color: %s\">", color)
469+
htmlStr += fmt.Sprintf("<span style=\"background-color: %s\">", color)
437470
} else {
438-
html += fmt.Sprintf("<span style=\"color: %s\">", color)
471+
htmlStr += fmt.Sprintf("<span style=\"color: %s\">", color)
439472
}
440473
tags += "</span>"
441474
} else if len(e) == 3 && e[0] == '1' && e[1] == '0' && e[2] != '8' {
442475
color, _ := colMap[string(e[1])]
443-
html += fmt.Sprintf("<span style=\"background-color: %s\">", color)
476+
htmlStr += fmt.Sprintf("<span style=\"background-color: %s\">", color)
444477
tags += "</span>"
445478
}
446479
}
447-
html += token[len(found[0]):]
448-
html += tags
480+
htmlStr += token[len(found[0]):]
481+
htmlStr += tags
449482
}
450483
}
451-
html = strings.ReplaceAll(html, "\n", "<br>\n")
452-
return []byte(html)
484+
htmlStr = strings.ReplaceAll(htmlStr, "\n", "<br>\n")
485+
return []byte("<pre>" + htmlStr + "</pre>")
453486
}

0 commit comments

Comments
 (0)