diff --git a/const.go b/const.go index c7734171..5d8ccfbc 100644 --- a/const.go +++ b/const.go @@ -83,7 +83,8 @@ const ( FG_PRIORITY_CRITICAL = 160 FG_PRIORITY_HIGH = 166 FG_PRIORITY_NORMAL = FG_DEFAULT - FG_PRIORITY_LOW = 245 + FG_PRIORITY_LOW = 245 + FG_NOTE = 240 ) // for import (etc) it's necessary to have full context diff --git a/display.go b/display.go index 35220ab7..ac5aea1b 100644 --- a/display.go +++ b/display.go @@ -47,6 +47,7 @@ func (ts *TaskSet) DisplayByNext(truncate bool) { for _, t := range tasks { style := t.Style() + table.AddRow( []string{ // id should be at least 2 chars wide to match column header @@ -55,7 +56,7 @@ func (ts *TaskSet) DisplayByNext(truncate bool) { t.Priority, strings.Join(t.Tags, " "), t.Project, - t.Summary, + t.LongSummary(), }, style, ) @@ -161,19 +162,16 @@ func (ts TaskSet) DisplayByWeek() { "Tags", "Project", "Summary", - "Closing note", ) } - noteLines := strings.Split(t.Notes, "\n") table.AddRow( []string{ t.Resolved.Format("Mon 2"), t.Priority, strings.Join(t.Tags, " "), t.Project, - t.Summary, - noteLines[len(noteLines)-1], + t.LongSummary(), }, t.Style(), ) diff --git a/table.go b/table.go index 9eb65a1f..06516170 100644 --- a/table.go +++ b/table.go @@ -3,6 +3,7 @@ package dstask import ( "fmt" "strings" + "strconv" ) type Table struct { @@ -37,6 +38,16 @@ func NewTable(w int, header ...string) *Table { } } +func FixStr(text string, width int) string { + // remove after newline + text = strings.Split(text, "\n")[0] + if len(text) <= width { + return fmt.Sprintf("%-"+strconv.Itoa(width)+"v", text) + } else { + return text[:width] + } +} + func (t *Table) AddRow(row []string, style RowStyle) { if len(row) != len(t.Header) { panic("Row is incorrect length") @@ -90,7 +101,19 @@ func (t *Table) Render() { for i, row := range rows { cells := row[:] for i, w := range widths { - cells[i] = FixStr(cells[i], w) + trimmed := FixStr(cells[i], w) + + // support ' / ' markup -- show notes faded + if strings.Contains(trimmed, " " + NOTE_MODE_KEYWORD + " ") { + trimmed = strings.Replace( + FixStr(cells[i], w + 2), + " " + NOTE_MODE_KEYWORD + " ", + fmt.Sprintf("\033[38;5;%dm ", FG_NOTE), + 1, + ) + } + + cells[i] = trimmed } line := strings.Join(cells, strings.Repeat(" ", TABLE_COL_GAP)) diff --git a/task.go b/task.go index a7452585..ceefdbc4 100644 --- a/task.go +++ b/task.go @@ -174,3 +174,15 @@ func (task *Task) Validate() error { return nil } + +// provides Summary + Last note if available +func (task *Task) LongSummary() string { + noteLines := strings.Split(task.Notes, "\n") + lastNote := noteLines[len(noteLines)-1] + + if len(lastNote) > 0 { + return task.Summary + " " + NOTE_MODE_KEYWORD + " " + lastNote + } else { + return task.Summary + } +} diff --git a/util.go b/util.go index da86e621..83361d3c 100644 --- a/util.go +++ b/util.go @@ -11,7 +11,6 @@ import ( "os/user" "path" "runtime" - "strconv" "strings" ) @@ -70,16 +69,6 @@ func SumInts(vals ...int) int { return total } -func FixStr(text string, width int) string { - // remove after newline - text = strings.Split(text, "\n")[0] - if len(text) <= width { - return fmt.Sprintf("%-"+strconv.Itoa(width)+"v", text) - } else { - return text[:width] - } -} - func MustRunCmd(name string, args ...string) { cmd := exec.Command(name, args...) cmd.Stdin = os.Stdin