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-12 15:06:35 +00:00
|
|
|
rxHist DiffHist
|
|
|
|
txHist DiffHist
|
2017-01-07 20:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewExpandedNet() *ExpandedNet {
|
2017-01-12 15:06:35 +00:00
|
|
|
net := &ExpandedNet{ui.NewSparklines(), NewDiffHist(50), NewDiffHist(50)}
|
2017-01-08 16:13:25 +00:00
|
|
|
net.BorderLabel = "NET"
|
2017-01-08 18:07:56 +00:00
|
|
|
net.Height = 6
|
|
|
|
net.Width = 50
|
2017-01-08 16:13:25 +00:00
|
|
|
net.X = 0
|
2017-01-08 18:07:56 +00:00
|
|
|
net.Y = 24
|
2017-01-07 20:37:11 +00:00
|
|
|
|
|
|
|
rx := ui.NewSparkline()
|
|
|
|
rx.Title = "RX"
|
2017-01-08 18:07:56 +00:00
|
|
|
rx.Height = 1
|
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 18:07:56 +00:00
|
|
|
tx.Height = 1
|
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
|
|
|
}
|