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