mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
commit missing compact column, row files
This commit is contained in:
parent
ed194e8c04
commit
a8e235beca
49
cwidgets/compact/column.go
Normal file
49
cwidgets/compact/column.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package compact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bcicen/ctop/config"
|
||||||
|
"github.com/bcicen/ctop/models"
|
||||||
|
|
||||||
|
ui "github.com/gizak/termui"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
allCols = map[string]NewCompactColFn{
|
||||||
|
"status": NewStatus,
|
||||||
|
"name": NewNameCol,
|
||||||
|
"id": NewCIDCol,
|
||||||
|
"cpu": NewCPUCol,
|
||||||
|
"mem": NewMemCol,
|
||||||
|
"net": NewNetCol,
|
||||||
|
"io": NewIOCol,
|
||||||
|
"pids": NewPIDCol,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type NewCompactColFn func() CompactCol
|
||||||
|
|
||||||
|
func newRowWidgets() []CompactCol {
|
||||||
|
enabled := config.EnabledColumns()
|
||||||
|
cols := make([]CompactCol, len(enabled))
|
||||||
|
|
||||||
|
for n, name := range enabled {
|
||||||
|
wFn, ok := allCols[name]
|
||||||
|
if !ok {
|
||||||
|
panic("no such widget name: %s" + name)
|
||||||
|
}
|
||||||
|
cols[n] = wFn()
|
||||||
|
}
|
||||||
|
|
||||||
|
return cols
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompactCol interface {
|
||||||
|
ui.GridBufferer
|
||||||
|
Reset()
|
||||||
|
Header() string // header text to display for column
|
||||||
|
FixedWidth() int // fixed width size. if == 0, width is automatically calculated
|
||||||
|
Highlight()
|
||||||
|
UnHighlight()
|
||||||
|
SetMeta(models.Meta)
|
||||||
|
SetMetrics(models.Metrics)
|
||||||
|
}
|
129
cwidgets/compact/row.go
Normal file
129
cwidgets/compact/row.go
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
package compact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bcicen/ctop/config"
|
||||||
|
"github.com/bcicen/ctop/logging"
|
||||||
|
"github.com/bcicen/ctop/models"
|
||||||
|
|
||||||
|
ui "github.com/gizak/termui"
|
||||||
|
)
|
||||||
|
|
||||||
|
const rowPadding = 1
|
||||||
|
|
||||||
|
var log = logging.Init()
|
||||||
|
|
||||||
|
type RowBufferer interface {
|
||||||
|
SetY(int)
|
||||||
|
SetWidths(int, []int)
|
||||||
|
GetHeight() int
|
||||||
|
Buffer() ui.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompactRow struct {
|
||||||
|
Bg *RowBg
|
||||||
|
Cols []CompactCol
|
||||||
|
X, Y int
|
||||||
|
Height int
|
||||||
|
widths []int // column widths
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCompactRow() *CompactRow {
|
||||||
|
row := &CompactRow{
|
||||||
|
Bg: NewRowBg(),
|
||||||
|
Cols: newRowWidgets(),
|
||||||
|
X: rowPadding,
|
||||||
|
Height: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) SetMeta(m models.Meta) {
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
w.SetMeta(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) SetMetrics(m models.Metrics) {
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
w.SetMetrics(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set gauges, counters, etc. to default unread values
|
||||||
|
func (row *CompactRow) Reset() {
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
w.Reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) GetHeight() int { return row.Height }
|
||||||
|
|
||||||
|
//func (row *CompactRow) SetX(x int) { row.X = x }
|
||||||
|
|
||||||
|
func (row *CompactRow) SetY(y int) {
|
||||||
|
if y == row.Y {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
row.Bg.Y = y
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
w.SetY(y)
|
||||||
|
}
|
||||||
|
row.Y = y
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) SetWidths(totalWidth int, widths []int) {
|
||||||
|
x := row.X
|
||||||
|
|
||||||
|
row.Bg.SetX(x)
|
||||||
|
row.Bg.SetWidth(totalWidth)
|
||||||
|
|
||||||
|
for n, w := range row.Cols {
|
||||||
|
w.SetX(x)
|
||||||
|
w.SetWidth(widths[n])
|
||||||
|
x += widths[n] + colSpacing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) Buffer() ui.Buffer {
|
||||||
|
buf := ui.NewBuffer()
|
||||||
|
buf.Merge(row.Bg.Buffer())
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
buf.Merge(w.Buffer())
|
||||||
|
}
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) Highlight() {
|
||||||
|
row.Cols[1].Highlight()
|
||||||
|
if config.GetSwitchVal("fullRowCursor") {
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
w.Highlight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (row *CompactRow) UnHighlight() {
|
||||||
|
row.Cols[1].UnHighlight()
|
||||||
|
if config.GetSwitchVal("fullRowCursor") {
|
||||||
|
for _, w := range row.Cols {
|
||||||
|
w.UnHighlight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type RowBg struct {
|
||||||
|
*ui.Par
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRowBg() *RowBg {
|
||||||
|
bg := ui.NewPar("")
|
||||||
|
bg.Height = 1
|
||||||
|
bg.Border = false
|
||||||
|
bg.Bg = ui.ThemeAttr("par.text.bg")
|
||||||
|
return &RowBg{bg}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *RowBg) Highlight() { w.Bg = ui.ThemeAttr("par.text.fg") }
|
||||||
|
func (w *RowBg) UnHighlight() { w.Bg = ui.ThemeAttr("par.text.bg") }
|
Loading…
Reference in New Issue
Block a user