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