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

View File

@ -1,12 +1,14 @@
package command package command
import ( import (
"sort"
"strings" "strings"
"ewintr.nl/gte/cmd/cli/format" "ewintr.nl/gte/cmd/cli/format"
"ewintr.nl/gte/internal/configuration" "ewintr.nl/gte/internal/configuration"
"ewintr.nl/gte/internal/process" "ewintr.nl/gte/internal/process"
"ewintr.nl/gte/internal/storage" "ewintr.nl/gte/internal/storage"
"ewintr.nl/gte/internal/task"
) )
type Project struct { type Project struct {
@ -38,5 +40,8 @@ func (p *Project) Do() string {
return format.FormatError(err) 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" return "no projects here\n\n"
} }
var out string var data [][]string
for _, project := range projects { for _, project := range projects {
if project != "" { 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 package command
import ( import (
"sort"
"ewintr.nl/gte/cmd/cli/format" "ewintr.nl/gte/cmd/cli/format"
"ewintr.nl/gte/internal/configuration" "ewintr.nl/gte/internal/configuration"
"ewintr.nl/gte/internal/process" "ewintr.nl/gte/internal/process"
@ -34,5 +36,7 @@ func (w *Week) Do() string {
return format.FormatError(err) return format.FormatError(err)
} }
sort.Sort(task.ByDefault(res.Tasks))
return format.FormatTaskTable(res.Tasks, format.COL_ALL) return format.FormatTaskTable(res.Tasks, format.COL_ALL)
} }

View File

@ -17,13 +17,13 @@ type Column int
const ( const (
COL_ID Column = iota COL_ID Column = iota
COL_STATUS COL_STATUS
COL_DATE COL_DUE
COL_ACTION COL_ACTION
COL_PROJECT COL_PROJECT
) )
var ( 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 { func FormatError(err error) string {
@ -44,14 +44,21 @@ func FormatTaskTable(tasks []*task.LocalTask, cols []Column) string {
line = append(line, fmt.Sprintf("%d", t.LocalId)) line = append(line, fmt.Sprintf("%d", t.LocalId))
case COL_STATUS: case COL_STATUS:
var updated []string var updated []string
if t.IsRecurrer() {
updated = append(updated, "r")
}
if t.LocalStatus == task.STATUS_UPDATED { if t.LocalStatus == task.STATUS_UPDATED {
updated = append(updated, "u") updated = append(updated, "u")
} }
if !t.Due.IsZero() && task.Today.After(t.Due) { if !t.Due.IsZero() && task.Today.After(t.Due) {
updated = append(updated, "o") updated = append(updated, "o")
} }
line = append(line, strings.Join(updated, "")) 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()) line = append(line, t.Due.Human())
case COL_ACTION: case COL_ACTION:
line = append(line, t.Action) line = append(line, t.Action)

View File

@ -189,7 +189,6 @@ func (d Date) Human() string {
return "-" return "-"
} }
fmt.Println(Today.String(), d.String())
if Today.Add(7).After(d) { if Today.Add(7).After(d) {
return strings.ToLower(d.t.Format("Monday")) 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) Len() int { return len(lt) }
func (lt ByDefault) Swap(i, j int) { lt[i], lt[j] = lt[j], lt[i] } func (lt ByDefault) Swap(i, j int) { lt[i], lt[j] = lt[j], lt[i] }
func (lt ByDefault) Less(i, j int) bool { 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) { if !lt[j].Due.Equal(lt[i].Due) {
return lt[j].Due.After(lt[i].Due) return lt[j].Due.After(lt[i].Due)
} }