From 9545dfba31054d824726a0120fc8fe77ce0d9c22 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 11 Dec 2020 20:59:35 +0200 Subject: [PATCH] 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 }