minor refactoring of handlePrint

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

62
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) return data.GetDistro()
} },
case "username": "username": data.GetUsername,
utils.CutePrint(data.GetUsername(), format) "uptime": func() string {
case "uptime": no, _ := strconv.Atoi(data.GetUptime())
no, _ := strconv.Atoi(data.GetUptime()) return data.FormatTime(no)
utils.CutePrint(data.FormatTime(no), format) },
case "hostname": "hostname": func() string { return data.Unamebs("-n") },
utils.CutePrint(data.Unamebs("-n"), format) "kernelname": func() string { return data.Unamebs("-s") },
case "kernelname": "GPU": data.GetGPU,
utils.CutePrint(data.Unamebs("-s"), format) "shell": func() string { return getShellVersion(data.GetShell()) },
case "GPU": "terminal": data.GetTerminal,
utils.CutePrint(data.GetGPU(), format) "memoryAll": func() string { return data.GetMemory(false) },
case "shell": "memoryUsed": func() string { return data.GetMemory(true) },
utils.CutePrint(getShellVersion(data.GetShell()), format) "wm": data.GetWM,
case "terminal": "ip": data.GetLocalIP,
utils.CutePrint(data.GetTerminal(), format)
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)