mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add ctop header, disabled by default
This commit is contained in:
47
widgets/header.go
Normal file
47
widgets/header.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type CTopHeader struct {
|
||||
Time *ui.Par
|
||||
Count *ui.Par
|
||||
}
|
||||
|
||||
func NewCTopHeader() *CTopHeader {
|
||||
return &CTopHeader{
|
||||
Time: headerPar(timeStr()),
|
||||
Count: headerPar("-"),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CTopHeader) Row() *ui.Row {
|
||||
c.Time.Text = timeStr()
|
||||
return ui.NewRow(
|
||||
ui.NewCol(2, 0, c.Time),
|
||||
ui.NewCol(2, 0, c.Count),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *CTopHeader) SetCount(val int) {
|
||||
c.Count.Text = fmt.Sprintf("%d containers", val)
|
||||
}
|
||||
|
||||
func timeStr() string {
|
||||
return time.Now().Local().Format("15:04:05 MST")
|
||||
}
|
||||
|
||||
func headerPar(s string) *ui.Par {
|
||||
p := ui.NewPar(fmt.Sprintf(" %s", s))
|
||||
p.Border = false
|
||||
p.Height = 1
|
||||
p.Width = 20
|
||||
p.TextFgColor = ui.ColorDefault
|
||||
p.TextBgColor = ui.ColorWhite
|
||||
p.Bg = ui.ColorWhite
|
||||
return p
|
||||
}
|
||||
Reference in New Issue
Block a user