added pause mode

This commit is contained in:
sqshq 2019-03-02 20:04:02 -05:00
parent ce08f19c53
commit 72e0f0d5e3
2 changed files with 24 additions and 12 deletions

View File

@ -23,11 +23,12 @@ type Mode rune
const ( const (
ModeDefault Mode = 0 ModeDefault Mode = 0
ModeComponentSelect Mode = 1 ModePause Mode = 1
ModeMenuOptionSelect Mode = 2 ModeComponentSelect Mode = 2
ModeComponentMove Mode = 3 ModeMenuOptionSelect Mode = 3
ModeComponentResize Mode = 4 ModeComponentMove Mode = 4
ModeChartPinpoint Mode = 5 ModeComponentResize Mode = 5
ModeChartPinpoint Mode = 6
) )
const ( const (
@ -78,6 +79,17 @@ func (l *Layout) changeMode(m Mode) {
func (l *Layout) HandleConsoleEvent(e string) { func (l *Layout) HandleConsoleEvent(e string) {
switch e { switch e {
case console.KeyPause:
if l.mode == ModePause {
l.changeMode(ModeDefault)
} else {
if l.getSelectedComponent().Type == config.TypeRunChart {
chart := l.getSelectedComponent().Drawable.(*runchart.RunChart)
chart.DisableSelection()
}
l.menu.idle()
l.changeMode(ModePause)
}
case console.KeyEnter: case console.KeyEnter:
switch l.mode { switch l.mode {
case ModeComponentSelect: case ModeComponentSelect:
@ -270,6 +282,6 @@ func (l *Layout) Draw(buffer *ui.Buffer) {
0, l.GetRect().Dy()-statusbarHeight, 0, l.GetRect().Dy()-statusbarHeight,
l.GetRect().Dx(), l.GetRect().Dy()) l.GetRect().Dx(), l.GetRect().Dy())
l.menu.Draw(buffer)
l.statusbar.Draw(buffer) l.statusbar.Draw(buffer)
l.menu.Draw(buffer)
} }

View File

@ -33,7 +33,6 @@ func (h *Handler) HandleEvents() {
// initial render // initial render
ui.Render(h.layout) ui.Render(h.layout)
pause := false
for { for {
select { select {
@ -46,8 +45,6 @@ func (h *Handler) HandleEvents() {
case console.KeyQuit, console.KeyExit: case console.KeyQuit, console.KeyExit:
h.handleExit() h.handleExit()
return return
case console.KeyPause:
pause = !pause // TODO move to layout, since it will show PAUSE sign in status line, pause/unpause can be sent via channel
case console.SignalResize: case console.SignalResize:
payload := e.Payload.(ui.Resize) payload := e.Payload.(ui.Resize)
h.layout.ChangeDimensions(payload.Width, payload.Height) h.layout.ChangeDimensions(payload.Width, payload.Height)
@ -60,13 +57,16 @@ func (h *Handler) HandleEvents() {
func (h *Handler) handleModeChange(m component.Mode) { func (h *Handler) handleModeChange(m component.Mode) {
// render change before switching the tickers // render the change before switching the tickers
ui.Render(h.layout) ui.Render(h.layout)
h.renderTicker.Stop() h.renderTicker.Stop()
if m == component.ModeDefault { switch m {
case component.ModeDefault:
h.renderTicker = time.NewTicker(h.renderRate) h.renderTicker = time.NewTicker(h.renderRate)
} else { case component.ModePause:
// proceed with stopped timer
default:
h.renderTicker = time.NewTicker(console.MinRenderInterval) h.renderTicker = time.NewTicker(console.MinRenderInterval)
} }
} }