2017-01-07 20:37:11 +00:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-01-08 16:13:25 +00:00
|
|
|
"strings"
|
2017-01-07 20:37:11 +00:00
|
|
|
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ExpandedNet struct {
|
|
|
|
*ui.Sparklines
|
2017-01-08 15:54:25 +00:00
|
|
|
rxHist DiffHistData
|
|
|
|
txHist DiffHistData
|
2017-01-07 20:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewExpandedNet() *ExpandedNet {
|
2017-01-08 15:54:25 +00:00
|
|
|
net := &ExpandedNet{ui.NewSparklines(), NewDiffHistData(30), NewDiffHistData(30)}
|
2017-01-08 16:13:25 +00:00
|
|
|
net.BorderLabel = "NET"
|
|
|
|
net.Height = 8
|
|
|
|
net.Width = 35
|
|
|
|
net.X = 0
|
|
|
|
net.Y = 15
|
2017-01-07 20:37:11 +00:00
|
|
|
|
|
|
|
rx := ui.NewSparkline()
|
|
|
|
rx.Title = "RX"
|
2017-01-08 15:54:25 +00:00
|
|
|
rx.Height = 2
|
2017-01-07 20:37:11 +00:00
|
|
|
rx.Data = net.rxHist.data
|
|
|
|
rx.TitleColor = ui.ColorDefault
|
|
|
|
rx.LineColor = ui.ColorGreen
|
|
|
|
|
|
|
|
tx := ui.NewSparkline()
|
|
|
|
tx.Title = "TX"
|
2017-01-08 15:54:25 +00:00
|
|
|
tx.Height = 2
|
2017-01-07 20:37:11 +00:00
|
|
|
tx.Data = net.txHist.data
|
|
|
|
tx.TitleColor = ui.ColorDefault
|
2017-01-08 15:54:25 +00:00
|
|
|
tx.LineColor = ui.ColorYellow
|
2017-01-07 20:37:11 +00:00
|
|
|
|
|
|
|
net.Lines = []ui.Sparkline{rx, tx}
|
|
|
|
return net
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *ExpandedNet) Update(rx int64, tx int64) {
|
2017-01-08 16:13:25 +00:00
|
|
|
var rate string
|
|
|
|
|
2017-01-07 20:37:11 +00:00
|
|
|
w.rxHist.Append(int(rx))
|
2017-01-08 16:13:25 +00:00
|
|
|
rate = strings.ToLower(byteFormatInt(w.rxHist.Last()))
|
|
|
|
w.Lines[0].Title = fmt.Sprintf("RX [%s/s]", rate)
|
2017-01-08 15:54:25 +00:00
|
|
|
|
2017-01-07 20:37:11 +00:00
|
|
|
w.txHist.Append(int(tx))
|
2017-01-08 16:13:25 +00:00
|
|
|
rate = strings.ToLower(byteFormatInt(w.txHist.Last()))
|
|
|
|
w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", rate)
|
2017-01-07 20:37:11 +00:00
|
|
|
}
|