commit 56d2dafd20f779cd60a6ebebc8826dcba6673a91
parent 683861f99b210b38f01908304721d95c74c334e1
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 16 Nov 2022 02:40:20 -0500
greatly reduce generated size
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/cmd/art/main.go b/cmd/art/main.go
@@ -97,6 +97,8 @@ FoEVD2av5BES9MvnPsQulj9bU2lUokhBjM1+LERxbqfVfZ2ddAYRIMGF`
out += "</style>\n"
out += "<div style=\"font-family: monospace; background-color: #222;\">\n"
out += "<pre>\n"
+ spanOpen := false
+ prevClass := ""
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
c := im.At(i, j)
@@ -106,10 +108,22 @@ FoEVD2av5BES9MvnPsQulj9bU2lUokhBjM1+LERxbqfVfZ2ddAYRIMGF`
char := lines[j][i]
hex := HexFromRgbColor(c.(color.NRGBA))
class := colorsMap[hex]
- out += fmt.Sprintf(`<span class="%s">%s</span>`, class, string(char))
+ if class != prevClass {
+ prevClass = class
+ if spanOpen {
+ out += "</span>"
+ }
+ out += fmt.Sprintf(`<span class="%s">%s`, class, string(char))
+ spanOpen = true
+ } else {
+ out += string(char)
+ }
}
out += "\n"
}
+ if spanOpen {
+ out += "</span>\n"
+ }
out += "</pre>\n"
out += "</div>"