new config options

This commit is contained in:
nekohepott 2026-06-17 04:16:27 +03:00
parent 33651685aa
commit 8c9598b07f
No known key found for this signature in database
2 changed files with 74 additions and 10 deletions

View File

@ -9,11 +9,6 @@ import (
"strings" "strings"
) )
const (
Reset = "\033[0m"
Blue = "\033[1;34m"
)
func main() { func main() {
conf, _ := providers.InitConfig() conf, _ := providers.InitConfig()
@ -72,9 +67,20 @@ func main() {
} }
} }
key := "->"
statColor := providers.Blue
if conf.Key != "" {
key = conf.Key
}
if conf.StatColor != "" {
statColor = providers.GetColorCode(conf.StatColor)
}
var statsLines []string var statsLines []string
for _, info := range stats { for _, info := range stats {
statsLines = append(statsLines, fmt.Sprintf("-> %s%s%s: %s", Blue, info.Label, Reset, info.Value)) statsLines = append(statsLines, fmt.Sprintf("%s %s%s%s: %s", key, statColor, info.Label, providers.Reset, info.Value))
} }
var logoLines []string var logoLines []string

View File

@ -9,18 +9,31 @@ import (
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
) )
const (
Reset = "\033[0m"
Blue = "\033[1;34m"
Green = "\033[1;32m"
Red = "\033[1;31m"
Yellow = "\033[1;33m"
Purple = "\033[1;35m"
Cyan = "\033[1;36m"
White = "\033[1;37m"
)
type Config struct { type Config struct {
Ascii bool `toml:"ascii"` Ascii bool `toml:"ascii"`
Layout []string `toml:"layout"` Layout []string `toml:"layout"`
CustomLogo string `toml:"custom_logo"` CustomLogo string `toml:"custom_logo"`
LogoPosition string `toml:"logo_position"` LogoPosition string `toml:"logo_position"`
Key string `toml:"key"`
StatColor string `toml:"stat_color"`
} }
func appendMissingConfigKeys(pathConf string, md toml.MetaData) error { func appendMissingConfigKeys(pathConf string, md toml.MetaData) error {
var missing []string var missing []string
if !md.IsDefined("ascii") { if !md.IsDefined("ascii") {
missing = append(missing, "# Set this to \"true\" if you like ascii more than images\nascii = false") missing = append(missing, "# Set this to \"true\" if you like ascii more than images (i'm too lazy to add support for all distros though, so there's only arch, nixos and debian)\nascii = false")
} }
if !md.IsDefined("layout") { if !md.IsDefined("layout") {
@ -42,13 +55,21 @@ layout = [
} }
if !md.IsDefined("custom_logo") { if !md.IsDefined("custom_logo") {
missing = append(missing, "# Absolute path to a custom image or .txt file. Leave empty to use auto-detection.\ncustom_logo = \"\"") missing = append(missing, "# Absolute path to a custom image or .txt file. Leave empty to use your distro logo\ncustom_logo = \"\"")
} }
if !md.IsDefined("logo_position") { if !md.IsDefined("logo_position") {
missing = append(missing, "# Position of the logo block relative to the stats block: \"left\" or \"right\".\nlogo_position = \"left\"") missing = append(missing, "# Position of the logo block relative to the stats block: \"left\" or \"right\".\nlogo_position = \"left\"")
} }
if !md.IsDefined("key") {
missing = append(missing, "# key symbol before stat (e.g. ->)\n# default: \"->\"\nkey = \"\"")
}
if !md.IsDefined("stat_color") {
missing = append(missing, "# color of the stat label, default is blue\n# available: blue, green, red, yellow, purple, cyan, white\nstat_color = \"\"")
}
if len(missing) == 0 { if len(missing) == 0 {
return nil return nil
} }
@ -61,7 +82,7 @@ layout = [
_ = f.Close() _ = f.Close()
}(f) }(f)
block := "\n# Added automatically after update\n\n" + strings.Join(missing, "\n\n") + "\n" block := "\n" + strings.Join(missing, "\n") + "\n"
_, err = f.WriteString(block) _, err = f.WriteString(block)
return err return err
} }
@ -77,6 +98,28 @@ func getConfigPath() (string, error) {
return fullPath, nil return fullPath, nil
} }
func GetColorCode(colorName string) string {
colorName = strings.ToLower(strings.TrimSpace(colorName))
switch colorName {
case "blue":
return Blue
case "green":
return Green
case "red":
return Red
case "yellow":
return Yellow
case "purple":
return Purple
case "cyan":
return Cyan
case "white":
return White
default:
return Blue
}
}
func InitConfig() (Config, string) { func InitConfig() (Config, string) {
var conf Config var conf Config
pathConf, err := getConfigPath() pathConf, err := getConfigPath()
@ -91,7 +134,7 @@ func InitConfig() (Config, string) {
if _, err := os.Stat(pathConf); os.IsNotExist(err) { if _, err := os.Stat(pathConf); os.IsNotExist(err) {
defaultConfig := []byte(` defaultConfig := []byte(`
# Set this to "true" if you like ascii more than images # Set this to "true" if you like ascii more than images (i'm too lazy to add support for all distros though, so there's only arch, nixos and debian)
ascii = false ascii = false
# Stats layout: reorder or remove items to customize your fetch # Stats layout: reorder or remove items to customize your fetch
@ -115,6 +158,14 @@ custom_logo = ""
# Position of the logo block relative to the stats block: "left" or "right". # Position of the logo block relative to the stats block: "left" or "right".
logo_position = "left" logo_position = "left"
# key symbol before stat (e.g. ->)
# default: "->"
key = ""
# color of the stat label, default is blue
# available: blue, green, red, yellow, purple, cyan, white
stat_color = ""
`) `)
err := os.WriteFile(pathConf, defaultConfig, 0644) err := os.WriteFile(pathConf, defaultConfig, 0644)
if err != nil { if err != nil {
@ -125,6 +176,13 @@ logo_position = "left"
md, err := toml.DecodeFile(pathConf, &conf) md, err := toml.DecodeFile(pathConf, &conf)
if err != nil { if err != nil {
fmt.Printf("Error loading config at %s: %v\n", pathConf, err) fmt.Printf("Error loading config at %s: %v\n", pathConf, err)
conf = Config{
Layout: []string{"host", "dist", "cpu", "kernel", "ram", "gpu", "de/wm", "pkgs", "shell", "terminal", "uptime"},
CustomLogo: "",
LogoPosition: "left",
Key: "->",
StatColor: "blue",
}
return conf, pathConf return conf, pathConf
} }