2023-08-18 18:52:40 +02:00

27 lines
576 B
Go

package clock
import (
"time"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func New(format string, interval time.Duration) *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(view, format, interval)
return view
}
func refresh(view *tview.TextView, format string, interval time.Duration) {
tick := time.NewTicker(interval)
for range tick.C {
view.SetText(time.Now().Format(format))
}
}