Add support for resetting stats without leaving app

This commit is contained in:
Pedro Pombeiro 2018-01-29 16:41:21 +01:00
parent 47b9b1e186
commit fbbc18f2cf
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
3 changed files with 13 additions and 1 deletions

View File

@ -53,3 +53,10 @@ func (d *Data) MemoryStats() (used []float64) {
func (d *Data) NetworkStats() (rx, tx []float64) {
return d.rxBytes.Data(), d.txBytes.Data()
}
// Clear clears all data.
func (d *Data) Clear() {
for _, b := range [...]*CircularBuffer{d.cpu, d.mem, d.rxBytes, d.txBytes} {
b.Reset()
}
}

View File

@ -80,6 +80,11 @@ func main() {
ui := initUI(pid, *interval)
defer stopUI()
// handle key r pressing
termui.Handle("/sys/kbd/r", func(termui.Event) {
data.Clear()
})
ui.HandleKeys()
ui.AddTimer(*interval, func(e termui.Event) {

2
ui.go
View File

@ -182,7 +182,7 @@ func (ui *UI) createHeader(pid int64) {
p.TextFgColor = termui.ColorWhite
p.BorderLabel = "Monitoring Status.im via adb"
p.BorderFg = termui.ColorCyan
p.Text = "press 'q' to exit"
p.Text = "press 'q' to exit, 'r' to reset"
p1 := termui.NewPar("")
p1.Height = headerHeight