diff --git a/cmd/cli/command/folder.go b/cmd/cli/command/folder.go index 51da1f3..dbf8deb 100644 --- a/cmd/cli/command/folder.go +++ b/cmd/cli/command/folder.go @@ -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) } diff --git a/cmd/cli/command/project.go b/cmd/cli/command/project.go index 7bdac14..60a2ef8 100644 --- a/cmd/cli/command/project.go +++ b/cmd/cli/command/project.go @@ -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) } diff --git a/cmd/cli/command/today.go b/cmd/cli/command/today.go index 6093d44..8a29783 100644 --- a/cmd/cli/command/today.go +++ b/cmd/cli/command/today.go @@ -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) } diff --git a/cmd/cli/command/tomorrow.go b/cmd/cli/command/tomorrow.go index 8be4ebd..c1ae768 100644 --- a/cmd/cli/command/tomorrow.go +++ b/cmd/cli/command/tomorrow.go @@ -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) } diff --git a/cmd/cli/command/week.go b/cmd/cli/command/week.go index 526d73e..52bcd44 100644 --- a/cmd/cli/command/week.go +++ b/cmd/cli/command/week.go @@ -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) } diff --git a/cmd/cli/format/format.go b/cmd/cli/format/format.go index 4c7e634..e869549 100644 --- a/cmd/cli/format/format.go +++ b/cmd/cli/format/format.go @@ -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")