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 (
ModeDefault Mode = 0
ModeComponentSelect Mode = 1
ModeMenuOptionSelect Mode = 2
ModeComponentMove Mode = 3
ModeComponentResize Mode = 4
ModeChartPinpoint Mode = 5
ModePause Mode = 1
ModeComponentSelect Mode = 2
ModeMenuOptionSelect Mode = 3
ModeComponentMove Mode = 4
ModeComponentResize Mode = 5
ModeChartPinpoint Mode = 6
)
const (
@ -78,6 +79,17 @@ func (l *Layout) changeMode(m Mode) {
func (l *Layout) HandleConsoleEvent(e string) {
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:
switch l.mode {
case ModeComponentSelect:
@ -270,6 +282,6 @@ func (l *Layout) Draw(buffer *ui.Buffer) {
0, l.GetRect().Dy()-statusbarHeight,
l.GetRect().Dx(), l.GetRect().Dy())
l.menu.Draw(buffer)
l.statusbar.Draw(buffer)
l.menu.Draw(buffer)
}

View File

@ -33,7 +33,6 @@ func (h *Handler) HandleEvents() {
// initial render
ui.Render(h.layout)
pause := false
for {
select {
@ -46,8 +45,6 @@ func (h *Handler) HandleEvents() {
case console.KeyQuit, console.KeyExit:
h.handleExit()
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:
payload := e.Payload.(ui.Resize)
h.layout.ChangeDimensions(payload.Width, payload.Height)
@ -60,13 +57,16 @@ func (h *Handler) HandleEvents() {
func (h *Handler) handleModeChange(m component.Mode) {
// render change before switching the tickers
// render the change before switching the tickers
ui.Render(h.layout)
h.renderTicker.Stop()
if m == component.ModeDefault {
switch m {
case component.ModeDefault:
h.renderTicker = time.NewTicker(h.renderRate)
} else {
case component.ModePause:
// proceed with stopped timer
default:
h.renderTicker = time.NewTicker(console.MinRenderInterval)
}
}