make colors customizable
This commit is contained in:
@@ -27,6 +27,8 @@ var (
|
|||||||
PacketLossWarnLimit = flag.Int("pwarn", 10, "package-loss warning limit")
|
PacketLossWarnLimit = flag.Int("pwarn", 10, "package-loss warning limit")
|
||||||
PacketLossCritLimit = flag.Int("pcrit", 25, "package-loss critical limit")
|
PacketLossCritLimit = flag.Int("pcrit", 25, "package-loss critical limit")
|
||||||
Host = flag.String("host", "google.com", "host to ping")
|
Host = flag.String("host", "google.com", "host to ping")
|
||||||
|
WarnColor = flag.String("warnc", "ffbf00", "hex color for warning ping (without #)")
|
||||||
|
CritColor = flag.String("critc", "ff5050", "hex color for critical ping (without #)")
|
||||||
)
|
)
|
||||||
|
|
||||||
type PingStats struct {
|
type PingStats struct {
|
||||||
@@ -37,8 +39,6 @@ type PingStats struct {
|
|||||||
|
|
||||||
//goland:noinspection ALL
|
//goland:noinspection ALL
|
||||||
const (
|
const (
|
||||||
CritColor = "ff5050"
|
|
||||||
WarnColor = "ffbf00"
|
|
||||||
ResetColor = "%{F-}"
|
ResetColor = "%{F-}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,11 +47,10 @@ type WaybarOut struct {
|
|||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatLine(stats *PingStats) {
|
func formatLinePolybar(stats *PingStats) {
|
||||||
if stats.PacketLoss >= 100.0 {
|
if stats.PacketLoss >= 100.0 {
|
||||||
// fontawesome/forkawesome doesn't have the fitting icon...
|
// fontawesome/forkawesome don't have a fitting icon, so we use 🚫 from UTF-8 symbols/emoji
|
||||||
// so this is the utf-8 icon/emoji
|
fmt.Printf("%%{F#%s}🚫\n", *CritColor)
|
||||||
fmt.Printf("%%{F#%s}🚫\n", CritColor)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,16 +59,16 @@ func formatLine(stats *PingStats) {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case int(stats.AvgRtt.Milliseconds()) >= *PingWarningLimit:
|
case int(stats.AvgRtt.Milliseconds()) >= *PingWarningLimit:
|
||||||
rttColor = fmt.Sprintf("%%{F#%s}", WarnColor)
|
rttColor = fmt.Sprintf("%%{F#%s}", *WarnColor)
|
||||||
case int(stats.AvgRtt.Milliseconds()) >= *PingCritLimit:
|
case int(stats.AvgRtt.Milliseconds()) >= *PingCritLimit:
|
||||||
rttColor = fmt.Sprintf("%%{F#%s}", CritColor)
|
rttColor = fmt.Sprintf("%%{F#%s}", *CritColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case int(math.Round(stats.PacketLoss)) >= *PacketLossWarnLimit:
|
case int(math.Round(stats.PacketLoss)) >= *PacketLossWarnLimit:
|
||||||
packetColor = fmt.Sprintf("%%{F#%s}", WarnColor)
|
packetColor = fmt.Sprintf("%%{F#%s}", *WarnColor)
|
||||||
case int(math.Round(stats.PacketLoss)) >= *PacketLossCritLimit:
|
case int(math.Round(stats.PacketLoss)) >= *PacketLossCritLimit:
|
||||||
packetColor = fmt.Sprintf("%%{F#%s}", CritColor)
|
packetColor = fmt.Sprintf("%%{F#%s}", *CritColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%s\uE4E2 %d \uE43C %dms %s\uF1B2 %d%%\n", rttColor, stats.AvgRtt.Milliseconds(), stats.StdDev.Milliseconds(), packetColor, int(math.Round(stats.PacketLoss)))
|
fmt.Printf("%s\uE4E2 %d \uE43C %dms %s\uF1B2 %d%%\n", rttColor, stats.AvgRtt.Milliseconds(), stats.StdDev.Milliseconds(), packetColor, int(math.Round(stats.PacketLoss)))
|
||||||
@@ -158,7 +157,7 @@ func main() {
|
|||||||
} else if *Waybar {
|
} else if *Waybar {
|
||||||
formatLineWaybar(pStats)
|
formatLineWaybar(pStats)
|
||||||
} else {
|
} else {
|
||||||
formatLine(pStats)
|
formatLinePolybar(pStats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +172,7 @@ func main() {
|
|||||||
} else if *Waybar {
|
} else if *Waybar {
|
||||||
formatLineWaybar(pStats)
|
formatLineWaybar(pStats)
|
||||||
} else {
|
} else {
|
||||||
formatLine(pStats)
|
formatLinePolybar(pStats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
Reference in New Issue
Block a user