diff options
Diffstat (limited to '.config/lemon.go')
-rw-r--r-- | .config/lemon.go | 125 |
1 files changed, 82 insertions, 43 deletions
diff --git a/.config/lemon.go b/.config/lemon.go index 17471e9..f873d2b 100644 --- a/.config/lemon.go +++ b/.config/lemon.go @@ -13,7 +13,8 @@ import ( ) var ( - data, connectedWiFi, memPercentage, cpuTemp, cpuPercentage string + data, connectedWiFi, memPercentage, cpuTemp, cpuPercentage, volumeLevel string + batteryLevel, chargingStatus string text string = "\n" moduleColor0, moduleColor1 string = "#9b1bed", "#ff0aa3" ) @@ -32,13 +33,43 @@ func stdinLoop() { } } +// to update modules every 5 seconds +func fiveSecLoop() { + for { + memPercentage = getMemUsage() + cpuTemp = getCPUTemp() + cpuPercentage = getCPUUsage() + + time.Sleep(time.Second * 5) + } +} + +// to update modules every 10 seconds +func tenSecLoop() { + for { + connectedWiFi = getWiFiName() + chargingStatus, batteryLevel = getBatteryInfo() + + time.Sleep(time.Second * 10) + } +} + +// very creative name +// used to update modules like volume, etc +// don't want lag on those modules! +func veryFastLoop() { + for { + volumeLevel = getVolumeLevel() + time.Sleep(time.Second / 10) + } +} + func main() { go dataLoop() go stdinLoop() - go cpuUsageLoop() - go connectedWiFiLoop() - go memUsageLoop() - go cpuTempLoop() + go fiveSecLoop() + go tenSecLoop() + go veryFastLoop() for { fmt.Print(data + text) @@ -46,22 +77,36 @@ func main() { } } -// TODO -// volume -// brightness (new) -// battery - func getData() string { time := "%{F" + moduleColor0 + "} " + getTime() + "%{F-} " wifiName := "%{F" + moduleColor1 + "} WiFI: " + connectedWiFi + "%{F-} " - rootFree := "%{F" + moduleColor0 + "} / " + getDisk("/") + "%%%{F-} " - homeFree := "%{F" + moduleColor1 + "} /home " + getDisk("/home") + "%%%{F-} " - hddFree := "%{F" + moduleColor0 + "} /hdd " + getDisk("/hdd") + "%%%{F-} " - cpuUsage := "%{F" + moduleColor1 + "} CPU: " + cpuPercentage + "%%%{F-} " - cpuTemp := "%{F" + moduleColor0 + "} TEMP: " + cpuTemp + "%%{F-} " - memUsage := "%{F" + moduleColor1 + "} MEM: " + memPercentage + "%%{F-} " + rootFree := "%{F" + moduleColor0 + "} / " + getDisk("/") + "%%{F-} " + homeFree := "%{F" + moduleColor1 + "} /home " + getDisk("/home") + "%%{F-} " + hddFree := "%{F" + moduleColor0 + "} /hdd " + getDisk("/hdd") + "%%{F-} " + cpuUsage := "%{F" + moduleColor1 + "} CPU: " + cpuPercentage + "%%{F-} " + cpuTemp := "%{F" + moduleColor0 + "} TEMP: " + cpuTemp + "%{F-} " + memUsage := "%{F" + moduleColor1 + "} MEM: " + memPercentage + "%{F-} " + + volume := "%{F" + moduleColor0 + "}" + if volumeLevel != "muted" { + volume = volume + "} VOL: " + volumeLevel + "%{F-} " + } else { + volume = volume + "} MUTED%{F-} " + } - return time + wifiName + rootFree + homeFree + hddFree + cpuUsage + cpuTemp + memUsage + // shows battery level in different color + // depending on charging status + // hidden when full + var battery string + btlvl, _ := strconv.Atoi(batteryLevel) + if btlvl < 100 { + col := moduleColor1 + if chargingStatus == "Charging" { col = moduleColor0 } + battery = fmt.Sprintf("%%{F%s} BATT: %s%%{F-} ", col, batteryLevel) + } + + // TODO add brightness (new) + return time + wifiName + rootFree + homeFree + hddFree + cpuUsage + cpuTemp + "%{r}" + memUsage + battery } func getWiFiName() string { @@ -72,13 +117,6 @@ func getWiFiName() string { return string(name) } -func connectedWiFiLoop() { - for { - connectedWiFi = getWiFiName() - time.Sleep(time.Second * 15) - } -} - func getMemUsage() string { // script located in ~/.scripts/ // look at github.com/MikunoNaka/dots @@ -87,12 +125,6 @@ func getMemUsage() string { return string(usage) } -func memUsageLoop() { - for { - memPercentage = getMemUsage() - time.Sleep(time.Second * 5) - } -} func getCPUTemp() string { // script located in ~/.scripts/ @@ -102,11 +134,24 @@ func getCPUTemp() string { return string(temp) } -func cpuTempLoop() { - for { - cpuTemp = getCPUTemp() - time.Sleep(time.Second * 5) - } +func getVolumeLevel() string { + // script located in ~/.scripts/ + // look at github.com/MikunoNaka/dots + cmd := exec.Command("volume_level.sh") + level, _ := cmd.Output() + return string(level) +} + +func getBatteryInfo() (string, string) { + // scripts located in ~/.scripts/ + // look at github.com/MikunoNaka/dots + statCmd := exec.Command("charging_status.sh") + stat, _ := statCmd.Output() + + levelCmd := exec.Command("battery_level.sh") + level, _ := levelCmd.Output() + + return string(stat), string(level) } // TODO: maybe add dates on click @@ -153,7 +198,7 @@ func getCPUSample() (idle, total uint64) { return } -func getCPUUsage() { +func getCPUUsage() string { idle0, total0 := getCPUSample() time.Sleep(3 * time.Second) idle1, total1 := getCPUSample() @@ -162,12 +207,6 @@ func getCPUUsage() { totalTicks := float64(total1 - total0) cpuUsage := 100 * (totalTicks - idleTicks) / totalTicks - cpuPercentage = strconv.Itoa(int(cpuUsage)) + return strconv.Itoa(int(cpuUsage)) } -func cpuUsageLoop() { - for { - getCPUUsage() - time.Sleep(5 * time.Second) - } -} |