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