minor refactoring of handlePrint

This commit is contained in:
exhq 2023-02-18 14:02:44 +03:30
parent f4bd0f0318
commit 2571e725f6

56
main.go
View file

@ -64,44 +64,42 @@ func handlePrint(action, format string, rest string) {
utils.CutePrint(rest, format) utils.CutePrint(rest, format)
utils.CuteNewLine() utils.CuteNewLine()
} else if action == "info" || action == "infoln" { } else if action == "info" || action == "infoln" {
switch rest { infoGetters := map[string]func() string{
case "distro": "distro": func() string {
if utils.Asciiforced { if utils.Asciiforced {
utils.CutePrint(utils.Forceddistro, format) return utils.Forceddistro
} else {
utils.CutePrint(data.GetDistro(), format)
} }
case "username": return data.GetDistro()
utils.CutePrint(data.GetUsername(), format) },
case "uptime": "username": data.GetUsername,
"uptime": func() string {
no, _ := strconv.Atoi(data.GetUptime()) no, _ := strconv.Atoi(data.GetUptime())
utils.CutePrint(data.FormatTime(no), format) return data.FormatTime(no)
case "hostname": },
utils.CutePrint(data.Unamebs("-n"), format) "hostname": func() string { return data.Unamebs("-n") },
case "kernelname": "kernelname": func() string { return data.Unamebs("-s") },
utils.CutePrint(data.Unamebs("-s"), format) "GPU": data.GetGPU,
case "GPU": "shell": func() string { return getShellVersion(data.GetShell()) },
utils.CutePrint(data.GetGPU(), format) "terminal": data.GetTerminal,
case "shell": "memoryAll": func() string { return data.GetMemory(false) },
utils.CutePrint(getShellVersion(data.GetShell()), format) "memoryUsed": func() string { return data.GetMemory(true) },
case "terminal": "wm": data.GetWM,
utils.CutePrint(data.GetTerminal(), format) "ip": data.GetLocalIP,
case "memoryAll":
utils.CutePrint(data.GetMemory(false), format)
case "memoryUsed":
utils.CutePrint(data.GetMemory(true), format)
case "wm":
utils.CutePrint(data.GetWM(), format)
case "ip":
utils.CutePrint(data.GetLocalIP(), format)
default:
print("{UNKNOWN KEYWORD: " + rest + "}")
} }
getter, ok := infoGetters[rest]
if ok {
utils.CutePrint(getter(), format)
} else {
utils.CutePrint("{UNKNOWN KEYWORD: "+rest+"}", format)
}
if action == "infoln" { if action == "infoln" {
utils.CuteNewLine() utils.CuteNewLine()
} }
} }
} }
func runpage() { func runpage() {
if utils.Ishelp { if utils.Ishelp {
println(`neowofetch version x (idk how to implement this) println(`neowofetch version x (idk how to implement this)