diff --git a/config/config.yaml b/config/config.yaml index 6164661..03e705b 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -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 diff --git a/src/color.go b/src/color.go new file mode 100644 index 0000000..a846141 --- /dev/null +++ b/src/color.go @@ -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 +} diff --git a/src/main.go b/src/main.go index a200ae4..7fe7623 100644 --- a/src/main.go +++ b/src/main.go @@ -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,49 +187,23 @@ 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) - //Execute fetch script + + asciiSplit := strings.Split(asciiArt, "\n") + asciiNoColor := StripAnsii(asciiArt) + + // Execute fetch script cmd := exec.Command("/bin/bash", fetchScriptPath) cmd.Dir = path.Dir(fetchScriptPath) cmd.Env = os.Environ()