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)) } }