cloumns today, status
This commit is contained in:
parent
b1d35b7f02
commit
56a24ff4b8
|
@ -51,9 +51,5 @@ func (f *Folder) Do() string {
|
|||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
if len(res.Tasks) == 0 {
|
||||
return "no tasks here\n\n"
|
||||
}
|
||||
|
||||
return format.FormatTasks(res.Tasks)
|
||||
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
|
||||
}
|
||||
|
|
|
@ -38,9 +38,5 @@ func (p *Project) Do() string {
|
|||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
if len(res.Tasks) == 0 {
|
||||
return "no tasks here\n\n"
|
||||
}
|
||||
|
||||
return format.FormatTasks(res.Tasks)
|
||||
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"ewintr.nl/gte/cmd/cli/format"
|
||||
"ewintr.nl/gte/internal/configuration"
|
||||
"ewintr.nl/gte/internal/process"
|
||||
|
@ -36,5 +38,8 @@ func (t *Today) Do() string {
|
|||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
return format.FormatTasks(res.Tasks)
|
||||
sort.Sort(task.ByDefault(res.Tasks))
|
||||
cols := []format.Column{format.COL_ID, format.COL_STATUS, format.COL_ACTION, format.COL_PROJECT}
|
||||
|
||||
return format.FormatTaskTable(res.Tasks, cols)
|
||||
}
|
||||
|
|
|
@ -36,5 +36,5 @@ func (t *Tomorrow) Do() string {
|
|||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
return format.FormatTasks(res.Tasks)
|
||||
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
|
||||
}
|
||||
|
|
|
@ -34,5 +34,5 @@ func (w *Week) Do() string {
|
|||
return format.FormatError(err)
|
||||
}
|
||||
|
||||
return format.FormatTasks(res.Tasks)
|
||||
return format.FormatTaskTable(res.Tasks, format.COL_ALL)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package format
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"ewintr.nl/gte/internal/task"
|
||||
|
@ -13,49 +12,29 @@ var (
|
|||
ErrFieldAlreadyUsed = errors.New("field was already used")
|
||||
)
|
||||
|
||||
type column int
|
||||
type Column int
|
||||
|
||||
const (
|
||||
COL_ID column = iota
|
||||
COL_ID Column = iota
|
||||
COL_STATUS
|
||||
COL_DATE
|
||||
COL_TASK
|
||||
COL_ACTION
|
||||
COL_PROJECT
|
||||
)
|
||||
|
||||
var (
|
||||
COL_ALL = []Column{COL_ID, COL_STATUS, COL_DATE, COL_ACTION, COL_PROJECT}
|
||||
)
|
||||
|
||||
func FormatError(err error) string {
|
||||
return fmt.Sprintf("could not perform command.\n\nerror: %s\n", err.Error())
|
||||
}
|
||||
|
||||
func FormatTasks(tasks []*task.LocalTask) string {
|
||||
func FormatTaskTable(tasks []*task.LocalTask, cols []Column) string {
|
||||
if len(tasks) == 0 {
|
||||
return "no tasks to display\n"
|
||||
}
|
||||
|
||||
sort.Sort(task.ByDefault(tasks))
|
||||
|
||||
normal, recurring := []*task.LocalTask{}, []*task.LocalTask{}
|
||||
for _, lt := range tasks {
|
||||
if lt.Folder == task.FOLDER_RECURRING {
|
||||
recurring = append(recurring, lt)
|
||||
continue
|
||||
}
|
||||
normal = append(normal, lt)
|
||||
}
|
||||
|
||||
output := ""
|
||||
if len(recurring) > 0 {
|
||||
output = fmt.Sprintf("%s\nRecurring:\n%s\nTasks:\n", output, FormatTaskTable(recurring))
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s\n%s\n", output, FormatTaskTable(normal))
|
||||
}
|
||||
|
||||
func FormatTaskTable(tasks []*task.LocalTask, cols ...column) string {
|
||||
if len(cols) == 0 {
|
||||
cols = []column{COL_ID, COL_STATUS, COL_DATE, COL_TASK, COL_PROJECT}
|
||||
}
|
||||
|
||||
var data [][]string
|
||||
for _, t := range tasks {
|
||||
var line []string
|
||||
|
@ -64,14 +43,17 @@ func FormatTaskTable(tasks []*task.LocalTask, cols ...column) string {
|
|||
case COL_ID:
|
||||
line = append(line, fmt.Sprintf("%d", t.LocalId))
|
||||
case COL_STATUS:
|
||||
var updated string
|
||||
var updated []string
|
||||
if t.LocalStatus == task.STATUS_UPDATED {
|
||||
updated = "*"
|
||||
updated = append(updated, "u")
|
||||
}
|
||||
line = append(line, updated)
|
||||
if task.Today.After(t.Due) {
|
||||
updated = append(updated, "o")
|
||||
}
|
||||
line = append(line, strings.Join(updated, ""))
|
||||
case COL_DATE:
|
||||
line = append(line, t.Due.String())
|
||||
case COL_TASK:
|
||||
case COL_ACTION:
|
||||
line = append(line, t.Action)
|
||||
case COL_PROJECT:
|
||||
line = append(line, t.Project)
|
||||
|
@ -80,7 +62,7 @@ func FormatTaskTable(tasks []*task.LocalTask, cols ...column) string {
|
|||
data = append(data, line)
|
||||
}
|
||||
|
||||
return FormatTable(data)
|
||||
return fmt.Sprintf("\n%s", FormatTable(data))
|
||||
}
|
||||
|
||||
func FormatTask(t *task.LocalTask) string {
|
||||
|
@ -157,7 +139,9 @@ func FormatTable(data [][]string) string {
|
|||
for s := 0; s < max[c]-len(col); s++ {
|
||||
output += " "
|
||||
}
|
||||
output += " "
|
||||
if c != len(line)-1 {
|
||||
output += " "
|
||||
}
|
||||
}
|
||||
if r%3 == 0 {
|
||||
output += fmt.Sprintf("%s", "\x1b[49m")
|
||||
|
|
Loading…
Reference in New Issue