diff --git a/widgets/expanded_net.go b/widgets/expanded_net.go index 910daee..21ec8c6 100644 --- a/widgets/expanded_net.go +++ b/widgets/expanded_net.go @@ -2,6 +2,7 @@ package widgets import ( "fmt" + "strings" ui "github.com/gizak/termui" ) @@ -14,6 +15,11 @@ type ExpandedNet struct { func NewExpandedNet() *ExpandedNet { net := &ExpandedNet{ui.NewSparklines(), NewDiffHistData(30), NewDiffHistData(30)} + net.BorderLabel = "NET" + net.Height = 8 + net.Width = 35 + net.X = 0 + net.Y = 15 rx := ui.NewSparkline() rx.Title = "RX" @@ -30,17 +36,17 @@ func NewExpandedNet() *ExpandedNet { tx.LineColor = ui.ColorYellow net.Lines = []ui.Sparkline{rx, tx} - net.Height = 8 - net.Width = 35 - net.X = 0 - net.Y = 15 return net } func (w *ExpandedNet) Update(rx int64, tx int64) { + var rate string + w.rxHist.Append(int(rx)) - w.Lines[0].Title = fmt.Sprintf("RX [%s/s]", byteFormat(int64(w.rxHist.Last()))) + rate = strings.ToLower(byteFormatInt(w.rxHist.Last())) + w.Lines[0].Title = fmt.Sprintf("RX [%s/s]", rate) w.txHist.Append(int(tx)) - w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", byteFormat(int64(w.txHist.Last()))) + rate = strings.ToLower(byteFormatInt(w.txHist.Last())) + w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", rate) } diff --git a/widgets/util.go b/widgets/util.go index 86a6793..53b2147 100644 --- a/widgets/util.go +++ b/widgets/util.go @@ -13,6 +13,11 @@ const ( gb = mb * 1024 ) +// convenience method +func byteFormatInt(n int) string { + return byteFormat(int64(n)) +} + func byteFormat(n int64) string { if n < kb { return fmt.Sprintf("%sB", strconv.FormatInt(n, 10))