Fix pickers; Add new select option

This commit is contained in:
Martin
2024-06-24 16:36:11 +02:00
parent fac7ff81dd
commit 73d51b956a
8 changed files with 715 additions and 31 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
)
type ReportPickerPage struct {
@ -38,17 +39,32 @@ func NewReportPickerPage(common *common.Common, activeReport *taskwarrior.Report
Options(huh.NewOptions(options...)...).
Title("Reports").
Description("Choose a report").
Value(&selected),
Value(&selected).
WithTheme(common.Styles.Form),
),
).
WithShowHelp(false).
WithShowErrors(false)
p.SetSize(common.Width(), common.Height())
return p
}
func (p *ReportPickerPage) SetSize(width, height int) {
p.common.SetSize(width, height)
if width >= 20 {
p.form = p.form.WithWidth(20)
} else {
p.form = p.form.WithWidth(width)
}
if height >= 30 {
p.form = p.form.WithHeight(30)
} else {
p.form = p.form.WithHeight(height)
}
}
func (p *ReportPickerPage) Init() tea.Cmd {
@ -93,7 +109,13 @@ func (p *ReportPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
func (p *ReportPickerPage) View() string {
return p.common.Styles.Base.Render(p.form.View())
return lipgloss.Place(
p.common.Width(),
p.common.Height(),
lipgloss.Center,
lipgloss.Center,
p.common.Styles.Base.Render(p.form.View()),
)
}
func (p *ReportPickerPage) updateReportCmd() tea.Msg {