Add time page

This commit is contained in:
Martin
2026-02-01 21:30:19 +01:00
committed by Martin Pander
parent effd95f6c1
commit 681ed7e635
12 changed files with 915 additions and 115 deletions

View File

@ -26,25 +26,30 @@ func NewContextPickerPage(common *common.Common) *ContextPickerPage {
}
selected := common.TW.GetActiveContext().Name
options := make([]string, 0)
for _, c := range p.contexts {
if c.Name != "none" {
options = append(options, c.Name)
itemProvider := func() []list.Item {
contexts := common.TW.GetContexts()
options := make([]string, 0)
for _, c := range contexts {
if c.Name != "none" {
options = append(options, c.Name)
}
}
}
slices.Sort(options)
options = append([]string{"(none)"}, options...)
slices.Sort(options)
options = append([]string{"(none)"}, options...)
items := []list.Item{}
for _, opt := range options {
items = append(items, picker.NewItem(opt))
items := []list.Item{}
for _, opt := range options {
items = append(items, picker.NewItem(opt))
}
return items
}
onSelect := func(item list.Item) tea.Cmd {
return func() tea.Msg { return contextSelectedMsg{item: item} }
}
p.picker = picker.New(common, "Contexts", items, onSelect)
p.picker = picker.New(common, "Contexts", itemProvider, onSelect)
// Set active context
if selected == "" {
@ -87,7 +92,7 @@ func (p *ContextPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.WindowSizeMsg:
p.SetSize(msg.Width, msg.Height)
case contextSelectedMsg:
name := msg.item.(picker.Item).Title()
name := msg.item.FilterValue() // Use FilterValue (which is the name/text)
if name == "(none)" {
name = ""
}
@ -101,14 +106,16 @@ func (p *ContextPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return model, func() tea.Msg { return UpdateContextMsg(ctx) }
case tea.KeyMsg:
switch {
case key.Matches(msg, p.common.Keymap.Back):
model, err := p.common.PopPage()
if err != nil {
slog.Error("page stack empty")
return nil, tea.Quit
if !p.picker.IsFiltering() {
switch {
case key.Matches(msg, p.common.Keymap.Back):
model, err := p.common.PopPage()
if err != nil {
slog.Error("page stack empty")
return nil, tea.Quit
}
return model, BackCmd
}
return model, BackCmd
}
}
@ -134,4 +141,4 @@ func (p *ContextPickerPage) View() string {
)
}
type UpdateContextMsg *taskwarrior.Context
type UpdateContextMsg *taskwarrior.Context