From cdcb8b6d99e6ae349f856a5929efe10e8aff4640 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 11 Dec 2020 20:32:22 +0200 Subject: [PATCH 1/3] columns.go: remove redundant type --- config/columns.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config/columns.go b/config/columns.go index da9f7fa..9336356 100644 --- a/config/columns.go +++ b/config/columns.go @@ -6,47 +6,47 @@ 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: "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, From 9545dfba31054d824726a0120fc8fe77ce0d9c22 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 11 Dec 2020 20:59:35 +0200 Subject: [PATCH 2/3] Extract MetaCol --- cwidgets/compact/text.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/cwidgets/compact/text.go b/cwidgets/compact/text.go index ef2642b..9df5774 100644 --- a/cwidgets/compact/text.go +++ b/cwidgets/compact/text.go @@ -9,34 +9,28 @@ 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")) -} - -type CIDCol struct { - *TextCol -} - func NewCIDCol() CompactCol { - c := &CIDCol{NewTextCol("CID")} + c := &MetaCol{NewTextCol("CID"), "id"} c.fWidth = 12 return c } -func (w *CIDCol) SetMeta(m models.Meta) { - w.setText(m.Get("id")) -} - type NetCol struct { *TextCol } From 491cd85b4d9a5fa6945315ae7cbd31f47c9068d2 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 11 Dec 2020 21:58:37 +0200 Subject: [PATCH 3/3] Additional columns --- config/columns.go | 20 ++++++++++++++++++++ cwidgets/compact/column.go | 22 +++++++++++++--------- cwidgets/compact/text.go | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/config/columns.go b/config/columns.go index 9336356..fb539d8 100644 --- a/config/columns.go +++ b/config/columns.go @@ -21,6 +21,26 @@ var defaultColumns = []Column{ Label: "Container ID", Enabled: true, }, + { + 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", diff --git a/cwidgets/compact/column.go b/cwidgets/compact/column.go index 4ff0793..7558dd9 100644 --- a/cwidgets/compact/column.go +++ b/cwidgets/compact/column.go @@ -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, } ) diff --git a/cwidgets/compact/text.go b/cwidgets/compact/text.go index 9df5774..5b3432b 100644 --- a/cwidgets/compact/text.go +++ b/cwidgets/compact/text.go @@ -31,6 +31,24 @@ func NewCIDCol() CompactCol { return c } +func NewImageCol() CompactCol { + return &MetaCol{NewTextCol("IMAGE"), "image"} +} + +func NewPortsCol() CompactCol { + return &MetaCol{NewTextCol("PORTS"), "ports"} +} + +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 { *TextCol }