mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
update expanded net labels
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
@ -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))
|
||||
|
Reference in New Issue
Block a user