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
|
|
|
|
}
|
|
|
|
|
2020-04-28 09:33:41 +08:00
|
|
|
func (sb *StatusBar) Draw(buf *ui.Buffer) {
|
|
|
|
sb.Block.Draw(buf)
|
2019-01-01 18:15:31 +08:00
|
|
|
|
2019-03-01 08:29:52 +08:00
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
2020-06-21 05:47:48 +08:00
|
|
|
log.Printf(tr.Value("error.nohostname", err.Error()))
|
2019-03-01 08:29:52 +08:00
|
|
|
return
|
|
|
|
}
|
2019-01-01 18:15:31 +08:00
|
|
|
buf.SetString(
|
|
|
|
hostname,
|
2020-04-16 23:18:00 +08:00
|
|
|
ui.Theme.Default,
|
2020-04-28 09:33:41 +08:00
|
|
|
image.Pt(sb.Inner.Min.X, sb.Inner.Min.Y+(sb.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,
|
2020-04-16 23:18:00 +08:00
|
|
|
ui.Theme.Default,
|
2019-01-01 18:15:31 +08:00
|
|
|
image.Pt(
|
2020-04-28 09:33:41 +08:00
|
|
|
sb.Inner.Min.X+(sb.Inner.Dx()/2)-len(formattedTime)/2,
|
|
|
|
sb.Inner.Min.Y+(sb.Inner.Dy()/2),
|
2019-01-01 18:15:31 +08:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2021-01-27 04:17:00 +08:00
|
|
|
// i, e := host.Info()
|
|
|
|
// i.Uptime // Number of seconds since boot
|
2019-01-01 18:15:31 +08:00
|
|
|
buf.SetString(
|
|
|
|
"gotop",
|
2020-04-16 23:18:00 +08:00
|
|
|
ui.Theme.Default,
|
2019-01-01 18:15:31 +08:00
|
|
|
image.Pt(
|
2020-04-28 09:33:41 +08:00
|
|
|
sb.Inner.Max.X-6,
|
|
|
|
sb.Inner.Min.Y+(sb.Inner.Dy()/2),
|
2019-01-01 18:15:31 +08:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|