clean up ui

This commit is contained in:
Kevin Schoon 2018-01-29 21:18:19 -05:00
parent d7863cb264
commit 479221cc00
1 changed files with 20 additions and 14 deletions

34
ui.go
View File

@ -5,36 +5,41 @@ import (
"github.com/gizak/termui" "github.com/gizak/termui"
) )
func status(runner *TaskRunner) termui.GridBufferer { func status(wheel *Wheel, runner *TaskRunner) termui.GridBufferer {
var text string var text string
switch runner.state { switch runner.state {
case RUNNING: case RUNNING:
text = fmt.Sprintf( text = fmt.Sprintf(
`%s remaining - [%d/%d] Pomodoros completed `[%d/%d] Pomodoros completed
%s %s remaining
[q] - quit [p] - pause [q] - quit [p] - pause
`, `,
runner.TimeRemaining(),
runner.count, runner.count,
runner.nPomodoros, runner.nPomodoros,
wheel,
runner.TimeRemaining(),
) )
case BREAKING: case BREAKING:
text = `It is time to take a break! text = `It is time to take a break!
Take a step back, reflect on your progress, or have a coffee. Once you a ready press [enter]
Once you a ready press [enter] to begin the next Pomodoro. to begin the next Pomodoro.
[q] - quit [p] - pause [q] - quit [p] - pause
` `
case PAUSED: case PAUSED:
text = `Pomo is suspended, this time does not count against your progress. text = `Pomo is suspended.
Press [p] to continue.
[q] - quit [p] - unpause [q] - quit [p] - unpause
` `
case COMPLETE: case COMPLETE:
text = `This session has concluded, press [q] to exit. If you are text = `This session has concluded.
going to continue working, consider taking an extended break
before starting again. Press [q] to exit.
[q] - quit [q] - quit
` `
@ -82,27 +87,28 @@ func startUI(runner *TaskRunner) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
wheel := Wheel(0)
defer termui.Close() defer termui.Close()
termui.Render(centered(status(runner))) termui.Render(centered(status(&wheel, runner)))
termui.Handle("/timer/1s", func(termui.Event) { termui.Handle("/timer/1s", func(termui.Event) {
termui.Render(centered(status(runner))) termui.Render(centered(status(&wheel, runner)))
}) })
termui.Handle("/sys/wnd/resize", func(termui.Event) { termui.Handle("/sys/wnd/resize", func(termui.Event) {
termui.Render(centered(status(runner))) termui.Render(centered(status(&wheel, runner)))
}) })
termui.Handle("/sys/kbd/<enter>", func(termui.Event) { termui.Handle("/sys/kbd/<enter>", func(termui.Event) {
runner.Toggle() runner.Toggle()
termui.Render(centered(status(runner))) termui.Render(centered(status(&wheel, runner)))
}) })
termui.Handle("/sys/kbd/p", func(termui.Event) { termui.Handle("/sys/kbd/p", func(termui.Event) {
runner.Pause() runner.Pause()
termui.Render(centered(status(runner))) termui.Render(centered(status(&wheel, runner)))
}) })
termui.Handle("/sys/kbd/q", func(termui.Event) { termui.Handle("/sys/kbd/q", func(termui.Event) {