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