Dan Anglin
1bf60d2b1f
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
50 lines
746 B
Go
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()
|
|
}()
|
|
}
|