Skip to content

Commit

Permalink
show muted last note as part of task summary
Browse files Browse the repository at this point in the history
  • Loading branch information
naggie committed Oct 7, 2019
1 parent 2518e81 commit c00bc97
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
3 changes: 2 additions & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,7 +56,7 @@ func (ts *TaskSet) DisplayByNext(truncate bool) {
t.Priority,
strings.Join(t.Tags, " "),
t.Project,
t.Summary,
t.LongSummary(),
},
style,
)
Expand Down Expand Up @@ -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(),
)
Expand Down
25 changes: 24 additions & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dstask
import (
"fmt"
"strings"
"strconv"
)

type Table struct {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
11 changes: 0 additions & 11 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os/user"
"path"
"runtime"
"strconv"
"strings"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c00bc97

Please sign in to comment.