Fetch module information outside os.Expand() function

This commit is contained in:
2025-12-22 17:38:35 +02:00
parent fabc1adbf7
commit cecce857e1
+14 -5
View File
@@ -100,10 +100,12 @@ func initializeModuleMap() {
// Packages module // Packages module
packagesModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "packages", Format: "%3Packages: %4$PACKAGES"}, Execute: func(sm StormfetchModule) string { packagesModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "packages", Format: "%3Packages: %4$PACKAGES"}, Execute: func(sm StormfetchModule) string {
packages := GetInstalledPackages()
return os.Expand(sm.Format, func(s string) string { return os.Expand(sm.Format, func(s string) string {
switch s { switch s {
case "PACKAGES": case "PACKAGES":
return GetInstalledPackages() return packages
default: default:
return "" return ""
} }
@@ -113,10 +115,12 @@ func initializeModuleMap() {
// Shell module // Shell module
shellModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "shell", Format: "%3Shell: %4$SHELL"}, Execute: func(sm StormfetchModule) string { shellModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "shell", Format: "%3Shell: %4$SHELL"}, Execute: func(sm StormfetchModule) string {
shell := GetShell()
return os.Expand(sm.Format, func(s string) string { return os.Expand(sm.Format, func(s string) string {
switch s { switch s {
case "SHELL": case "SHELL":
return GetShell() return shell
default: default:
return "" return ""
} }
@@ -139,10 +143,12 @@ func initializeModuleMap() {
// Libc module // Libc module
libcModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "libc", Format: "%3Libc: %4$LIBC"}, Execute: func(sm StormfetchModule) string { libcModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "libc", Format: "%3Libc: %4$LIBC"}, Execute: func(sm StormfetchModule) string {
libc := GetLibc()
return os.Expand(sm.Format, func(s string) string { return os.Expand(sm.Format, func(s string) string {
switch s { switch s {
case "LIBC": case "LIBC":
return GetLibc() return libc
default: default:
return "" return ""
} }
@@ -330,10 +336,12 @@ func initializeModuleMap() {
// Local IP module // Local IP module
localIpModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "local_ip", Format: "%3Local IP: %4$LOCAL_IP"}, Execute: func(sm StormfetchModule) string { localIpModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "local_ip", Format: "%3Local IP: %4$LOCAL_IP"}, Execute: func(sm StormfetchModule) string {
localIP := GetLocalIP()
return os.Expand(sm.Format, func(s string) string { return os.Expand(sm.Format, func(s string) string {
switch s { switch s {
case "LOCAL_IP": case "LOCAL_IP":
return GetLocalIP() return localIP
default: default:
return "" return ""
} }
@@ -349,6 +357,7 @@ func initializeModuleMap() {
} }
dewm := GetDEWM() dewm := GetDEWM()
displayProtocol := GetDisplayProtocol()
// Return empty string if can't detect DE/WM // Return empty string if can't detect DE/WM
if dewm.Name == "Unknown" { if dewm.Name == "Unknown" {
@@ -364,7 +373,7 @@ func initializeModuleMap() {
case "DEWM_VERSION": case "DEWM_VERSION":
return dewm.Version return dewm.Version
case "DISPLAY_PROTOCOL": case "DISPLAY_PROTOCOL":
return GetDisplayProtocol() return displayProtocol
default: default:
return "" return ""
} }