mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
remove Render method from containerWidgets interface
This commit is contained in:
parent
70f2648952
commit
6cc357bb97
@ -35,12 +35,7 @@ func (c *Container) ShortName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) Expand() {
|
func (c *Container) Expand() {
|
||||||
var curWidgets cwidgets.ContainerWidgets
|
|
||||||
|
|
||||||
curWidgets = c.widgets
|
|
||||||
c.widgets = expanded.NewExpanded(c.ShortID(), c.name)
|
c.widgets = expanded.NewExpanded(c.ShortID(), c.name)
|
||||||
c.widgets.Render(0, 0)
|
|
||||||
c.widgets = curWidgets
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) SetState(s string) {
|
func (c *Container) SetState(s string) {
|
||||||
|
@ -7,11 +7,12 @@ import (
|
|||||||
|
|
||||||
type CompactGrid struct {
|
type CompactGrid struct {
|
||||||
ui.GridBufferer
|
ui.GridBufferer
|
||||||
Rows []cwidgets.ContainerWidgets
|
Rows []cwidgets.ContainerWidgets
|
||||||
X, Y int
|
X, Y int
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
header *CompactHeader
|
header *CompactHeader
|
||||||
|
cursorID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCompactGrid() *CompactGrid {
|
func NewCompactGrid() *CompactGrid {
|
||||||
|
@ -5,7 +5,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CompactHeader struct {
|
type CompactHeader struct {
|
||||||
pars []*ui.Par
|
pars []*ui.Par
|
||||||
|
X, Y int
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCompactHeader() *CompactHeader {
|
func NewCompactHeader() *CompactHeader {
|
||||||
@ -18,6 +21,9 @@ func NewCompactHeader() *CompactHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompactHeader) SetWidth(w int) {
|
func (c *CompactHeader) SetWidth(w int) {
|
||||||
|
if w == c.Width {
|
||||||
|
return
|
||||||
|
}
|
||||||
x := 1
|
x := 1
|
||||||
autoWidth := calcWidth(w, 5)
|
autoWidth := calcWidth(w, 5)
|
||||||
for n, col := range c.pars {
|
for n, col := range c.pars {
|
||||||
@ -31,12 +37,17 @@ func (c *CompactHeader) SetWidth(w int) {
|
|||||||
col.SetWidth(autoWidth)
|
col.SetWidth(autoWidth)
|
||||||
x += autoWidth + colSpacing
|
x += autoWidth + colSpacing
|
||||||
}
|
}
|
||||||
|
c.Width = w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompactHeader) SetY(y int) {
|
func (c *CompactHeader) SetY(y int) {
|
||||||
|
if y == c.Y {
|
||||||
|
return
|
||||||
|
}
|
||||||
for _, p := range c.pars {
|
for _, p := range c.pars {
|
||||||
p.SetY(y)
|
p.SetY(y)
|
||||||
}
|
}
|
||||||
|
c.Y = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompactHeader) Buffer() ui.Buffer {
|
func (c *CompactHeader) Buffer() ui.Buffer {
|
||||||
|
@ -2,12 +2,15 @@ package compact
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bcicen/ctop/cwidgets"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/bcicen/ctop/cwidgets"
|
||||||
|
"github.com/bcicen/ctop/logging"
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logging.Init()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mark = string('\u25C9')
|
mark = string('\u25C9')
|
||||||
vBar = string('\u25AE')
|
vBar = string('\u25AE')
|
||||||
@ -22,47 +25,58 @@ type Compact struct {
|
|||||||
Name *ui.Par
|
Name *ui.Par
|
||||||
Cpu *ui.Gauge
|
Cpu *ui.Gauge
|
||||||
Memory *ui.Gauge
|
Memory *ui.Gauge
|
||||||
|
X, Y int
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCompact(id, name, status string) *Compact {
|
func NewCompact(id, name, status string) *Compact {
|
||||||
w := &Compact{
|
row := &Compact{
|
||||||
Status: slimPar(mark),
|
Status: slimPar(mark),
|
||||||
Cid: slimPar(id),
|
Cid: slimPar(id),
|
||||||
Name: slimPar(name),
|
Name: slimPar(name),
|
||||||
|
Height: 1,
|
||||||
}
|
}
|
||||||
w.Reset()
|
row.Reset()
|
||||||
w.SetStatus(status)
|
row.SetStatus(status)
|
||||||
return w
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set gauges, counters to default unread values
|
// Set gauges, counters to default unread values
|
||||||
func (w *Compact) Reset() {
|
func (row *Compact) Reset() {
|
||||||
w.Net = slimPar("-")
|
row.Net = slimPar("-")
|
||||||
w.Cpu = slimGauge()
|
row.Cpu = slimGauge()
|
||||||
w.Memory = slimGauge()
|
row.Memory = slimGauge()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) all() []ui.GridBufferer {
|
func (row *Compact) all() []ui.GridBufferer {
|
||||||
return []ui.GridBufferer{
|
return []ui.GridBufferer{
|
||||||
w.Status,
|
row.Status,
|
||||||
w.Name,
|
row.Name,
|
||||||
w.Cid,
|
row.Cid,
|
||||||
w.Cpu,
|
row.Cpu,
|
||||||
w.Memory,
|
row.Memory,
|
||||||
w.Net,
|
row.Net,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) SetY(y int) {
|
func (row *Compact) SetY(y int) {
|
||||||
for _, col := range w.all() {
|
if y == row.Y {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, col := range row.all() {
|
||||||
col.SetY(y)
|
col.SetY(y)
|
||||||
}
|
}
|
||||||
|
row.Y = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) SetWidth(width int) {
|
func (row *Compact) SetWidth(width int) {
|
||||||
|
if row.Width == width {
|
||||||
|
return
|
||||||
|
}
|
||||||
x := 1
|
x := 1
|
||||||
autoWidth := calcWidth(width, 5)
|
autoWidth := calcWidth(width, 5)
|
||||||
for n, col := range w.all() {
|
for n, col := range row.all() {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
col.SetWidth(statusWidth)
|
col.SetWidth(statusWidth)
|
||||||
@ -73,71 +87,71 @@ func (w *Compact) SetWidth(width int) {
|
|||||||
col.SetWidth(autoWidth)
|
col.SetWidth(autoWidth)
|
||||||
x += autoWidth + colSpacing
|
x += autoWidth + colSpacing
|
||||||
}
|
}
|
||||||
|
row.Width = width
|
||||||
|
log.Info("resized row width")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) Render(y, rowWidth int) {}
|
func (row *Compact) Buffer() ui.Buffer {
|
||||||
|
|
||||||
func (w *Compact) Buffer() ui.Buffer {
|
|
||||||
buf := ui.NewBuffer()
|
buf := ui.NewBuffer()
|
||||||
|
|
||||||
buf.Merge(w.Status.Buffer())
|
buf.Merge(row.Status.Buffer())
|
||||||
buf.Merge(w.Name.Buffer())
|
buf.Merge(row.Name.Buffer())
|
||||||
buf.Merge(w.Cid.Buffer())
|
buf.Merge(row.Cid.Buffer())
|
||||||
buf.Merge(w.Cpu.Buffer())
|
buf.Merge(row.Cpu.Buffer())
|
||||||
buf.Merge(w.Memory.Buffer())
|
buf.Merge(row.Memory.Buffer())
|
||||||
buf.Merge(w.Net.Buffer())
|
buf.Merge(row.Net.Buffer())
|
||||||
|
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) Highlight() {
|
func (row *Compact) Highlight() {
|
||||||
w.Name.TextFgColor = ui.ColorDefault
|
row.Name.TextFgColor = ui.ColorDefault
|
||||||
w.Name.TextBgColor = ui.ColorWhite
|
row.Name.TextBgColor = ui.ColorWhite
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) UnHighlight() {
|
func (row *Compact) UnHighlight() {
|
||||||
w.Name.TextFgColor = ui.ColorWhite
|
row.Name.TextFgColor = ui.ColorWhite
|
||||||
w.Name.TextBgColor = ui.ColorDefault
|
row.Name.TextBgColor = ui.ColorDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) SetStatus(val string) {
|
func (row *Compact) SetStatus(val string) {
|
||||||
switch val {
|
switch val {
|
||||||
case "running":
|
case "running":
|
||||||
w.Status.Text = mark
|
row.Status.Text = mark
|
||||||
w.Status.TextFgColor = ui.ColorGreen
|
row.Status.TextFgColor = ui.ColorGreen
|
||||||
case "exited":
|
case "exited":
|
||||||
w.Status.Text = mark
|
row.Status.Text = mark
|
||||||
w.Status.TextFgColor = ui.ColorRed
|
row.Status.TextFgColor = ui.ColorRed
|
||||||
case "paused":
|
case "paused":
|
||||||
w.Status.Text = fmt.Sprintf("%s%s", vBar, vBar)
|
row.Status.Text = fmt.Sprintf("%s%s", vBar, vBar)
|
||||||
w.Status.TextFgColor = ui.ColorDefault
|
row.Status.TextFgColor = ui.ColorDefault
|
||||||
default:
|
default:
|
||||||
w.Status.Text = mark
|
row.Status.Text = mark
|
||||||
w.Status.TextFgColor = ui.ColorRed
|
row.Status.TextFgColor = ui.ColorRed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) SetCPU(val int) {
|
func (row *Compact) SetCPU(val int) {
|
||||||
w.Cpu.BarColor = cwidgets.ColorScale(val)
|
row.Cpu.BarColor = cwidgets.ColorScale(val)
|
||||||
w.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
|
row.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
|
||||||
if val < 5 {
|
if val < 5 {
|
||||||
val = 5
|
val = 5
|
||||||
w.Cpu.BarColor = ui.ColorBlack
|
row.Cpu.BarColor = ui.ColorBlack
|
||||||
}
|
}
|
||||||
w.Cpu.Percent = val
|
row.Cpu.Percent = val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) SetNet(rx int64, tx int64) {
|
func (row *Compact) SetNet(rx int64, tx int64) {
|
||||||
w.Net.Text = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(rx), cwidgets.ByteFormat(tx))
|
row.Net.Text = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(rx), cwidgets.ByteFormat(tx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) SetMem(val int64, limit int64, percent int) {
|
func (row *Compact) SetMem(val int64, limit int64, percent int) {
|
||||||
w.Memory.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(val), cwidgets.ByteFormat(limit))
|
row.Memory.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(val), cwidgets.ByteFormat(limit))
|
||||||
if percent < 5 {
|
if percent < 5 {
|
||||||
percent = 5
|
percent = 5
|
||||||
w.Memory.BarColor = ui.ColorBlack
|
row.Memory.BarColor = ui.ColorBlack
|
||||||
} else {
|
} else {
|
||||||
w.Memory.BarColor = ui.ColorGreen
|
row.Memory.BarColor = ui.ColorGreen
|
||||||
}
|
}
|
||||||
w.Memory.Percent = percent
|
row.Memory.Percent = percent
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,12 @@ func NewInfo(id, name string) *ui.Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Expanded) Buffer() ui.Buffer {
|
func (w *Expanded) Buffer() ui.Buffer {
|
||||||
return ui.NewBuffer()
|
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) Reset() {}
|
||||||
@ -44,17 +49,6 @@ func (w *Expanded) Highlight() {}
|
|||||||
func (w *Expanded) UnHighlight() {}
|
func (w *Expanded) UnHighlight() {}
|
||||||
func (w *Expanded) SetStatus(val string) {}
|
func (w *Expanded) SetStatus(val string) {}
|
||||||
|
|
||||||
func (w *Expanded) Render(_, _ int) {
|
|
||||||
ui.Render(w.Info, w.Cpu, w.Mem, w.Net)
|
|
||||||
ui.Handle("/timer/1s", func(ui.Event) {
|
|
||||||
ui.Render(w.Info, w.Cpu, w.Mem, w.Net)
|
|
||||||
})
|
|
||||||
ui.Handle("/sys/kbd/", func(ui.Event) {
|
|
||||||
ui.StopLoop()
|
|
||||||
})
|
|
||||||
ui.Loop()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Expanded) SetCPU(val int) {
|
func (w *Expanded) SetCPU(val int) {
|
||||||
w.Cpu.Update(val)
|
w.Cpu.Update(val)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
var log = logging.Init()
|
var log = logging.Init()
|
||||||
|
|
||||||
type ContainerWidgets interface {
|
type ContainerWidgets interface {
|
||||||
Render(int, int)
|
|
||||||
Reset()
|
Reset()
|
||||||
Buffer() ui.Buffer
|
Buffer() ui.Buffer
|
||||||
Highlight()
|
Highlight()
|
||||||
|
14
grid.go
14
grid.go
@ -126,8 +126,22 @@ func (g *Grid) ExpandView() {
|
|||||||
ui.Clear()
|
ui.Clear()
|
||||||
ui.DefaultEvtStream.ResetHandlers()
|
ui.DefaultEvtStream.ResetHandlers()
|
||||||
defer ui.DefaultEvtStream.ResetHandlers()
|
defer ui.DefaultEvtStream.ResetHandlers()
|
||||||
|
|
||||||
container, _ := g.cSource.Get(g.cursorID)
|
container, _ := g.cSource.Get(g.cursorID)
|
||||||
|
// copy current widgets to restore on exit view
|
||||||
|
curWidgets := container.widgets
|
||||||
container.Expand()
|
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()
|
||||||
|
|
||||||
|
container.widgets = curWidgets
|
||||||
}
|
}
|
||||||
|
|
||||||
func logEvent(e ui.Event) {
|
func logEvent(e ui.Event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user