Termite is my playground for terminal app utilities and visual elements such as progress bars and indicators, cursor control and screen updates.
go get github.com/sha1n/termite
refreshInterval := time.Millisecond * 100
spinner := termite.NewSpinner(termite.StdoutWriter, "Processing...", refreshInterval, termite.DefaultSpinnerFormatter())
if _, e := spinner.Start(); e == nil {
doWork()
_ = spinner.Stop("Done!")
}
termWidth, _, _ := termite.GetTerminalDimensions()
progressBar := termite.NewProgressBar(termite.StdoutWriter, tickCount, width, termWidth, termite.DefaultProgressBarFormatter())
if tick, cancel, err := progressBar.Start(); err == nil {
defer cancel()
doWork(tick)
}
The code for this demo can be found in internal/main.go (go run internal/main.go
).