2019-01-01 18:15:31 +08:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2019-03-01 08:29:52 +08:00
|
|
|
"log"
|
2019-01-01 18:15:31 +08:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2019-03-08 15:15:41 +08:00
|
|
|
ui "github.com/gizak/termui/v3"
|
2019-01-01 18:15:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type StatusBar struct {
|
|
|
|
ui.Block
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewStatusBar() *StatusBar {
|
|
|
|
self := &StatusBar{*ui.NewBlock()}
|
|
|
|
self.Border = false
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StatusBar) Draw(buf *ui.Buffer) {
|
|
|
|
self.Block.Draw(buf)
|
|
|
|
|
2019-03-01 08:29:52 +08:00
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("could not get hostname: %v", err)
|
|
|
|
return
|
|
|
|
}
|
2019-01-01 18:15:31 +08:00
|
|
|
buf.SetString(
|
|
|
|
hostname,
|
2019-03-01 08:29:52 +08:00
|
|
|
ui.NewStyle(ui.ColorWhite),
|
2019-01-15 11:47:44 +08:00
|
|
|
image.Pt(self.Inner.Min.X, self.Inner.Min.Y+(self.Inner.Dy()/2)),
|
2019-01-01 18:15:31 +08:00
|
|
|
)
|
|
|
|
|
2019-03-01 08:29:52 +08:00
|
|
|
currentTime := time.Now()
|
|
|
|
formattedTime := currentTime.Format("15:04:05")
|
2019-01-01 18:15:31 +08:00
|
|
|
buf.SetString(
|
2019-03-01 08:29:52 +08:00
|
|
|
formattedTime,
|
|
|
|
ui.NewStyle(ui.ColorWhite),
|
2019-01-01 18:15:31 +08:00
|
|
|
image.Pt(
|
2019-03-01 08:29:52 +08:00
|
|
|
self.Inner.Min.X+(self.Inner.Dx()/2)-len(formattedTime)/2,
|
2019-01-01 18:15:31 +08:00
|
|
|
self.Inner.Min.Y+(self.Inner.Dy()/2),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
buf.SetString(
|
|
|
|
"gotop",
|
2019-03-01 08:29:52 +08:00
|
|
|
ui.NewStyle(ui.ColorWhite),
|
2019-01-01 18:15:31 +08:00
|
|
|
image.Pt(
|
|
|
|
self.Inner.Max.X-6,
|
|
|
|
self.Inner.Min.Y+(self.Inner.Dy()/2),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|