2017-01-06 13:49:22 +00:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CTopHeader struct {
|
2017-02-13 03:37:17 +00:00
|
|
|
Time *ui.Par
|
|
|
|
Count *ui.Par
|
|
|
|
Filter *ui.Par
|
2017-02-18 03:31:50 +00:00
|
|
|
bg *ui.Par
|
2017-01-06 13:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCTopHeader() *CTopHeader {
|
|
|
|
return &CTopHeader{
|
2017-02-18 03:31:50 +00:00
|
|
|
Time: headerPar(2, timeStr()),
|
2017-02-19 23:52:59 +00:00
|
|
|
Count: headerPar(27, "-"),
|
|
|
|
Filter: headerPar(47, ""),
|
2017-02-18 03:31:50 +00:00
|
|
|
bg: headerBg(),
|
2017-01-06 13:49:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:31:50 +00:00
|
|
|
func (c *CTopHeader) Render() {
|
2017-01-06 13:49:22 +00:00
|
|
|
c.Time.Text = timeStr()
|
2017-02-18 03:31:50 +00:00
|
|
|
ui.Render(c.bg)
|
|
|
|
ui.Render(c.Time, c.Count, c.Filter)
|
|
|
|
}
|
|
|
|
|
2017-02-19 23:52:59 +00:00
|
|
|
func (c *CTopHeader) Align() {
|
|
|
|
c.bg.SetWidth(ui.TermWidth() - 1)
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:31:50 +00:00
|
|
|
func (c *CTopHeader) Height() int {
|
|
|
|
return c.bg.Height
|
|
|
|
}
|
|
|
|
|
|
|
|
func headerBgBordered() *ui.Par {
|
|
|
|
bg := ui.NewPar("")
|
|
|
|
bg.X = 1
|
|
|
|
bg.Width = ui.TermWidth() - 1
|
|
|
|
bg.Height = 3
|
|
|
|
bg.Bg = ui.ColorWhite
|
|
|
|
return bg
|
|
|
|
}
|
|
|
|
|
|
|
|
func headerBg() *ui.Par {
|
|
|
|
bg := ui.NewPar("")
|
|
|
|
bg.X = 1
|
|
|
|
bg.Width = ui.TermWidth() - 1
|
|
|
|
bg.Height = 1
|
|
|
|
bg.Border = false
|
|
|
|
bg.Bg = ui.ColorWhite
|
|
|
|
return bg
|
2017-01-06 13:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CTopHeader) SetCount(val int) {
|
|
|
|
c.Count.Text = fmt.Sprintf("%d containers", val)
|
|
|
|
}
|
|
|
|
|
2017-02-13 03:37:17 +00:00
|
|
|
func (c *CTopHeader) SetFilter(val string) {
|
|
|
|
if val == "" {
|
|
|
|
c.Filter.Text = ""
|
|
|
|
} else {
|
|
|
|
c.Filter.Text = fmt.Sprintf("filter: %s", val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 13:49:22 +00:00
|
|
|
func timeStr() string {
|
2017-02-19 23:52:59 +00:00
|
|
|
ts := time.Now().Local().Format("15:04:05 MST")
|
|
|
|
return fmt.Sprintf("cTop - %s", ts)
|
2017-01-06 13:49:22 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 03:31:50 +00:00
|
|
|
func headerPar(x int, s string) *ui.Par {
|
2017-01-06 13:49:22 +00:00
|
|
|
p := ui.NewPar(fmt.Sprintf(" %s", s))
|
2017-02-18 03:31:50 +00:00
|
|
|
p.X = x
|
2017-01-06 13:49:22 +00:00
|
|
|
p.Border = false
|
|
|
|
p.Height = 1
|
|
|
|
p.Width = 20
|
|
|
|
p.TextFgColor = ui.ColorDefault
|
|
|
|
p.TextBgColor = ui.ColorWhite
|
|
|
|
p.Bg = ui.ColorWhite
|
|
|
|
return p
|
|
|
|
}
|