pominal/ui.go

62 lines
1.7 KiB
Go

/*
Pominal
Copyright (C) 2020 Daniel Anglin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"fmt"
"github.com/rivo/tview"
)
func newInfoUI() *tview.TextView {
i := tview.NewTextView()
i.SetBorder(true)
i.SetTitle(" Pominal ")
i.SetTitleAlign(tview.AlignLeft)
return i
}
func newTimerUI(app *tview.Application) *tview.TextView {
t := tview.NewTextView().SetTextAlign(tview.AlignCenter).SetChangedFunc(func() {
app.Draw()
})
t.SetBorder(true)
return t
}
func newFlex(info, timer *tview.TextView) *tview.Flex {
f := tview.NewFlex().AddItem(info, 30, 1, false).AddItem(timer, 50, 1, false)
f.SetRect(0, 0, 80, 8)
return f
}
func drawInfo(t *tview.TextView, pominalCycle, workSessions, maxWorkSessions int, label string) {
t.Clear()
fmt.Fprintf(t, "\nPominal cycle: %d\nWork session: %d of %d\nSession: %s", pominalCycle, workSessions, maxWorkSessions, label)
}
func drawTimer(t *tview.TextView, countdown float64) {
t.Clear()
secondsPerMinute := 60
fmt.Fprintf(t, "\nTime remaining:\n%02d:%02d", int(countdown)/secondsPerMinute, int(countdown)%secondsPerMinute)
}