pominal/ui.go
Dan Anglin 0a2b9c483e
fix: limit the height and width of flex
This commit fixes the issue where the app was using
the full height of the terminal screen.

The fix include setting the 'fullscreen' boolean to
false and explicity defining the size using SetRect.
2020-01-20 20:29:45 +00:00

60 lines
1.6 KiB
Go

/*
Pominal
Copyright (C) 2019 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, 20)
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()
fmt.Fprintf(t, "\nTime remaining:\n%02d:%02d", int(countdown)/60, int(countdown)%60)
}