ctop/widgets/expanded.go

72 lines
1.2 KiB
Go
Raw Normal View History

2017-01-06 19:46:30 +00:00
package widgets
import (
ui "github.com/gizak/termui"
)
type Expanded struct {
2017-01-07 20:37:11 +00:00
Info *ui.Table
Net *ExpandedNet
Cpu *ExpandedCpu
Mem *ExpandedMem
2017-01-06 19:46:30 +00:00
}
func NewExpanded(id, name string) *Expanded {
return &Expanded{
2017-01-07 20:37:11 +00:00
Info: NewInfo(id, name),
Net: NewExpandedNet(),
Cpu: NewExpandedCpu(),
Mem: NewExpandedMem(),
2017-01-06 19:46:30 +00:00
}
}
func NewInfo(id, name string) *ui.Table {
p := ui.NewTable()
p.Rows = [][]string{
[]string{"name", name},
[]string{"id", id},
}
p.Height = 4
p.Width = 50
2017-01-06 19:46:30 +00:00
p.FgColor = ui.ColorWhite
p.Seperator = false
return p
}
func (w *Expanded) Render() {
2017-01-07 20:37:11 +00:00
ui.Render(w.Info, w.Cpu, w.Mem, w.Net)
2017-01-06 19:46:30 +00:00
ui.Handle("/timer/1s", func(ui.Event) {
2017-01-07 20:37:11 +00:00
ui.Render(w.Info, w.Cpu, w.Mem, w.Net)
2017-01-06 19:46:30 +00:00
})
ui.Handle("/sys/kbd/", func(ui.Event) {
ui.StopLoop()
})
ui.Loop()
}
func (w *Expanded) Row() *ui.Row {
return ui.NewRow(
ui.NewCol(2, 0, w.Cpu),
2017-01-07 20:37:11 +00:00
ui.NewCol(2, 0, w.Mem),
2017-01-06 19:46:30 +00:00
ui.NewCol(2, 0, w.Net),
)
}
func (w *Expanded) Highlight() {
}
func (w *Expanded) UnHighlight() {
}
func (w *Expanded) SetCPU(val int) {
w.Cpu.Update(val)
}
func (w *Expanded) SetNet(rx int64, tx int64) {
2017-01-07 20:37:11 +00:00
w.Net.Update(rx, tx)
2017-01-06 19:46:30 +00:00
}
func (w *Expanded) SetMem(val int64, limit int64, percent int) {
2017-01-07 20:37:11 +00:00
w.Mem.Update(int(val), int(limit))
2017-01-06 19:46:30 +00:00
}