Add new options in multiselect

This commit is contained in:
Martin
2024-06-11 21:48:13 +02:00
parent c660b6cbb1
commit 0d55a3b119
7 changed files with 811 additions and 65 deletions

View File

@ -7,6 +7,7 @@ import (
"tasksquire/common"
"time"
"tasksquire/components/input"
"tasksquire/taskwarrior"
"github.com/charmbracelet/bubbles/key"
@ -151,6 +152,10 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil, tea.Quit
}
return model, p.updateTasksCmd
case key.Matches(msg, p.common.Keymap.PrevPage):
return p, prevArea()
case key.Matches(msg, p.common.Keymap.NextPage):
return p, nextArea()
case key.Matches(msg, p.common.Keymap.Left):
return p, prevColumn()
case key.Matches(msg, p.common.Keymap.Right):
@ -192,6 +197,14 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch {
case key.Matches(msg, p.common.Keymap.Back):
model, cmd := p.areas[p.area].Update(msg)
p.areas[p.area] = model.(area)
if cmd != nil {
_, ok := cmd().(input.SuppressBackMsg)
if ok {
return p, nil
}
}
return p, changeMode(modeNormal)
case key.Matches(msg, p.common.Keymap.Prev):
if p.columnCursor == 0 {
@ -264,17 +277,33 @@ func (p *TaskEditorPage) View() string {
}
tabs := ""
for i, a := range p.areas {
if i == p.area {
tabs += p.common.Styles.Base.Bold(true).Render(fmt.Sprintf(" %s ", a.GetName()))
} else {
tabs += p.common.Styles.Base.Render(fmt.Sprintf(" %s ", a.GetName()))
}
}
page := lipgloss.JoinVertical(
lipgloss.Left,
tabs,
area,
)
// return lipgloss.Place(p.common.Width(), p.common.Height(), lipgloss.Center, lipgloss.Center, lipgloss.JoinHorizontal(
// lipgloss.Center,
// picker,
// area,
// ))
return lipgloss.Place(p.common.Width(), p.common.Height(), lipgloss.Center, lipgloss.Center, area)
return lipgloss.Place(p.common.Width(), p.common.Height(), lipgloss.Center, lipgloss.Center, page)
}
type area interface {
tea.Model
SetCursor(c int)
GetName() string
}
type areaPicker struct {
@ -493,6 +522,10 @@ func NewTaskEdit(com *common.Common, task *taskwarrior.Task) *taskEdit {
return &t
}
func (t *taskEdit) GetName() string {
return "Task"
}
func (t *taskEdit) SetCursor(c int) {
t.fields[t.cursor].Blur()
if c < 0 {
@ -565,8 +598,8 @@ func NewTagEdit(common *common.Common, selected *[]string, options []string) *ta
t := tagEdit{
common: common,
fields: []huh.Field{
huh.NewMultiSelect[string]().
Options(huh.NewOptions(options...)...).
input.NewMultiSelect(common).
Options(true, input.NewOptions(options...)...).
// Key("tags").
Title("Tags").
Value(selected).
@ -586,6 +619,10 @@ func NewTagEdit(common *common.Common, selected *[]string, options []string) *ta
return &t
}
func (t *tagEdit) GetName() string {
return "Tags"
}
func (t *tagEdit) SetCursor(c int) {
t.fields[t.cursor].Blur()
if c < 0 {
@ -683,6 +720,10 @@ func NewTimeEdit(common *common.Common, due *string, scheduled *string, wait *st
return &t
}
func (t *timeEdit) GetName() string {
return "Dates"
}
func (t *timeEdit) SetCursor(c int) {
t.fields[t.cursor].Blur()
if c < 0 {
@ -772,6 +813,10 @@ func NewDetailsEdit(com *common.Common, task *taskwarrior.Task) *detailsEdit {
return &d
}
func (d *detailsEdit) GetName() string {
return "Details"
}
func (d *detailsEdit) SetCursor(c int) {
}