2023-08-18 13:17:46 +02:00

33 lines
608 B
Go

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)
for range tick.C {
view.SetText(time.Now().Format(format))
app.Draw()
}
}