pause function visualization and handling enhancements

This commit is contained in:
sqshq 2019-06-07 01:09:37 -04:00
parent a9fd652eb7
commit ac75e7e891
4 changed files with 29 additions and 12 deletions

View File

@ -98,15 +98,17 @@ func (l *Layout) HandleKeyboardEvent(e string) {
selected := l.getSelection()
switch e {
case console.KeyPause:
case console.KeyPause1, console.KeyPause2:
if l.mode == ModePause {
l.changeMode(ModeDefault)
l.statusbar.TogglePause()
} else {
if selected.Type == config.TypeRunChart {
selected.CommandChannel <- &data.Command{Type: runchart.CommandDisableSelection}
}
l.menu.Idle()
l.changeMode(ModePause)
l.statusbar.TogglePause()
}
case console.KeyEnter:
switch l.mode {

View File

@ -9,13 +9,15 @@ import (
)
const (
bindingsIndent = 4
bindingsIndent = 3
pauseText = " P A U S E D "
)
type StatusBar struct {
*ui.Block
keyBindings []string
text string
pause bool
}
func NewStatusLine(configFileName string, palette console.Palette, license *metadata.License) *StatusBar {
@ -28,6 +30,9 @@ func NewStatusLine(configFileName string, palette console.Palette, license *meta
text += console.AppLicenseWarning
} else if license.Username != nil {
text += fmt.Sprintf("%s | licensed to %s", configFileName, *license.Username)
if license.Company != nil {
text += fmt.Sprintf(", %s", *license.Company)
}
} else {
text += fmt.Sprintf("%s | licensed to %s", configFileName, *license.Company)
}
@ -55,5 +60,13 @@ func (s *StatusBar) Draw(buffer *ui.Buffer) {
indent += bindingsIndent + len(binding)
}
if s.pause {
buffer.SetString(pauseText, ui.NewStyle(console.MenuColorBackground, console.MenuColorText), image.Pt(s.Max.X-s.Dx()/2-len(pauseText)/2, s.Min.Y))
}
s.Block.Draw(buffer)
}
func (s *StatusBar) TogglePause() {
s.pause = !s.pause
}

View File

@ -6,9 +6,11 @@ const (
)
const (
KeyPause = "p"
KeyQuit = "q"
KeyExit = "<C-c>"
KeyPause1 = "p"
KeyPause2 = "P"
KeyQuit1 = "q"
KeyQuit2 = "Q"
KeyQuit3 = "<C-c>"
KeyLeft = "<Left>"
KeyRight = "<Right>"
KeyUp = "<Up>"

View File

@ -47,7 +47,7 @@ func (h *Handler) HandleEvents() {
case console.SignalClick:
payload := e.Payload.(ui.Mouse)
h.layout.HandleMouseClick(payload.X, payload.Y)
case console.KeyQuit, console.KeyExit:
case console.KeyQuit1, console.KeyQuit2, console.KeyQuit3:
if h.layout.WerePositionsChanged() {
h.updateConfigFile()
}