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
|
distro_ascii: auto
|
||||||
fetch_script: auto
|
fetch_script: auto
|
||||||
ansii_colors: []
|
|
||||||
force_config_ansii: false
|
|
||||||
show_fs_type: true
|
show_fs_type: true
|
||||||
hidden_partitions: []
|
hidden_partitions: []
|
||||||
# Hiding squashfs prevents snaps from showing up
|
# 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
|
||||||
|
}
|
||||||
+14
-42
@@ -25,8 +25,6 @@ var TimeTaken = false
|
|||||||
var config = StormfetchConfig{
|
var config = StormfetchConfig{
|
||||||
Ascii: "auto",
|
Ascii: "auto",
|
||||||
FetchScript: "auto",
|
FetchScript: "auto",
|
||||||
AnsiiColors: make([]int, 0),
|
|
||||||
ForceConfigAnsii: false,
|
|
||||||
ShowFSType: false,
|
ShowFSType: false,
|
||||||
HiddenPartitions: make([]string, 0),
|
HiddenPartitions: make([]string, 0),
|
||||||
HiddenGPUS: make([]int, 0),
|
HiddenGPUS: make([]int, 0),
|
||||||
@@ -189,49 +187,23 @@ func SetupFetchEnv(showTimeTaken bool) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runStormfetch() {
|
func runStormfetch() {
|
||||||
// Fetch ascii art and apply colors
|
// Fetch ascii art
|
||||||
colorMap := make(map[string]string)
|
asciiArt := GetDistroAsciiArt()
|
||||||
colorMap["C0"] = "\033[0m"
|
|
||||||
setColorMap := func() {
|
// Setup color map
|
||||||
for i := 0; i < 6; i++ {
|
colorMap := setupColorMap(asciiArt)
|
||||||
if i > len(config.AnsiiColors)-1 {
|
if len(colorMap) > 0 {
|
||||||
colorMap["C"+strconv.Itoa(i+1)] = "\033[0m"
|
asciiArt = os.Expand(asciiArt, func(s string) string {
|
||||||
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 {
|
|
||||||
return colorMap[s]
|
return colorMap[s]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
asciiArt = strings.SplitN(asciiArt, "\n", 2)[1]
|
||||||
}
|
}
|
||||||
asciiSplit := strings.Split(ascii, "\n")
|
|
||||||
asciiNoColor := StripAnsii(ascii)
|
asciiSplit := strings.Split(asciiArt, "\n")
|
||||||
//Execute fetch script
|
asciiNoColor := StripAnsii(asciiArt)
|
||||||
|
|
||||||
|
// Execute fetch script
|
||||||
cmd := exec.Command("/bin/bash", fetchScriptPath)
|
cmd := exec.Command("/bin/bash", fetchScriptPath)
|
||||||
cmd.Dir = path.Dir(fetchScriptPath)
|
cmd.Dir = path.Dir(fetchScriptPath)
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
|||||||
Reference in New Issue
Block a user