1
1
package redovc
2
2
3
3
import (
4
+ "fmt"
4
5
"io"
5
6
"sort"
6
7
"strconv"
@@ -18,6 +19,14 @@ type ScreenPrinter struct {
18
19
UnicodeSupport bool
19
20
}
20
21
22
+ const (
23
+ idColumnWidth = "%-4s"
24
+ completedColumnWidth = "%-3s"
25
+ infoColumnWidth = "%-3s"
26
+ dueColumnWidth = "%-10s"
27
+ statusColumnWidth = "%-10s"
28
+ )
29
+
21
30
// NewScreenPrinter creates a new screeen printer.
22
31
func NewScreenPrinter (unicodeSupport bool ) * ScreenPrinter {
23
32
w := new (io.Writer )
@@ -49,41 +58,41 @@ func (f *ScreenPrinter) Print(groupedTodos *GroupedTodos, printNotes bool, showI
49
58
}
50
59
51
60
func (f * ScreenPrinter ) printTodo (tabby * tabby.Tabby , todo * Todo , printNotes bool , showInfoFlags bool ) {
61
+ id := fmt .Sprintf (idColumnWidth , f .formatID (todo .ID , todo .IsPriority ))
62
+ completed := fmt .Sprintf (completedColumnWidth , f .formatCompleted (todo .Completed ))
63
+ info := fmt .Sprintf (infoColumnWidth , f .formatInfoFlags (todo ))
64
+ due := fmt .Sprintf (dueColumnWidth , f .formatDue (todo .Due , todo .IsPriority , todo .Completed ))
65
+ status := fmt .Sprintf (statusColumnWidth , f .formatStatus (todo .Status , todo .IsPriority ))
66
+ subject := f .formatSubject (todo .Subject , todo .IsPriority )
67
+
68
+ columns := OrderColumns (showInfoFlags , id , completed , info , due , status , subject )
69
+
52
70
if showInfoFlags {
53
- tabby .AddLine (
54
- f .formatID (todo .ID , todo .IsPriority ),
55
- f .formatCompleted (todo .Completed ),
56
- f .formatInfoFlags (todo ),
57
- f .formatDue (todo .Due , todo .IsPriority , todo .Completed ),
58
- f .formatStatus (todo .Status , todo .IsPriority ),
59
- f .formatSubject (todo .Subject , todo .IsPriority ))
71
+ tabby .AddLine (columns [0 ], columns [1 ], columns [2 ], columns [3 ], columns [4 ], columns [5 ])
60
72
} else {
61
- tabby .AddLine (
62
- f .formatID (todo .ID , todo .IsPriority ),
63
- f .formatCompleted (todo .Completed ),
64
- f .formatDue (todo .Due , todo .IsPriority , todo .Completed ),
65
- f .formatStatus (todo .Status , todo .IsPriority ),
66
- f .formatSubject (todo .Subject , todo .IsPriority ))
73
+ tabby .AddLine (columns [0 ], columns [1 ], columns [2 ], columns [3 ], columns [4 ])
67
74
}
68
75
69
76
if printNotes {
70
77
for nid , note := range todo .Notes {
71
78
tabby .AddLine (
72
- " " + noteIDColor .Sprint (strconv .Itoa (nid )),
73
- noteTextColor .Sprint ("" ),
74
- noteTextColor .Sprint ("" ),
75
- noteTextColor .Sprint ("" ),
76
- noteTextColor .Sprint ("" ),
77
- noteTextColor .Sprint (note ))
79
+ " " + noteIDColor .Sprint (strconv .Itoa (nid )),
80
+ noteTextColor .Sprintf (idColumnWidth , "" ),
81
+ noteTextColor .Sprintf (completedColumnWidth , "" ),
82
+ noteTextColor .Sprintf (infoColumnWidth , "" ),
83
+ noteTextColor .Sprintf (dueColumnWidth , "" ),
84
+ noteTextColor .Sprintf (statusColumnWidth , "" ),
85
+ noteTextColor .Sprintf ("" ),
86
+ noteTextColor .Sprint ("- " + note ))
78
87
}
79
88
}
80
89
}
81
90
82
91
func (f * ScreenPrinter ) formatID (ID int , isPriority bool ) string {
83
92
if isPriority {
84
- return taskIDPriColor .Sprint (strconv .Itoa (ID ))
93
+ return taskIDPriColor .Sprintf (strconv .Itoa (ID ))
85
94
}
86
- return taskIDColor .Sprint (strconv .Itoa (ID ))
95
+ return taskIDColor .Sprintf (strconv .Itoa (ID ))
87
96
}
88
97
89
98
func (f * ScreenPrinter ) formatCompleted (completed bool ) string {
@@ -98,7 +107,7 @@ func (f *ScreenPrinter) formatCompleted(completed bool) string {
98
107
99
108
func (f * ScreenPrinter ) formatDue (due string , isPriority bool , completed bool ) string {
100
109
if due == "" {
101
- return whiteFg .Sprint ( " " )
110
+ return whiteFg .Sprintf ( " " )
102
111
}
103
112
dueTime , _ := time .Parse (DATE_FORMAT , due )
104
113
@@ -110,21 +119,15 @@ func (f *ScreenPrinter) formatDue(due string, isPriority bool, completed bool) s
110
119
111
120
func (f * ScreenPrinter ) formatStatus (status string , isPriority bool ) string {
112
121
if status == "" {
113
- return statusColor .Sprint (" " )
114
- }
115
-
116
- if len (status ) < 10 {
117
- for x := len (status ); x <= 10 ; x ++ {
118
- status += " "
119
- }
122
+ return statusColor .Sprintf ("" )
120
123
}
121
124
122
- statusRune := []rune (status )
125
+ // statusRune := []rune(status)
123
126
124
127
if isPriority {
125
- return statusPriColor .Sprintf ("%-10v" , string (statusRune [0 :10 ]))
128
+ return statusPriColor .Sprintf (status ) // string(statusRune[0:10]))
126
129
}
127
- return statusColor .Sprintf ("%-10s" , string (statusRune [0 :10 ]))
130
+ return statusColor .Sprintf (status ) // string(statusRune[0:10]))
128
131
}
129
132
130
133
func (f * ScreenPrinter ) formatInfoFlags (todo * Todo ) string {
@@ -150,25 +153,25 @@ func (f *ScreenPrinter) formatInfoFlags(todo *Todo) string {
150
153
151
154
func (f * ScreenPrinter ) printDue (due time.Time , completed bool ) string {
152
155
if isToday (due ) {
153
- return todayColor .Sprint ("today " )
156
+ return todayColor .Sprintf ("today" )
154
157
} else if isTomorrow (due ) {
155
- return tomorrowColor .Sprint ("tomorrow " )
158
+ return tomorrowColor .Sprintf ("tomorrow" )
156
159
} else if isPastDue (due ) && ! completed {
157
- return overdueColor .Sprint (due .Format ("Mon Jan 02" ))
160
+ return overdueColor .Sprintf (due .Format ("Mon Jan 02" ))
158
161
}
159
162
160
- return otherDue .Sprint (due .Format ("Mon Jan 02" ))
163
+ return otherDue .Sprintf (due .Format ("Mon Jan 02" ))
161
164
}
162
165
163
166
func (f * ScreenPrinter ) printPriorityDue (due time.Time , completed bool ) string {
164
167
if isToday (due ) {
165
- return todayPriColor .Sprint ("today " )
168
+ return todayPriColor .Sprintf ("today" )
166
169
} else if isTomorrow (due ) {
167
- return tomorrowPriColor .Sprint ("tomorrow " )
170
+ return tomorrowPriColor .Sprintf ("tomorrow" )
168
171
} else if isPastDue (due ) && ! completed {
169
- return overduePriColor .Sprint (due .Format ("Mon Jan 02" ))
172
+ return overduePriColor .Sprintf (due .Format ("Mon Jan 02" ))
170
173
}
171
- return otherDuePriColor .Sprint (due .Format ("Mon Jan 02" ))
174
+ return otherDuePriColor .Sprintf (due .Format ("Mon Jan 02" ))
172
175
}
173
176
174
177
func (f * ScreenPrinter ) formatSubject (subject string , isPriority bool ) string {
0 commit comments