Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ jobs:
cache: false

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

- name: Build notebook
run: go build -o rz-notebook-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm }} -ldflags "-X main.NBVERSION=$(git rev-list -1 HEAD)"
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ jobs:
cache: false

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

- name: Build notebook
run: go build -o rz-notebook -ldflags "-X main.NBVERSION=$(git rev-list -1 HEAD)"
Expand Down
4 changes: 2 additions & 2 deletions assets/templates/about.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.spacing-top { margin: 3px 0px 0px 0px; }
.spacing-left { margin: 0px 3px 0px 0px; }
.spacing-top { margin: 3px 0px 0px 0px !important; }
.spacing-left { margin: 0px 3px 0px 0px !important; }
.align-center { text-align: center; }
.pipe { color: #e85600; border-color: #e85600; }
.pipe:hover { background: #e85600; border-color: #e85600; }
Expand Down
4 changes: 2 additions & 2 deletions assets/templates/error.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="stylesheet" href="{{ .root }}static/spectre.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.spacing-top { margin: 3px 0px 0px 0px; }
.spacing-left { margin: 0px 3px 0px 0px; }
.spacing-top { margin: 3px 0px 0px 0px !important; }
.spacing-left { margin: 0px 3px 0px 0px !important; }
.align-center { text-align: center; }
</style>
</head>
Expand Down
27 changes: 26 additions & 1 deletion assets/templates/output.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,34 @@
@font-face { font-family: 'Inconsolata'; src: URL('{{ .root }}static/inconsolata.ttf') format('truetype'); }
html, body { width: 100%; height: 100%; background-color: #4b4b4b; color: #eeeeee; font-family: Inconsolata; }
pre { width: 100%; height: 100%; margin: 5px; background-color: inherit; color: inherit; line-height: 10px; }
table {
border-collapse: separate;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
background-color: inherit;
color: inherit;
height: 100%;
text-align: left;
}
th {
font-family: sans-serif;
text-align: left;
}
td, th {
padding: 3px 10px;
}
tbody tr {
border-bottom: 1px solid #dddddd;
}
tbody tr:nth-of-type(even) {
-webkit-backdrop-filter: invert(40%);
backdrop-filter: invert(40%);
}
tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
</style>
</head>
<body>
<pre>{{ .output | raw }}</pre>
{{ .output | raw }}
</body>
</html>
4 changes: 2 additions & 2 deletions assets/templates/page-new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.spacing-top { margin: 3px 0px 0px 0px; }
.spacing-left { margin: 0px 3px 0px 0px; }
.spacing-top { margin: 3px 0px 0px 0px !important; }
.spacing-left { margin: 0px 3px 0px 0px !important; }
.navbar-fixed-height { height: 32px; }
.icon-height { height: 20px; }
iframe { border: 0px; width: 100%; height: 100% }
Expand Down
4 changes: 2 additions & 2 deletions assets/templates/page-view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
@font-face { font-family: 'Inconsolata'; src: URL('{{ .root }}static/inconsolata.ttf') format('truetype'); }
.spacing-top { margin: 3px 0px 0px 0px; }
.spacing-left { margin: 0px 3px 0px 0px; }
.spacing-top { margin: 3px 0px 0px 0px !important; }
.spacing-left { margin: 0px 3px 0px 0px !important; }
.align-center { text-align: center; }
.navbar-fixed-height { height: 32px; }
.icon-height { height: 20px; }
Expand Down
4 changes: 2 additions & 2 deletions assets/templates/settings-edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.spacing-top { margin: 3px 0px 0px 0px; }
.spacing-left { margin: 0px 3px 0px 0px; }
.spacing-top { margin: 3px 0px 0px 0px !important; }
.spacing-left { margin: 0px 3px 0px 0px !important; }
.navbar-fixed-height { height: 32px; }
.inline { display: inline; }
.icon-height { height: 20px; }
Expand Down
4 changes: 2 additions & 2 deletions assets/templates/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="stylesheet" href="{{ $root }}static/spectre.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.spacing-top { margin: 3px 0px 0px 0px; }
.spacing-left { margin: 0px 3px 0px 0px; }
.spacing-top { margin: 3px 0px 0px 0px !important; }
.spacing-left { margin: 0px 3px 0px 0px !important; }
.height-32px { height: 32px; }
.align-center { text-align: center; }
.pipe { color: #e85600; border-color: #e85600; }
Expand Down
123 changes: 78 additions & 45 deletions output.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main

import (
"encoding/csv"
"fmt"
"html"
"io"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -288,13 +291,42 @@ var color265 = map[string]string{
}

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

func toHtml(raw []byte) []byte {
func fromRawToString(raw []byte) string {
var output = strings.TrimSuffix(string(raw), "\x00")
output = strings.ReplaceAll(output, "\r", "")
output = strings.Trim(output, "\n")
return strings.Trim(output, "\n")
}

func toCsv(output string) ([]byte, bool) {
reader := csv.NewReader(strings.NewReader(output))
reader.Comma = ','

var htmlStr = "<table>\n"
for i := 0; ; i++ {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil || (i == 0 && len(record) < 2) {
return nil, false
}

htmlStr += "<tr>"
for _, elem := range record {
htmlStr += "\n<td>"
htmlStr += html.EscapeString(elem)
htmlStr += "</td>"
}
htmlStr += "\n</tr>\n"
}

htmlStr += "</table>"
return []byte(htmlStr), true
}

func toHtml(output string) []byte {
if output == "" {
return []byte{}
}
Expand All @@ -303,20 +335,21 @@ func toHtml(raw []byte) []byte {
output = strings.ReplaceAll(output, ">", "&gt;")
output = strings.ReplaceAll(output, "\"", "&quot;")
output = strings.ReplaceAll(output, "'", "&apos;")
var html = ""
var htmlStr = ""
tokens := strings.Split(output, "\x1b")
for _, token := range tokens {
if token == "" {
continue
}

if strings.HasPrefix(token, "[H") ||
strings.HasPrefix(token, "[s") ||
strings.HasPrefix(token, "[u") ||
strings.HasPrefix(token, "[J") ||
strings.HasPrefix(token, "[K") {
html += token[2:]
htmlStr += token[2:]
} else if strings.HasPrefix(token, "[#;#R") {
html += token[5:]
htmlStr += token[5:]
} else if strings.HasPrefix(token, "[#") ||
strings.HasPrefix(token, "[0m") ||
strings.HasPrefix(token, "[0J") ||
Expand All @@ -326,41 +359,41 @@ func toHtml(raw []byte) []byte {
strings.HasPrefix(token, "[1K") ||
strings.HasPrefix(token, "[2K") ||
strings.HasPrefix(token, "[6n") {
html += token[3:]
htmlStr += token[3:]
} else if strings.HasPrefix(token, "[1m") ||
strings.HasPrefix(token, "[2m") {
html += "<b>"
html += token[3:]
html += "</b>"
htmlStr += "<b>"
htmlStr += token[3:]
htmlStr += "</b>"
} else if strings.HasPrefix(token, "[3m") {
html += "<i>"
html += token[3:]
html += "</i>"
htmlStr += "<i>"
htmlStr += token[3:]
htmlStr += "</i>"
} else if strings.HasPrefix(token, "[4m") {
html += "<ins>"
html += token[3:]
html += "</ins>"
htmlStr += "<ins>"
htmlStr += token[3:]
htmlStr += "</ins>"
} else if strings.HasPrefix(token, "[5m") {
html += "<blink>"
html += token[3:]
html += "</blink>"
htmlStr += "<blink>"
htmlStr += token[3:]
htmlStr += "</blink>"
} else if strings.HasPrefix(token, "[7m") ||
strings.HasPrefix(token, "[8m") {
html += token[3:]
htmlStr += token[3:]
} else if strings.HasPrefix(token, "[9m") {
html += "<strike>"
html += token[3:]
html += "</strike>"
htmlStr += "<strike>"
htmlStr += token[3:]
htmlStr += "</strike>"
} else if strings.HasPrefix(token, "[22m") ||
strings.HasPrefix(token, "[23m") ||
strings.HasPrefix(token, "[24m") ||
strings.HasPrefix(token, "[25m") ||
strings.HasPrefix(token, "[28m") ||
strings.HasPrefix(token, "[27m") ||
strings.HasPrefix(token, "[29m") {
html += token[4:]
htmlStr += token[4:]
} else if token == "7" || token == "8" {
html += token[1:]
htmlStr += token[1:]
} else {
var btok = []byte(token)
var found = col256.FindSubmatch(btok)
Expand All @@ -371,14 +404,14 @@ func toHtml(raw []byte) []byte {
color, ok := color265[string(found[2])]
if ok {
if string(found[1]) == "48" {
html += fmt.Sprintf("<span style=\"background-color: %s\">", color)
htmlStr += fmt.Sprintf("<span style=\"background-color: %s\">", color)
} else {
html += fmt.Sprintf("<span style=\"color: %s\">", color)
htmlStr += fmt.Sprintf("<span style=\"color: %s\">", color)
}
}
html += token[len(found[0]):]
htmlStr += token[len(found[0]):]
if ok {
html += "</span>"
htmlStr += "</span>"
}
continue
}
Expand All @@ -395,21 +428,21 @@ func toHtml(raw []byte) []byte {
g &= 0xFF
b &= 0xFF
if string(found[1]) == "48" {
html += fmt.Sprintf("<span style=\"background-color: #%02x%02x%02x\">", r, g, b)
htmlStr += fmt.Sprintf("<span style=\"background-color: #%02x%02x%02x\">", r, g, b)
} else {
html += fmt.Sprintf("<span style=\"color: #%02x%02x%02x\">", r, g, b)
htmlStr += fmt.Sprintf("<span style=\"color: #%02x%02x%02x\">", r, g, b)
}
html += token[len(found[0]):]
html += "</span>"
htmlStr += token[len(found[0]):]
htmlStr += "</span>"
continue
}

found = escape.FindSubmatch(btok)
if len(found) < 1 {
html += token
htmlStr += token
continue
} else if string(found[len(found)-1]) != "m" {
html += token[len(found[0]):]
htmlStr += token[len(found[0]):]
continue
} else if len(token) == len(found[0]) {
continue
Expand All @@ -424,30 +457,30 @@ func toHtml(raw []byte) []byte {
e = e[:len(e)-1]
}
if e == "0" {
html += tags
htmlStr += tags
tags = ""
continue
} else if tag, ok := tagMap[e]; ok {
html += fmt.Sprintf("<%s>", tag)
htmlStr += fmt.Sprintf("<%s>", tag)
tags += fmt.Sprintf("</%s>", tag)
} else if len(e) == 2 && (e[0] == '3' || e[0] == '4' || e[0] == '9') && e[1] != '8' {
color, _ := colMap[string(e[1])]
if e[0] == '4' {
html += fmt.Sprintf("<span style=\"background-color: %s\">", color)
htmlStr += fmt.Sprintf("<span style=\"background-color: %s\">", color)
} else {
html += fmt.Sprintf("<span style=\"color: %s\">", color)
htmlStr += fmt.Sprintf("<span style=\"color: %s\">", color)
}
tags += "</span>"
} else if len(e) == 3 && e[0] == '1' && e[1] == '0' && e[2] != '8' {
color, _ := colMap[string(e[1])]
html += fmt.Sprintf("<span style=\"background-color: %s\">", color)
htmlStr += fmt.Sprintf("<span style=\"background-color: %s\">", color)
tags += "</span>"
}
}
html += token[len(found[0]):]
html += tags
htmlStr += token[len(found[0]):]
htmlStr += tags
}
}
html = strings.ReplaceAll(html, "\n", "<br>\n")
return []byte(html)
htmlStr = strings.ReplaceAll(htmlStr, "\n", "<br>\n")
return []byte("<pre>" + htmlStr + "</pre>")
}
Loading