1
2
3
4
5 package main
6
7 import (
8 "bytes"
9 "fmt"
10 "strings"
11 )
12
13
14
15 const labelWidth = 47
16
17
18
19
20 func section(w *bytes.Buffer, title, tasks string) {
21 head := "## " + title
22 if tag := taskTag(tasks); tag != "" {
23 if len(head)+len(tag)+1 <= 88 {
24 head += " " + tag
25 } else {
26 head += "\n " + strings.TrimSpace(tag)
27 }
28 }
29 fmt.Fprintf(w, "\n\n%s\n\n", head)
30 }
31
32
33 func note(w *bytes.Buffer, text string) {
34 fmt.Fprintf(w, "%s\n\n", text)
35 }
36
37
38 func frac(w *bytes.Buffer, label string, r result, tasks string) {
39 pct := " --"
40 if r.d > 0 {
41 pct = fmt.Sprintf("%3.0f%%", 100*float64(r.n)/float64(r.d))
42 }
43 line(w, fmt.Sprintf("%-*s %5d / %-5d %s%s", labelWidth, label, r.n, r.d, pct, taskTag(tasks)))
44 }
45
46
47 func count(w *bytes.Buffer, label string, n int, tasks string) {
48 line(w, fmt.Sprintf("%-*s %5d %-9s%s", labelWidth, label, n, "-> 0", taskTag(tasks)))
49 }
50
51
52 func kv(w *bytes.Buffer, label string, n int) {
53 line(w, fmt.Sprintf("%-*s %5d", labelWidth, label, n))
54 }
55
56
57 func sub(w *bytes.Buffer, label string, n int) {
58 line(w, fmt.Sprintf(" %-*s %5d", labelWidth-4, label, n))
59 }
60
61
62
63 func countIndented(w *bytes.Buffer, label string, n int, tasks string) {
64 line(w, fmt.Sprintf(" %-*s %5d %-9s%s", labelWidth-4, label, n, "-> 0", taskTag(tasks)))
65 }
66
67
68
69 func emptyList(w *bytes.Buffer, n int) {
70 if n == 0 {
71 line(w, " (none)")
72 }
73 }
74
75 const lineWrap = 78
76
77
78
79
80
81 func wrap(w *bytes.Buffer, indent, lead string, words []string) {
82 first, rest := indent+lead, indent+strings.Repeat(" ", len(lead))
83 cur := first
84 for _, s := range words {
85 if len(cur) > len(rest) && len(cur)+1+len(s) > lineWrap {
86 line(w, cur)
87 cur = rest
88 }
89 if len(cur) > len(rest) {
90 cur += " "
91 }
92 cur += s
93 }
94 if len(cur) > len(rest) {
95 line(w, cur)
96 }
97 }
98
99 func line(w *bytes.Buffer, s string) {
100 fmt.Fprintf(w, "%s\n", strings.TrimRight(s, " "))
101 }
102
103 func taskTag(tasks string) string {
104 if tasks == "" || tasks == "-" {
105 return ""
106 }
107 return " [" + tasks + "]"
108 }
109
View as plain text