-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
logo_unix.go
87 lines (73 loc) · 3.85 KB
/
logo_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//go:build unix
package platformdep
import (
"bytes"
"compress/gzip"
"encoding/base64"
"io"
"strings"
)
/*
ANSI banner HOWTO
-----------------
1. Find an image.
2. Convert to png, if needed:
convert image.jpg image.png
3. Crop and resize the image until it is approximately 20 pixels in width. Gimp works.
4. Install the transmogrify executable from the transmogrifier package (for converting to ANSI):
npm -g install transmogrifier
5. Transform, compress and encode:
transmogrify image.png | gzip -c -9 | base64 -w0 > output.b64
6. Copy and paste the base64 encoded data as the image constant below.
*/
// gopher eyes
const image = `H4sIAJB76FoCA9WWTRKDIAxG91zBjUcQSBTGo/QM3n/bbvozfFRCRGp3nW+q5PEwZLhRWHm17LdxHG4Ut+GZJIHz9oeJtUu3xDGXk/NIGYKXG3NITgYCE0oTWhpD1LiBp5RuKGjQVdbf6Obre9AfT+lfZmBwAk7Yr8dPDUNHW1BhBl1yBn1xT3fRTUXNSxtZ9H+yJOdUIov6yXJcXh4oEMs7wXuvZqv8lUjISUEuaYOypL5iO7lGV3E/V3hjAoRAFS6tmy8yMxF1m5KsYLewQMIGApc+47mIgnGQ6u0ph6Q0CFEjSznSNkpyX81cHFQ4loWSLy+lbJSN0PdUmEM9JHMUdImgp0E14bTkYuSfuu6KgLzwGw8AAA==`
// Drawn in GIMP. Just a white grid on black background.
// const image = `H4sIAK/e01kCA5OONrGwNrU2MjbMVVCQjjaxzJUeFaFYhAunIkMzQgKjekaDkt5BOSoymtlHM/toZh8VIZjZAT4BWy4xCQAA`
// Blue and green circles. Drawn in Inkscape
// const image = `H4sIAKy5IlU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SmjGAAA`
// Decompress text that has first been gzipped and then base64 encoded
func decompressImage(asciigfx string) string {
unbasedBytes, err := base64.StdEncoding.DecodeString(asciigfx)
if err != nil {
panic("Could not decode base64: " + err.Error())
}
buf := bytes.NewBuffer(unbasedBytes)
decompressorReader, err := gzip.NewReader(buf)
if err != nil {
panic("Could not read buffer: " + err.Error())
}
decompressedBytes, err := io.ReadAll(decompressorReader)
decompressorReader.Close()
if err != nil {
panic("Could not decompress: " + err.Error())
}
return string(decompressedBytes)
}
// Insert text while replacing tab characters
func insertText(s, tabs string, linenr, offset int, message string, removal int) string {
tabcounter := 0
for pos := 0; pos < len(s); pos++ {
if s[pos] == '\t' {
tabcounter++
}
if tabcounter == len(tabs)*linenr+offset {
s = s[:pos] + message + s[pos+removal:]
break
}
}
return s
}
// Banner returns ANSI graphics with the current version number embedded in the text
func Banner(versionString, description string) string {
tabs := "\t\t\t\t"
s := tabs + strings.ReplaceAll("\n"+decompressImage(image), "\n", "\n"+tabs)
parts := strings.Fields(versionString)
// See https://github.com/shiena/ansicolor/blob/master/README.md for ANSI color code table
s = insertText(s, tabs, 3, 2, "\x1b[37m"+parts[0]+"\x1b[0m", 1)
s = insertText(s, tabs, 4, 1, "\x1b[90m"+parts[1]+"\x1b[0\t", 1)
s = insertText(s, tabs, 5, 1, "\x1b[94m"+description+"\x1b[0m", 1)
return s
}