pelican/internal/ui/statusbar.go
Dan Anglin 1bf60d2b1f
All checks were successful
/ test (pull_request) Successful in 33s
/ lint (pull_request) Successful in 35s
feat(ui): add a status bar
This commit adds a status bar at the bottom of the application for
displaying confirmation and error messages to the user.

Resolves apollo/pelican#19
2024-01-13 12:34:16 +00:00

50 lines
746 B
Go

package ui
import (
"fmt"
"time"
"github.com/rivo/tview"
)
type statusbarLogLevel int
const (
infoLevel statusbarLogLevel = iota
errorLevel
)
type statusbar struct {
*tview.TextView
duration time.Duration
}
func newStatusbar() *statusbar {
obj := statusbar{
TextView: tview.NewTextView(),
duration: 5 * time.Second,
}
obj.SetDynamicColors(true).SetBorder(false).SetBorderPadding(0, 0, 1, 1)
return &obj
}
func (s *statusbar) displayMessage(category statusbarLogLevel, message string) {
go func() {
var colour string
switch category {
case infoLevel:
colour = "green"
case errorLevel:
colour = "red"
}
fmt.Fprintf(s, "[%s::b]%s[-:-:-:-]", colour, message)
time.Sleep(s.duration)
s.Clear()
}()
}