From ac75e7e891244cbd8087ad517697830332ea8982 Mon Sep 17 00:00:00 2001 From: sqshq Date: Fri, 7 Jun 2019 01:09:37 -0400 Subject: [PATCH] pause function visualization and handling enhancements --- component/layout/layout.go | 4 +++- component/statusbar.go | 15 ++++++++++++++- console/signal.go | 20 +++++++++++--------- event/handler.go | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/component/layout/layout.go b/component/layout/layout.go index 02e67fb..2535d97 100644 --- a/component/layout/layout.go +++ b/component/layout/layout.go @@ -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 { diff --git a/component/statusbar.go b/component/statusbar.go index c983dc5..18c9d70 100644 --- a/component/statusbar.go +++ b/component/statusbar.go @@ -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 +} diff --git a/console/signal.go b/console/signal.go index b146df6..a7c0730 100644 --- a/console/signal.go +++ b/console/signal.go @@ -6,13 +6,15 @@ const ( ) const ( - KeyPause = "p" - KeyQuit = "q" - KeyExit = "" - KeyLeft = "" - KeyRight = "" - KeyUp = "" - KeyDown = "" - KeyEnter = "" - KeyEsc = "" + KeyPause1 = "p" + KeyPause2 = "P" + KeyQuit1 = "q" + KeyQuit2 = "Q" + KeyQuit3 = "" + KeyLeft = "" + KeyRight = "" + KeyUp = "" + KeyDown = "" + KeyEnter = "" + KeyEsc = "" ) diff --git a/event/handler.go b/event/handler.go index 44b7091..f658a56 100644 --- a/event/handler.go +++ b/event/handler.go @@ -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() }