33 lines
608 B
Go
Raw Normal View History

2023-08-17 23:10:09 +00:00
package clock
import (
"time"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
const (
interval = 1 * time.Second
format = "15:04:05"
)
func New(app *tview.Application) *tview.TextView {
view := tview.NewTextView()
view.SetTextAlign(tview.AlignCenter)
view.SetBackgroundColor(tcell.ColorDefault)
view.SetText(time.Now().Format(format))
view.SetBorderPadding(1, 1, 1, 1)
go refresh(app, view)
return view
}
func refresh(app *tview.Application, view *tview.TextView) {
tick := time.NewTicker(interval)
2023-08-18 11:17:46 +00:00
for range tick.C {
view.SetText(time.Now().Format(format))
app.Draw()
2023-08-17 23:10:09 +00:00
}
}