new config options
This commit is contained in:
parent
33651685aa
commit
8c9598b07f
18
src/main.go
18
src/main.go
@ -9,11 +9,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
Reset = "\033[0m"
|
||||
Blue = "\033[1;34m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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
|
||||
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
|
||||
|
||||
@ -9,18 +9,31 @@ import (
|
||||
"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 {
|
||||
Ascii bool `toml:"ascii"`
|
||||
Layout []string `toml:"layout"`
|
||||
CustomLogo string `toml:"custom_logo"`
|
||||
LogoPosition string `toml:"logo_position"`
|
||||
Key string `toml:"key"`
|
||||
StatColor string `toml:"stat_color"`
|
||||
}
|
||||
|
||||
func appendMissingConfigKeys(pathConf string, md toml.MetaData) error {
|
||||
var missing []string
|
||||
|
||||
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") {
|
||||
@ -42,13 +55,21 @@ layout = [
|
||||
}
|
||||
|
||||
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") {
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
@ -61,7 +82,7 @@ layout = [
|
||||
_ = f.Close()
|
||||
}(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)
|
||||
return err
|
||||
}
|
||||
@ -77,6 +98,28 @@ func getConfigPath() (string, error) {
|
||||
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) {
|
||||
var conf Config
|
||||
pathConf, err := getConfigPath()
|
||||
@ -91,7 +134,7 @@ func InitConfig() (Config, string) {
|
||||
|
||||
if _, err := os.Stat(pathConf); os.IsNotExist(err) {
|
||||
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
|
||||
|
||||
# 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".
|
||||
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)
|
||||
if err != nil {
|
||||
@ -125,6 +176,13 @@ logo_position = "left"
|
||||
md, err := toml.DecodeFile(pathConf, &conf)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user