mirror of
https://github.com/miguelmota/cointop
synced 2024-11-10 13:10:26 +00:00
77f5c752e9
Former-commit-id: 807a38499b5e912a909d18e142ac5ffd27518f47 [formerly 807a38499b5e912a909d18e142ac5ffd27518f47 [formerly 3b23f739d91859165827c1af6a923cf7be19a1d5 [formerly 6f3f3dd824
]]]
Former-commit-id: 36948040aa5bec0dd2c25ec210e02349f5bddf0a
Former-commit-id: 4b1b9d17fc425bc764a46d0fdcd12747cca608f5 [formerly 56d4451c69972aa25ed17119773e6af9085b00c1]
Former-commit-id: 7967040e3a6348128010d3bc0ad213e5eabbf567
79 lines
1.2 KiB
Go
79 lines
1.2 KiB
Go
package table
|
|
|
|
// FormatFn format function
|
|
type FormatFn func(interface{}) string
|
|
|
|
// Col struct
|
|
type Col struct {
|
|
name string
|
|
hide bool
|
|
format string
|
|
formatFn FormatFn
|
|
align Align
|
|
width int
|
|
perc float32
|
|
minWidth int
|
|
minWidthPerc int
|
|
}
|
|
|
|
// Cols columns
|
|
type Cols []*Col
|
|
|
|
// Hide hide
|
|
func (c *Col) Hide() *Col {
|
|
c.hide = true
|
|
return c
|
|
}
|
|
|
|
// SetFormatFn set format function
|
|
func (c *Col) SetFormatFn(f FormatFn) *Col {
|
|
c.formatFn = f
|
|
return c
|
|
}
|
|
|
|
// SetFormat sets format
|
|
func (c *Col) SetFormat(f string) *Col {
|
|
c.format = f
|
|
return c
|
|
}
|
|
|
|
// AlignLeft align left
|
|
func (c *Col) AlignLeft() *Col {
|
|
c.align = AlignLeft
|
|
return c
|
|
}
|
|
|
|
// AlignRight align right
|
|
func (c *Col) AlignRight() *Col {
|
|
c.align = AlignRight
|
|
return c
|
|
}
|
|
|
|
// AlignCenter align center
|
|
func (c *Col) AlignCenter() *Col {
|
|
c.align = AlignCenter
|
|
return c
|
|
}
|
|
|
|
// SetWidth set width
|
|
func (c *Col) SetWidth(w int) *Col {
|
|
c.minWidth = w
|
|
return c
|
|
}
|
|
|
|
// SetWidthPerc set width percentage
|
|
func (c *Col) SetWidthPerc(w int) *Col {
|
|
c.minWidthPerc = w
|
|
return c
|
|
}
|
|
|
|
// Index index
|
|
func (c Cols) Index(n string) int {
|
|
for i := range c {
|
|
if c[i].name == n {
|
|
return i
|
|
}
|
|
}
|
|
return -1
|
|
}
|