added status bar
This commit is contained in:
parent
8790d2f966
commit
68acb63715
|
@ -11,8 +11,9 @@ type Layout struct {
|
|||
ui.Block
|
||||
Components []Component
|
||||
ChangeModeEvents chan Mode
|
||||
mode Mode
|
||||
statusbar *StatusBar
|
||||
menu *Menu
|
||||
mode Mode
|
||||
selection int
|
||||
}
|
||||
|
||||
|
@ -32,14 +33,16 @@ const (
|
|||
rowsCount = 30
|
||||
)
|
||||
|
||||
func NewLayout(width, height int, menu *Menu) *Layout {
|
||||
func NewLayout(width, height int, statusline *StatusBar, menu *Menu) *Layout {
|
||||
|
||||
block := *ui.NewBlock()
|
||||
block.SetRect(0, 0, width, height)
|
||||
statusline.SetRect(0, height-1, width, height)
|
||||
|
||||
return &Layout{
|
||||
Block: block,
|
||||
Components: make([]Component, 0),
|
||||
statusbar: statusline,
|
||||
menu: menu,
|
||||
mode: ModeDefault,
|
||||
selection: 0,
|
||||
|
@ -191,6 +194,7 @@ func (l *Layout) HandleConsoleEvent(e string) {
|
|||
|
||||
func (l *Layout) ChangeDimensions(width, height int) {
|
||||
l.SetRect(0, 0, width, height)
|
||||
l.statusbar.SetRect(0, height-1, width, height)
|
||||
}
|
||||
|
||||
// TODO func to get prev/next component navigating left/right/top/bottom
|
||||
|
@ -219,4 +223,5 @@ func (l *Layout) Draw(buffer *ui.Buffer) {
|
|||
}
|
||||
|
||||
l.menu.Draw(buffer)
|
||||
l.statusbar.Draw(buffer)
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ func (m *Menu) renderHighlight(buffer *ui.Buffer) {
|
|||
|
||||
arrowsText := "Use arrows for selection"
|
||||
arrowsTextPoint := getMiddlePoint(m.Block, arrowsText, 2)
|
||||
if arrowsTextPoint.In(m.Rectangle) {
|
||||
if arrowsTextPoint.Y+1 < m.Inner.Max.Y {
|
||||
buffer.SetString(
|
||||
arrowsText,
|
||||
ui.NewStyle(console.ColorDarkGrey),
|
||||
|
@ -129,7 +129,7 @@ func (m *Menu) renderHighlight(buffer *ui.Buffer) {
|
|||
|
||||
optionsText := "<ENTER> to view options"
|
||||
optionsTextPoint := getMiddlePoint(m.Block, optionsText, 3)
|
||||
if optionsTextPoint.In(m.Rectangle) {
|
||||
if optionsTextPoint.Y+1 < m.Inner.Max.Y {
|
||||
buffer.SetString(
|
||||
optionsText,
|
||||
ui.NewStyle(console.ColorDarkGrey),
|
||||
|
@ -139,7 +139,7 @@ func (m *Menu) renderHighlight(buffer *ui.Buffer) {
|
|||
|
||||
resumeText := "<ESC> to resume"
|
||||
resumeTextPoint := getMiddlePoint(m.Block, resumeText, 4)
|
||||
if resumeTextPoint.In(m.Rectangle) {
|
||||
if resumeTextPoint.Y+1 < m.Inner.Max.Y {
|
||||
buffer.SetString(
|
||||
resumeText,
|
||||
ui.NewStyle(console.ColorDarkGrey),
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package component
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sqshq/sampler/console"
|
||||
ui "github.com/sqshq/termui"
|
||||
"image"
|
||||
)
|
||||
|
||||
const (
|
||||
bindingsIndent = 4
|
||||
)
|
||||
|
||||
type StatusBar struct {
|
||||
ui.Block
|
||||
keyBindings []string
|
||||
configFileName string
|
||||
}
|
||||
|
||||
func NewStatusLine(configFileName string) *StatusBar {
|
||||
block := *ui.NewBlock()
|
||||
block.Border = false
|
||||
return &StatusBar{
|
||||
Block: block,
|
||||
configFileName: configFileName,
|
||||
keyBindings: []string{
|
||||
"(Q) quit",
|
||||
"(P) pause",
|
||||
"(<->) selection",
|
||||
"(ESC) reset alarm",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StatusBar) Draw(buffer *ui.Buffer) {
|
||||
buffer.Fill(ui.NewCell(' ', ui.NewStyle(console.ColorClear, console.MenuColorBackground)), s.GetRect())
|
||||
buffer.SetString(fmt.Sprintf(" %s %s @ %s", console.AppTitle, console.AppVersion, s.configFileName), ui.NewStyle(console.MenuColorText, console.MenuColorBackground), s.Min)
|
||||
|
||||
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)
|
||||
}
|
|
@ -18,6 +18,11 @@ type Config struct {
|
|||
AsciiBoxes []AsciiBoxConfig `yaml:"asciiboxes,omitempty"`
|
||||
}
|
||||
|
||||
type Flags struct {
|
||||
ConfigFileName string
|
||||
Variables map[string]string
|
||||
}
|
||||
|
||||
type ComponentConfig struct {
|
||||
Title string `yaml:"title"`
|
||||
RefreshRateMs *int `yaml:"refresh-rate-ms,omitempty"`
|
||||
|
@ -75,7 +80,7 @@ type ComponentSettings struct {
|
|||
Position Position
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
func Load() (Config, Flags) {
|
||||
|
||||
if len(os.Args) < 2 {
|
||||
println("Please specify config file location. See www.github.com/sqshq/sampler for the reference")
|
||||
|
@ -86,7 +91,9 @@ func Load() *Config {
|
|||
cfg.validate()
|
||||
cfg.setDefaults()
|
||||
|
||||
return cfg
|
||||
flg := Flags{ConfigFileName: os.Args[1]}
|
||||
|
||||
return *cfg, flg
|
||||
}
|
||||
|
||||
func Update(settings []ComponentSettings) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
defaultRefreshRateMs = 200
|
||||
defaultRefreshRateMs = 1000
|
||||
defaultScale = 1
|
||||
defaultTheme = console.ThemeDark
|
||||
)
|
||||
|
|
|
@ -11,6 +11,7 @@ const (
|
|||
MaxRenderInterval = 1000 * time.Millisecond
|
||||
MinRenderInterval = 100 * time.Millisecond
|
||||
AppTitle = "sampler"
|
||||
AppVersion = "0.1.0"
|
||||
)
|
||||
|
||||
type Console struct{}
|
||||
|
|
|
@ -21,8 +21,15 @@ const (
|
|||
ColorPurple ui.Color = 129
|
||||
ColorGreen ui.Color = 64
|
||||
ColorDarkGrey ui.Color = 240
|
||||
ColorWhite ui.Color = 7
|
||||
ColorGrey ui.Color = 242
|
||||
ColorWhite ui.Color = 15
|
||||
ColorBlack ui.Color = 0
|
||||
ColorClear ui.Color = -1
|
||||
)
|
||||
|
||||
const (
|
||||
MenuColorBackground ui.Color = 236
|
||||
MenuColorText ui.Color = 255
|
||||
)
|
||||
|
||||
type Palette struct {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
refreshRateToRenderRateRatio = 0.6
|
||||
refreshRateToRenderRateRatio = 0.3
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
|
|
5
main.go
5
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/sqshq/sampler/asset"
|
||||
"github.com/sqshq/sampler/component"
|
||||
"github.com/sqshq/sampler/component/asciibox"
|
||||
"github.com/sqshq/sampler/component/barchart"
|
||||
|
@ -15,13 +14,13 @@ import (
|
|||
|
||||
func main() {
|
||||
|
||||
cfg := config.Load()
|
||||
cfg, flg := config.Load()
|
||||
csl := console.Console{}
|
||||
csl.Init()
|
||||
defer csl.Close()
|
||||
|
||||
width, height := ui.TerminalDimensions()
|
||||
layout := component.NewLayout(width, height, component.NewMenu())
|
||||
layout := component.NewLayout(width, height, component.NewStatusLine(flg.ConfigFileName), component.NewMenu())
|
||||
|
||||
for _, c := range cfg.RunCharts {
|
||||
|
||||
|
|
Loading…
Reference in New Issue