2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-10 13:10:26 +00:00
cointop/table/column.go

79 lines
1.2 KiB
Go
Raw Normal View History

2018-03-29 22:02:24 +00:00
package table
// FormatFn format function
2018-03-29 22:02:24 +00:00
type FormatFn func(interface{}) string
// Col struct
2018-03-29 22:02:24 +00:00
type Col struct {
name string
hide bool
format string
formatFn FormatFn
align Align
width int
perc float32
minWidth int
minWidthPerc int
}
// Cols columns
2018-03-29 22:02:24 +00:00
type Cols []*Col
// Hide hide
2018-03-29 22:02:24 +00:00
func (c *Col) Hide() *Col {
c.hide = true
return c
}
// SetFormatFn set format function
func (c *Col) SetFormatFn(f FormatFn) *Col {
c.formatFn = f
2018-03-29 22:02:24 +00:00
return c
}
// SetFormat sets format
func (c *Col) SetFormat(f string) *Col {
c.format = f
2018-03-29 22:02:24 +00:00
return c
}
// AlignLeft align left
2018-03-29 22:02:24 +00:00
func (c *Col) AlignLeft() *Col {
c.align = AlignLeft
return c
}
// AlignRight align right
2018-03-29 22:02:24 +00:00
func (c *Col) AlignRight() *Col {
c.align = AlignRight
return c
}
// AlignCenter align center
2018-03-29 22:02:24 +00:00
func (c *Col) AlignCenter() *Col {
c.align = AlignCenter
return c
}
// SetWidth set width
2018-03-29 22:02:24 +00:00
func (c *Col) SetWidth(w int) *Col {
c.minWidth = w
return c
}
// SetWidthPerc set width percentage
2018-03-29 22:02:24 +00:00
func (c *Col) SetWidthPerc(w int) *Col {
c.minWidthPerc = w
return c
}
// Index index
2018-03-29 22:02:24 +00:00
func (c Cols) Index(n string) int {
for i := range c {
if c[i].name == n {
return i
}
}
return -1
}