2019-02-25 00:08:36 +00:00
|
|
|
package component
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-03-14 03:01:44 +00:00
|
|
|
ui "github.com/gizak/termui/v3"
|
2019-02-25 00:08:36 +00:00
|
|
|
"github.com/sqshq/sampler/console"
|
|
|
|
"image"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
bindingsIndent = 4
|
|
|
|
)
|
|
|
|
|
|
|
|
type StatusBar struct {
|
2019-03-24 00:16:59 +00:00
|
|
|
*ui.Block
|
2019-02-25 00:08:36 +00:00
|
|
|
keyBindings []string
|
|
|
|
configFileName string
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:16:59 +00:00
|
|
|
func NewStatusLine(configFileName string, palette console.Palette) *StatusBar {
|
2019-02-25 00:08:36 +00:00
|
|
|
block := *ui.NewBlock()
|
|
|
|
block.Border = false
|
|
|
|
return &StatusBar{
|
2019-03-24 00:16:59 +00:00
|
|
|
Block: NewBlock("", false, palette),
|
2019-02-25 00:08:36 +00:00
|
|
|
configFileName: configFileName,
|
|
|
|
keyBindings: []string{
|
|
|
|
"(Q) quit",
|
|
|
|
"(P) pause",
|
|
|
|
"(<->) selection",
|
2019-03-08 04:04:46 +00:00
|
|
|
"(ESC) reset alerts",
|
2019-02-25 00:08:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StatusBar) Draw(buffer *ui.Buffer) {
|
|
|
|
buffer.Fill(ui.NewCell(' ', ui.NewStyle(console.ColorClear, console.MenuColorBackground)), s.GetRect())
|
2019-05-14 03:24:29 +00:00
|
|
|
|
|
|
|
if false { // TODO check license
|
|
|
|
buffer.SetString(fmt.Sprintf(" %s", console.AppLicenseWarning), ui.NewStyle(console.MenuColorText, console.MenuColorBackground), s.Min)
|
|
|
|
} else {
|
|
|
|
buffer.SetString(fmt.Sprintf(" %s %s @ %s", console.AppTitle, console.AppVersion, s.configFileName), ui.NewStyle(console.MenuColorText, console.MenuColorBackground), s.Min)
|
|
|
|
}
|
2019-02-25 00:08:36 +00:00
|
|
|
|
|
|
|
indent := bindingsIndent
|
|
|
|
for _, binding := range s.keyBindings {
|
|
|
|
buffer.SetString(binding, ui.NewStyle(console.MenuColorText, console.MenuColorBackground), image.Pt(s.Max.X-len(binding)-indent, s.Min.Y))
|
|
|
|
indent += bindingsIndent + len(binding)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Block.Draw(buffer)
|
|
|
|
}
|