diff --git a/container.go b/container.go index 748c8ea..8144502 100644 --- a/container.go +++ b/container.go @@ -5,7 +5,6 @@ import ( "github.com/bcicen/ctop/cwidgets" "github.com/bcicen/ctop/cwidgets/compact" - "github.com/bcicen/ctop/cwidgets/expanded" "github.com/bcicen/ctop/metrics" ) @@ -35,10 +34,6 @@ func (c *Container) ShortName() string { return strings.Replace(c.name, "/", "", 1) // use primary container name } -func (c *Container) Expand() { - c.widgets = expanded.NewExpanded(c.ShortID(), c.name) -} - func (c *Container) SetState(s string) { c.state = s c.widgets.SetStatus(s) diff --git a/cwidgets/expanded/cpu.go b/cwidgets/expanded/cpu.go deleted file mode 100644 index a5c1491..0000000 --- a/cwidgets/expanded/cpu.go +++ /dev/null @@ -1,28 +0,0 @@ -package expanded - -import ( - ui "github.com/gizak/termui" -) - -type ExpandedCpu struct { - *ui.LineChart - hist FloatHist -} - -func NewExpandedCpu() *ExpandedCpu { - cpu := &ExpandedCpu{ui.NewLineChart(), NewFloatHist(60)} - cpu.BorderLabel = "CPU" - cpu.Height = 10 - cpu.Width = 50 - cpu.X = 0 - cpu.Y = 4 - cpu.Data = cpu.hist.Data - cpu.DataLabels = cpu.hist.Labels - cpu.AxesColor = ui.ColorDefault - cpu.LineColor = ui.ColorGreen - return cpu -} - -func (w *ExpandedCpu) Update(val int) { - w.hist.Append(float64(val)) -} diff --git a/cwidgets/expanded/hist.go b/cwidgets/expanded/hist.go deleted file mode 100644 index b431f2e..0000000 --- a/cwidgets/expanded/hist.go +++ /dev/null @@ -1,60 +0,0 @@ -package expanded - -type IntHist struct { - Val int // most current data point - Data []int // historical data points - Labels []string -} - -func NewIntHist(max int) *IntHist { - return &IntHist{ - Data: make([]int, max), - Labels: make([]string, max), - } -} - -func (h *IntHist) Append(val int) { - if len(h.Data) == cap(h.Data) { - h.Data = append(h.Data[:0], h.Data[1:]...) - } - h.Val = val - h.Data = append(h.Data, val) -} - -type DiffHist struct { - *IntHist - lastVal int -} - -func NewDiffHist(max int) *DiffHist { - return &DiffHist{NewIntHist(max), -1} -} - -func (h *DiffHist) Append(val int) { - if h.lastVal >= 0 { // skip append if this is the initial update - diff := val - h.lastVal - h.IntHist.Append(diff) - } - h.lastVal = val -} - -type FloatHist struct { - Val float64 // most current data point - Data []float64 // historical data points - Labels []string -} - -func NewFloatHist(max int) FloatHist { - return FloatHist{ - Data: make([]float64, max), - Labels: make([]string, max), - } -} - -func (h FloatHist) Append(val float64) { - if len(h.Data) == cap(h.Data) { - h.Data = append(h.Data[:0], h.Data[1:]...) - } - h.Val = val - h.Data = append(h.Data, val) -} diff --git a/cwidgets/expanded/main.go b/cwidgets/expanded/main.go deleted file mode 100644 index ef7c082..0000000 --- a/cwidgets/expanded/main.go +++ /dev/null @@ -1,62 +0,0 @@ -package expanded - -import ( - ui "github.com/gizak/termui" -) - -type Expanded struct { - Info *ui.Table - Net *ExpandedNet - Cpu *ExpandedCpu - Mem *ExpandedMem -} - -func NewExpanded(id, name string) *Expanded { - return &Expanded{ - Info: NewInfo(id, name), - Net: NewExpandedNet(), - Cpu: NewExpandedCpu(), - Mem: NewExpandedMem(), - } -} - -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 - p.FgColor = ui.ColorWhite - p.Seperator = false - return p -} - -func (w *Expanded) Buffer() ui.Buffer { - buf := ui.NewBuffer() - buf.Merge(w.Info.Buffer()) - buf.Merge(w.Cpu.Buffer()) - buf.Merge(w.Mem.Buffer()) - buf.Merge(w.Net.Buffer()) - return buf -} - -func (w *Expanded) Reset() {} -func (w *Expanded) SetY(_ int) {} -func (w *Expanded) SetWidth(_ int) {} -func (w *Expanded) Highlight() {} -func (w *Expanded) UnHighlight() {} -func (w *Expanded) SetStatus(val string) {} - -func (w *Expanded) SetCPU(val int) { - w.Cpu.Update(val) -} - -func (w *Expanded) SetNet(rx int64, tx int64) { - w.Net.Update(rx, tx) -} - -func (w *Expanded) SetMem(val int64, limit int64, percent int) { - w.Mem.Update(int(val), int(limit)) -} diff --git a/cwidgets/expanded/mem.go b/cwidgets/expanded/mem.go deleted file mode 100644 index 3b2a755..0000000 --- a/cwidgets/expanded/mem.go +++ /dev/null @@ -1,41 +0,0 @@ -package expanded - -import ( - "github.com/bcicen/ctop/cwidgets" - ui "github.com/gizak/termui" -) - -type ExpandedMem struct { - *ui.BarChart - hist *IntHist -} - -func NewExpandedMem() *ExpandedMem { - mem := &ExpandedMem{ - ui.NewBarChart(), - NewIntHist(8), - } - mem.BorderLabel = "MEM" - mem.Height = 10 - mem.Width = 50 - mem.BarWidth = 5 - mem.BarGap = 1 - mem.X = 0 - mem.Y = 14 - mem.TextColor = ui.ColorDefault - mem.Data = mem.hist.Data - mem.BarColor = ui.ColorGreen - mem.DataLabels = mem.hist.Labels - mem.NumFmt = cwidgets.ByteFormatInt - return mem -} - -func (w *ExpandedMem) Update(val int, limit int) { - // implement our own scaling for mem graph - if val*4 < limit { - w.SetMax(val * 4) - } else { - w.SetMax(limit) - } - w.hist.Append(val) -} diff --git a/cwidgets/expanded/net.go b/cwidgets/expanded/net.go deleted file mode 100644 index 7213e0b..0000000 --- a/cwidgets/expanded/net.go +++ /dev/null @@ -1,53 +0,0 @@ -package expanded - -import ( - "fmt" - "strings" - - "github.com/bcicen/ctop/cwidgets" - ui "github.com/gizak/termui" -) - -type ExpandedNet struct { - *ui.Sparklines - rxHist *DiffHist - txHist *DiffHist -} - -func NewExpandedNet() *ExpandedNet { - net := &ExpandedNet{ui.NewSparklines(), NewDiffHist(50), NewDiffHist(50)} - net.BorderLabel = "NET" - net.Height = 6 - net.Width = 50 - net.X = 0 - net.Y = 24 - - rx := ui.NewSparkline() - rx.Title = "RX" - rx.Height = 1 - rx.Data = net.rxHist.Data - rx.TitleColor = ui.ColorDefault - rx.LineColor = ui.ColorGreen - - tx := ui.NewSparkline() - tx.Title = "TX" - tx.Height = 1 - tx.Data = net.txHist.Data - tx.TitleColor = ui.ColorDefault - tx.LineColor = ui.ColorYellow - - net.Lines = []ui.Sparkline{rx, tx} - return net -} - -func (w *ExpandedNet) Update(rx int64, tx int64) { - var rate string - - w.rxHist.Append(int(rx)) - rate = strings.ToLower(cwidgets.ByteFormatInt(w.rxHist.Val)) - w.Lines[0].Title = fmt.Sprintf("RX [%s/s]", rate) - - w.txHist.Append(int(tx)) - rate = strings.ToLower(cwidgets.ByteFormatInt(w.txHist.Val)) - w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", rate) -} diff --git a/grid.go b/grid.go index 75eb8bb..75fd2c6 100644 --- a/grid.go +++ b/grid.go @@ -131,28 +131,28 @@ func (g *Grid) dumpContainer() { log.Infof(msg) } -func (g *Grid) ExpandView() { - ui.Clear() - ui.DefaultEvtStream.ResetHandlers() - defer ui.DefaultEvtStream.ResetHandlers() +//func (g *Grid) ExpandView() { +//ui.Clear() +//ui.DefaultEvtStream.ResetHandlers() +//defer ui.DefaultEvtStream.ResetHandlers() - container, _ := g.cSource.Get(g.cursorID) - // copy current widgets to restore on exit view - curWidgets := container.widgets - container.Expand() +//container, _ := g.cSource.Get(g.cursorID) +//// copy current widgets to restore on exit view +//curWidgets := container.widgets +//container.Expand() - ui.Render(container.widgets) - ui.Handle("/timer/1s", func(ui.Event) { - ui.Render(container.widgets) - }) - ui.Handle("/sys/kbd/", func(ui.Event) { - ui.StopLoop() - }) - ui.Loop() +//ui.Render(container.widgets) +//ui.Handle("/timer/1s", func(ui.Event) { +//ui.Render(container.widgets) +//}) +//ui.Handle("/sys/kbd/", func(ui.Event) { +//ui.StopLoop() +//}) +//ui.Loop() - container.widgets = curWidgets - container.widgets.Reset() -} +//container.widgets = curWidgets +//container.widgets.Reset() +//} func logEvent(e ui.Event) { var s string @@ -165,7 +165,6 @@ func logEvent(e ui.Event) { func Display(g *Grid) bool { var menu func() - var expand bool cGrid.SetWidth(ui.TermWidth()) ui.DefaultEvtStream.Hook(logEvent) @@ -180,7 +179,6 @@ func Display(g *Grid) bool { g.cursorDown() }) ui.Handle("/sys/kbd/", func(ui.Event) { - expand = true ui.StopLoop() }) @@ -231,9 +229,5 @@ func Display(g *Grid) bool { menu() return false } - if expand { - g.ExpandView() - return false - } return true }