27 lines
576 B
Go
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))
|
|
}
|
|
}
|