Style forms; [WIP] Draw table
This commit is contained in:
@ -35,9 +35,12 @@ func NewContextPickerPage(common *common.Common) *ContextPickerPage {
|
||||
selected := common.TW.GetActiveContext().Name
|
||||
options := make([]string, 0)
|
||||
for _, c := range p.contexts {
|
||||
options = append(options, c.Name)
|
||||
if c.Name != "none" {
|
||||
options = append(options, c.Name)
|
||||
}
|
||||
}
|
||||
slices.Sort(options)
|
||||
options = append([]string{"(none)"}, options...)
|
||||
|
||||
p.form = huh.NewForm(
|
||||
huh.NewGroup(
|
||||
@ -50,7 +53,8 @@ func NewContextPickerPage(common *common.Common) *ContextPickerPage {
|
||||
),
|
||||
).
|
||||
WithShowHelp(false).
|
||||
WithShowErrors(true)
|
||||
WithShowErrors(true).
|
||||
WithTheme(p.common.Styles.Form)
|
||||
|
||||
return p
|
||||
}
|
||||
@ -99,7 +103,11 @@ func (p *ContextPickerPage) View() string {
|
||||
}
|
||||
|
||||
func (p *ContextPickerPage) updateContextCmd() tea.Msg {
|
||||
return UpdateContextMsg(p.common.TW.GetContext(p.form.GetString("context")))
|
||||
context := p.form.GetString("context")
|
||||
if context == "(none)" {
|
||||
context = "none"
|
||||
}
|
||||
return UpdateContextMsg(p.common.TW.GetContext(context))
|
||||
}
|
||||
|
||||
type UpdateContextMsg *taskwarrior.Context
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"tasksquire/common"
|
||||
"tasksquire/taskwarrior"
|
||||
|
||||
@ -43,13 +40,12 @@ func NewReportPage(com *common.Common, report *taskwarrior.Report) *ReportPage {
|
||||
s := table.DefaultStyles()
|
||||
s.Header = s.Header.
|
||||
BorderStyle(lipgloss.NormalBorder()).
|
||||
BorderForeground(lipgloss.Color("240")).
|
||||
BorderForeground(com.Styles.Active.GetForeground()).
|
||||
BorderBottom(true).
|
||||
Bold(false)
|
||||
Bold(true)
|
||||
s.Selected = s.Selected.
|
||||
Foreground(lipgloss.Color("229")).
|
||||
Background(lipgloss.Color("57")).
|
||||
Bold(false)
|
||||
Reverse(true).
|
||||
Bold(true)
|
||||
|
||||
keys := ReportKeys{
|
||||
Quit: key.NewBinding(
|
||||
@ -91,6 +87,9 @@ func (p ReportPage) Init() tea.Cmd {
|
||||
func (p ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmds []tea.Cmd
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
p.taskTable.SetWidth(msg.Width - 2)
|
||||
p.taskTable.SetHeight(msg.Height - 4)
|
||||
case BackMsg:
|
||||
p.subpageActive = false
|
||||
case TaskMsg:
|
||||
@ -107,9 +106,6 @@ func (p ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
cmds = append(cmds, p.getTasks())
|
||||
case AddedTaskMsg:
|
||||
cmds = append(cmds, p.getTasks())
|
||||
case tea.WindowSizeMsg:
|
||||
p.taskTable.SetWidth(msg.Width - 2)
|
||||
p.taskTable.SetHeight(msg.Height - 4)
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, p.common.Keymap.Quit):
|
||||
@ -157,24 +153,39 @@ func (p ReportPage) View() string {
|
||||
}
|
||||
|
||||
func (p *ReportPage) populateTaskTable(tasks []*taskwarrior.Task) {
|
||||
columns := []table.Column{
|
||||
{Title: "ID", Width: 4},
|
||||
{Title: "Project", Width: 10},
|
||||
{Title: "Tags", Width: 10},
|
||||
{Title: "Prio", Width: 2},
|
||||
{Title: "Due", Width: 10},
|
||||
{Title: "Task", Width: 50},
|
||||
nCols := len(p.activeReport.Columns)
|
||||
columns := make([]table.Column, 0)
|
||||
columnSizes := make([]int, nCols)
|
||||
fullRows := make([]table.Row, len(tasks))
|
||||
rows := make([]table.Row, len(tasks))
|
||||
|
||||
for i, task := range tasks {
|
||||
row := table.Row{}
|
||||
for i, col := range p.activeReport.Columns {
|
||||
field := task.Get(col)
|
||||
columnSizes[i] = max(columnSizes[i], len(field))
|
||||
row = append(row, field)
|
||||
}
|
||||
fullRows[i] = row
|
||||
}
|
||||
var rows []table.Row
|
||||
for _, task := range tasks {
|
||||
rows = append(rows, table.Row{
|
||||
strconv.FormatInt(task.Id, 10),
|
||||
task.Project,
|
||||
strings.Join(task.Tags, ", "),
|
||||
task.Priority,
|
||||
task.Due,
|
||||
task.Description,
|
||||
})
|
||||
|
||||
for i, r := range fullRows {
|
||||
row := table.Row{}
|
||||
for j, size := range columnSizes {
|
||||
if size == 0 {
|
||||
continue
|
||||
}
|
||||
row = append(row, r[j])
|
||||
}
|
||||
rows[i] = row
|
||||
}
|
||||
|
||||
for i, label := range p.activeReport.Labels {
|
||||
if columnSizes[i] == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
columns = append(columns, table.Column{Title: label, Width: max(columnSizes[i], len(label))})
|
||||
}
|
||||
|
||||
p.taskTable = table.New(
|
||||
|
||||
@ -85,7 +85,8 @@ func NewTaskEditorPage(common *common.Common, task taskwarrior.Task) *TaskEditor
|
||||
),
|
||||
).
|
||||
WithShowHelp(false).
|
||||
WithShowErrors(false)
|
||||
WithShowErrors(false).
|
||||
WithTheme(p.common.Styles.Form)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user