mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Simplify color map system
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
distro_ascii: auto
|
||||
fetch_script: auto
|
||||
ansii_colors: []
|
||||
force_config_ansii: false
|
||||
show_fs_type: true
|
||||
hidden_partitions: []
|
||||
# Hiding squashfs prevents snaps from showing up
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func setupColorMap(asciiArt string) map[string]string {
|
||||
colorMap := make(map[string]string)
|
||||
|
||||
// Read colors from ascii art
|
||||
if strings.HasPrefix(asciiArt, "#/") {
|
||||
firstLine := strings.Split(asciiArt, "\n")[0]
|
||||
ansiColors := strings.Split(strings.TrimPrefix(firstLine, "#/"), ";")
|
||||
|
||||
for i, ansiColor := range ansiColors {
|
||||
colorMap["C"+strconv.Itoa(i+1)] = fmt.Sprintf("\033[38;5;%sm", ansiColor)
|
||||
}
|
||||
}
|
||||
|
||||
return colorMap
|
||||
}
|
||||
+13
-41
@@ -25,8 +25,6 @@ var TimeTaken = false
|
||||
var config = StormfetchConfig{
|
||||
Ascii: "auto",
|
||||
FetchScript: "auto",
|
||||
AnsiiColors: make([]int, 0),
|
||||
ForceConfigAnsii: false,
|
||||
ShowFSType: false,
|
||||
HiddenPartitions: make([]string, 0),
|
||||
HiddenGPUS: make([]int, 0),
|
||||
@@ -189,48 +187,22 @@ func SetupFetchEnv(showTimeTaken bool) []string {
|
||||
}
|
||||
|
||||
func runStormfetch() {
|
||||
// Fetch ascii art and apply colors
|
||||
colorMap := make(map[string]string)
|
||||
colorMap["C0"] = "\033[0m"
|
||||
setColorMap := func() {
|
||||
for i := 0; i < 6; i++ {
|
||||
if i > len(config.AnsiiColors)-1 {
|
||||
colorMap["C"+strconv.Itoa(i+1)] = "\033[0m"
|
||||
continue
|
||||
}
|
||||
colorMap["C"+strconv.Itoa(i+1)] = fmt.Sprintf("\033[1m\033[38;5;%dm", config.AnsiiColors[i])
|
||||
}
|
||||
}
|
||||
setColorMap()
|
||||
ascii := GetDistroAsciiArt()
|
||||
if strings.HasPrefix(ascii, "#/") {
|
||||
firstLine := strings.Split(ascii, "\n")[0]
|
||||
if !config.ForceConfigAnsii {
|
||||
ansiiColors := strings.Split(strings.TrimPrefix(firstLine, "#/"), ";")
|
||||
for i, color := range ansiiColors {
|
||||
atoi, err := strconv.Atoi(color)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if i < len(config.AnsiiColors) {
|
||||
config.AnsiiColors[i] = atoi
|
||||
} else {
|
||||
config.AnsiiColors = append(config.AnsiiColors, atoi)
|
||||
}
|
||||
}
|
||||
setColorMap()
|
||||
}
|
||||
ascii = os.Expand(ascii, func(s string) string {
|
||||
return colorMap[s]
|
||||
})
|
||||
ascii = strings.TrimPrefix(ascii, firstLine+"\n")
|
||||
} else {
|
||||
ascii = os.Expand(ascii, func(s string) string {
|
||||
// Fetch ascii art
|
||||
asciiArt := GetDistroAsciiArt()
|
||||
|
||||
// Setup color map
|
||||
colorMap := setupColorMap(asciiArt)
|
||||
if len(colorMap) > 0 {
|
||||
asciiArt = os.Expand(asciiArt, func(s string) string {
|
||||
return colorMap[s]
|
||||
})
|
||||
|
||||
asciiArt = strings.SplitN(asciiArt, "\n", 2)[1]
|
||||
}
|
||||
asciiSplit := strings.Split(ascii, "\n")
|
||||
asciiNoColor := StripAnsii(ascii)
|
||||
|
||||
asciiSplit := strings.Split(asciiArt, "\n")
|
||||
asciiNoColor := StripAnsii(asciiArt)
|
||||
|
||||
// Execute fetch script
|
||||
cmd := exec.Command("/bin/bash", fetchScriptPath)
|
||||
cmd.Dir = path.Dir(fetchScriptPath)
|
||||
|
||||
Reference in New Issue
Block a user