output remaining commands with table

This commit is contained in:
Erik Winter 2022-06-05 15:00:28 +02:00
parent e5f76c840e
commit 70829d898a
7 changed files with 30 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package command
import (
"sort"
"strings"
"ewintr.nl/gte/cmd/cli/format"
@ -51,5 +52,7 @@ func (f *Folder) Do() string {
return format.FormatError(err)
}
sort.Sort(task.ByDefault(res.Tasks))
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
}

View File

@ -1,12 +1,14 @@
package command
import (
"sort"
"strings"
"ewintr.nl/gte/cmd/cli/format"
"ewintr.nl/gte/internal/configuration"
"ewintr.nl/gte/internal/process"
"ewintr.nl/gte/internal/storage"
"ewintr.nl/gte/internal/task"
)
type Project struct {
@ -38,5 +40,8 @@ func (p *Project) Do() string {
return format.FormatError(err)
}
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
sort.Sort(task.ByDefault(res.Tasks))
cols := []format.Column{format.COL_ID, format.COL_STATUS, format.COL_DUE, format.COL_ACTION}
return format.FormatTaskTable(res.Tasks, cols)
}

View File

@ -38,12 +38,12 @@ func (p *Projects) Do() string {
return "no projects here\n\n"
}
var out string
var data [][]string
for _, project := range projects {
if project != "" {
out += fmt.Sprintf("%s\n", project)
data = append(data, []string{project})
}
}
return fmt.Sprintf("%s\n", out)
return fmt.Sprintf("%s", format.FormatTable(data))
}

View File

@ -1,6 +1,8 @@
package command
import (
"sort"
"ewintr.nl/gte/cmd/cli/format"
"ewintr.nl/gte/internal/configuration"
"ewintr.nl/gte/internal/process"
@ -34,5 +36,7 @@ func (w *Week) Do() string {
return format.FormatError(err)
}
sort.Sort(task.ByDefault(res.Tasks))
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
}

View File

@ -17,13 +17,13 @@ type Column int
const (
COL_ID Column = iota
COL_STATUS
COL_DATE
COL_DUE
COL_ACTION
COL_PROJECT
)
var (
COL_ALL = []Column{COL_ID, COL_STATUS, COL_DATE, COL_ACTION, COL_PROJECT}
COL_ALL = []Column{COL_ID, COL_STATUS, COL_DUE, COL_ACTION, COL_PROJECT}
)
func FormatError(err error) string {
@ -44,6 +44,9 @@ func FormatTaskTable(tasks []*task.LocalTask, cols []Column) string {
line = append(line, fmt.Sprintf("%d", t.LocalId))
case COL_STATUS:
var updated []string
if t.IsRecurrer() {
updated = append(updated, "r")
}
if t.LocalStatus == task.STATUS_UPDATED {
updated = append(updated, "u")
}
@ -51,7 +54,11 @@ func FormatTaskTable(tasks []*task.LocalTask, cols []Column) string {
updated = append(updated, "o")
}
line = append(line, strings.Join(updated, " "))
case COL_DATE:
case COL_DUE:
if t.Due.IsZero() {
line = append(line, "")
continue
}
line = append(line, t.Due.Human())
case COL_ACTION:
line = append(line, t.Action)

View File

@ -189,7 +189,6 @@ func (d Date) Human() string {
return "-"
}
fmt.Println(Today.String(), d.String())
if Today.Add(7).After(d) {
return strings.ToLower(d.t.Format("Monday"))
}

View File

@ -77,6 +77,9 @@ type ByDefault []*LocalTask
func (lt ByDefault) Len() int { return len(lt) }
func (lt ByDefault) Swap(i, j int) { lt[i], lt[j] = lt[j], lt[i] }
func (lt ByDefault) Less(i, j int) bool {
if lt[i].IsRecurrer() != lt[j].IsRecurrer() {
return lt[i].IsRecurrer()
}
if !lt[j].Due.Equal(lt[i].Due) {
return lt[j].Due.After(lt[i].Due)
}