Skip to content

Commit

Permalink
Merge pull request bcicen#247 from stokito/more_columns
Browse files Browse the repository at this point in the history
More columns
  • Loading branch information
bcicen authored Dec 14, 2020
2 parents b562c92 + 491cd85 commit 537bb2a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
38 changes: 29 additions & 9 deletions config/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,67 @@ import (

// defaults
var defaultColumns = []Column{
Column{
{
Name: "status",
Label: "Status Indicator",
Enabled: true,
},
Column{
{
Name: "name",
Label: "Container Name",
Enabled: true,
},
Column{
{
Name: "id",
Label: "Container ID",
Enabled: true,
},
Column{
{
Name: "image",
Label: "Image name",
Enabled: false,
},
{
Name: "ports",
Label: "Exposed ports",
Enabled: false,
},
{
Name: "IPs",
Label: "Exposed IPs",
Enabled: false,
},
{
Name: "created",
Label: "Date created",
Enabled: false,
},
{
Name: "cpu",
Label: "CPU Usage",
Enabled: true,
},
Column{
{
Name: "cpus",
Label: "CPU Usage (% of system total)",
Enabled: false,
},
Column{
{
Name: "mem",
Label: "Memory Usage",
Enabled: true,
},
Column{
{
Name: "net",
Label: "Network RX/TX",
Enabled: true,
},
Column{
{
Name: "io",
Label: "Disk IO Read/Write",
Enabled: true,
},
Column{
{
Name: "pids",
Label: "Container PID Count",
Enabled: true,
Expand Down
22 changes: 13 additions & 9 deletions cwidgets/compact/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import (

var (
allCols = map[string]NewCompactColFn{
"status": NewStatus,
"name": NewNameCol,
"id": NewCIDCol,
"cpu": NewCPUCol,
"cpus": NewCpuScaledCol,
"mem": NewMemCol,
"net": NewNetCol,
"io": NewIOCol,
"pids": NewPIDCol,
"status": NewStatus,
"name": NewNameCol,
"id": NewCIDCol,
"image": NewImageCol,
"ports": NewPortsCol,
"IPs": NewIpsCol,
"created": NewCreatedCol,
"cpu": NewCPUCol,
"cpus": NewCpuScaledCol,
"mem": NewMemCol,
"net": NewNetCol,
"io": NewIOCol,
"pids": NewPIDCol,
}
)

Expand Down
36 changes: 24 additions & 12 deletions cwidgets/compact/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,44 @@ import (
ui "github.com/gizak/termui"
)

type NameCol struct {
// Column that shows container's meta property i.e. name, id, image tc.
type MetaCol struct {
*TextCol
metaName string
}

func (w *MetaCol) SetMeta(m models.Meta) {
w.setText(m.Get(w.metaName))
}

func NewNameCol() CompactCol {
c := &NameCol{NewTextCol("NAME")}
c := &MetaCol{NewTextCol("NAME"), "name"}
c.fWidth = 30
return c
}

func (w *NameCol) SetMeta(m models.Meta) {
w.setText(m.Get("name"))
func NewCIDCol() CompactCol {
c := &MetaCol{NewTextCol("CID"), "id"}
c.fWidth = 12
return c
}

type CIDCol struct {
*TextCol
func NewImageCol() CompactCol {
return &MetaCol{NewTextCol("IMAGE"), "image"}
}

func NewCIDCol() CompactCol {
c := &CIDCol{NewTextCol("CID")}
c.fWidth = 12
return c
func NewPortsCol() CompactCol {
return &MetaCol{NewTextCol("PORTS"), "ports"}
}

func (w *CIDCol) SetMeta(m models.Meta) {
w.setText(m.Get("id"))
func NewIpsCol() CompactCol {
return &MetaCol{NewTextCol("IPs"), "IPs"}
}

func NewCreatedCol() CompactCol {
c := &MetaCol{NewTextCol("CREATED"), "created"}
c.fWidth = 19 // Year will be stripped e.g. "Thu Nov 26 07:44:03" without 2020 at end
return c
}

type NetCol struct {
Expand Down

0 comments on commit 537bb2a

Please sign in to comment.