2018-01-26 16:07:38 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2018-01-30 03:18:19 +01:00
|
|
|
func status(wheel *Wheel, runner *TaskRunner) termui.GridBufferer {
|
2018-01-27 16:58:56 +01:00
|
|
|
var text string
|
2018-01-26 16:07:38 +01:00
|
|
|
switch runner.state {
|
|
|
|
case RUNNING:
|
2018-01-27 16:58:56 +01:00
|
|
|
text = fmt.Sprintf(
|
2018-01-30 03:18:19 +01:00
|
|
|
`[%d/%d] Pomodoros completed
|
|
|
|
|
|
|
|
%s %s remaining
|
2018-01-27 17:22:41 +01:00
|
|
|
|
2018-01-30 04:00:41 +01:00
|
|
|
|
2018-01-27 17:22:41 +01:00
|
|
|
[q] - quit [p] - pause
|
|
|
|
`,
|
2018-01-26 16:07:38 +01:00
|
|
|
runner.count,
|
2018-01-27 16:58:56 +01:00
|
|
|
runner.nPomodoros,
|
2018-01-30 03:18:19 +01:00
|
|
|
wheel,
|
|
|
|
runner.TimeRemaining(),
|
2018-01-26 16:07:38 +01:00
|
|
|
)
|
|
|
|
case BREAKING:
|
2018-01-27 17:22:41 +01:00
|
|
|
text = `It is time to take a break!
|
|
|
|
|
2018-01-30 03:18:19 +01:00
|
|
|
Once you a ready press [enter]
|
|
|
|
to begin the next Pomodoro.
|
2018-01-27 17:22:41 +01:00
|
|
|
|
|
|
|
[q] - quit [p] - pause
|
|
|
|
`
|
2018-01-26 16:07:38 +01:00
|
|
|
case PAUSED:
|
2018-01-30 03:18:19 +01:00
|
|
|
text = `Pomo is suspended.
|
|
|
|
|
|
|
|
Press [p] to continue.
|
2018-01-27 17:22:41 +01:00
|
|
|
|
2018-01-30 04:00:41 +01:00
|
|
|
|
2018-01-27 17:22:41 +01:00
|
|
|
[q] - quit [p] - unpause
|
|
|
|
`
|
2018-01-26 16:07:38 +01:00
|
|
|
case COMPLETE:
|
2018-01-30 03:18:19 +01:00
|
|
|
text = `This session has concluded.
|
|
|
|
|
|
|
|
Press [q] to exit.
|
2018-01-27 17:22:41 +01:00
|
|
|
|
2018-01-30 04:00:41 +01:00
|
|
|
|
2018-01-27 17:22:41 +01:00
|
|
|
[q] - quit
|
|
|
|
`
|
2018-01-26 16:07:38 +01:00
|
|
|
}
|
2018-01-27 16:58:56 +01:00
|
|
|
par := termui.NewPar(text)
|
2018-01-27 17:22:41 +01:00
|
|
|
par.Height = 8
|
2018-01-26 16:07:38 +01:00
|
|
|
par.BorderLabel = fmt.Sprintf("Pomo - %s", runner.state)
|
|
|
|
par.BorderLabelFg = termui.ColorWhite
|
|
|
|
par.BorderFg = termui.ColorRed
|
|
|
|
if runner.state == RUNNING {
|
|
|
|
par.BorderFg = termui.ColorGreen
|
|
|
|
}
|
|
|
|
return par
|
|
|
|
}
|
|
|
|
|
2018-01-27 16:58:56 +01:00
|
|
|
func newBlk() termui.GridBufferer {
|
|
|
|
blk := termui.NewBlock()
|
|
|
|
blk.Height = termui.TermHeight() / 3
|
|
|
|
blk.Border = false
|
|
|
|
return blk
|
|
|
|
}
|
|
|
|
|
|
|
|
func centered(part termui.GridBufferer) *termui.Grid {
|
|
|
|
grid := termui.NewGrid(
|
|
|
|
termui.NewRow(
|
|
|
|
termui.NewCol(12, 0, newBlk()),
|
|
|
|
),
|
|
|
|
termui.NewRow(
|
|
|
|
termui.NewCol(3, 0, newBlk()),
|
|
|
|
termui.NewCol(6, 0, part),
|
|
|
|
termui.NewCol(3, 0, newBlk()),
|
|
|
|
),
|
|
|
|
termui.NewRow(
|
|
|
|
termui.NewCol(12, 0, newBlk()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
grid.BgColor = termui.ThemeAttr("bg")
|
|
|
|
grid.Width = termui.TermWidth()
|
|
|
|
grid.Align()
|
|
|
|
return grid
|
|
|
|
}
|
|
|
|
|
2018-01-26 16:07:38 +01:00
|
|
|
func startUI(runner *TaskRunner) {
|
|
|
|
err := termui.Init()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-01-30 03:18:19 +01:00
|
|
|
wheel := Wheel(0)
|
2018-01-26 16:07:38 +01:00
|
|
|
|
|
|
|
defer termui.Close()
|
|
|
|
|
2018-01-30 03:18:19 +01:00
|
|
|
termui.Render(centered(status(&wheel, runner)))
|
2018-01-27 16:58:56 +01:00
|
|
|
|
2018-01-26 16:07:38 +01:00
|
|
|
termui.Handle("/timer/1s", func(termui.Event) {
|
2018-01-30 03:18:19 +01:00
|
|
|
termui.Render(centered(status(&wheel, runner)))
|
2018-01-27 16:58:56 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
termui.Handle("/sys/wnd/resize", func(termui.Event) {
|
2018-01-30 03:18:19 +01:00
|
|
|
termui.Render(centered(status(&wheel, runner)))
|
2018-01-26 16:07:38 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
termui.Handle("/sys/kbd/<enter>", func(termui.Event) {
|
|
|
|
runner.Toggle()
|
2018-01-30 03:18:19 +01:00
|
|
|
termui.Render(centered(status(&wheel, runner)))
|
2018-01-26 16:07:38 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
termui.Handle("/sys/kbd/p", func(termui.Event) {
|
|
|
|
runner.Pause()
|
2018-01-30 03:18:19 +01:00
|
|
|
termui.Render(centered(status(&wheel, runner)))
|
2018-01-26 16:07:38 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
|
|
|
termui.StopLoop()
|
|
|
|
})
|
|
|
|
|
|
|
|
termui.Loop()
|
|
|
|
}
|