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 (
|
2019-06-07 05:09:37 +00:00
|
|
|
pauseText = " P A U S E D "
|
2019-06-07 05:39:11 +00:00
|
|
|
bindingsIndent = 3
|
2019-02-25 00:08:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type StatusBar struct {
|
2019-03-24 00:16:59 +00:00
|
|
|
*ui.Block
|
2019-05-21 03:18:23 +00:00
|
|
|
keyBindings []string
|
|
|
|
text string
|
2019-06-07 05:09:37 +00:00
|
|
|
pause bool
|
2019-02-25 00:08:36 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 02:05:01 +00:00
|
|
|
func NewStatusBar(configFileName string, palette console.Palette) *StatusBar {
|
2019-05-28 01:44:06 +00:00
|
|
|
|
2019-02-25 00:08:36 +00:00
|
|
|
block := *ui.NewBlock()
|
|
|
|
block.Border = false
|
2019-12-24 18:24:01 +00:00
|
|
|
text := fmt.Sprintf(" %s %s @ %s", console.AppTitle, console.AppVersion, configFileName)
|
2019-05-21 03:18:23 +00:00
|
|
|
|
2019-02-25 00:08:36 +00:00
|
|
|
return &StatusBar{
|
2019-05-21 03:18:23 +00:00
|
|
|
Block: NewBlock("", false, palette),
|
|
|
|
text: text,
|
2019-02-25 00:08:36 +00:00
|
|
|
keyBindings: []string{
|
2019-05-21 03:18:23 +00:00
|
|
|
"(q) quit",
|
|
|
|
"(p) pause",
|
2019-02-25 00:08:36 +00:00
|
|
|
"(<->) 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) {
|
2019-05-14 03:24:29 +00:00
|
|
|
|
2019-07-28 20:59:51 +00:00
|
|
|
buffer.Fill(ui.NewCell(' ', ui.NewStyle(console.ColorClear, console.GetMenuColorReverse())), s.GetRect())
|
2019-02-25 00:08:36 +00:00
|
|
|
|
|
|
|
indent := bindingsIndent
|
|
|
|
for _, binding := range s.keyBindings {
|
2019-07-28 20:59:51 +00:00
|
|
|
buffer.SetString(binding, ui.NewStyle(console.GetMenuColor(), console.GetMenuColorReverse()), image.Pt(s.Max.X-len(binding)-indent, s.Min.Y))
|
2019-02-25 00:08:36 +00:00
|
|
|
indent += bindingsIndent + len(binding)
|
|
|
|
}
|
|
|
|
|
2019-07-28 20:59:51 +00:00
|
|
|
buffer.SetString(s.text, ui.NewStyle(console.GetMenuColor(), console.GetMenuColorReverse()), s.Min)
|
2019-06-13 03:35:12 +00:00
|
|
|
|
2019-06-07 05:09:37 +00:00
|
|
|
if s.pause {
|
2019-07-28 20:59:51 +00:00
|
|
|
buffer.SetString(pauseText, ui.NewStyle(console.GetMenuColorReverse(), console.GetMenuColor()), image.Pt(s.Max.X-s.Dx()/2-len(pauseText)/2, s.Min.Y))
|
2019-06-07 05:09:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 00:08:36 +00:00
|
|
|
s.Block.Draw(buffer)
|
|
|
|
}
|
2019-06-07 05:09:37 +00:00
|
|
|
|
|
|
|
func (s *StatusBar) TogglePause() {
|
|
|
|
s.pause = !s.pause
|
|
|
|
}
|