set icons directly in output for waybar

This commit is contained in:
2023-04-14 22:10:49 +02:00
parent 1c946e8102
commit 0639074398

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"github.com/prometheus-community/pro-bing"
"math"
"strconv"
"time"
)
@@ -22,10 +21,8 @@ var (
)
type WaybarOut struct {
Class string `json:"class"`
PackageLoss string `json:"package_loss"`
Ping string `json:"ping"`
Text string `json:"text"`
Class string `json:"class"`
Text string `json:"text"`
}
func formatLine(stats *probing.Statistics) {
@@ -65,8 +62,8 @@ func formatLine(stats *probing.Statistics) {
func formatLineWaybar(stats *probing.Statistics) {
res := new(WaybarOut)
res.PackageLoss = strconv.Itoa(int(math.Round(stats.PacketLoss)))
res.Ping = strconv.Itoa(int(stats.AvgRtt.Milliseconds()))
res.Text = fmt.Sprintf("\uE4E2 %dms \uF1B2 %d%%", int(stats.AvgRtt.Milliseconds()), int(math.Round(stats.PacketLoss)))
res.Class = "good"
switch {
case int(math.Round(stats.PacketLoss)) > *PacketLossWarnLimit || int(stats.AvgRtt.Milliseconds()) > *PingWarningLimit: