-
Notifications
You must be signed in to change notification settings - Fork 298
/
text.go
50 lines (41 loc) · 963 Bytes
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package hud
import (
"strings"
"time"
"github.com/gdamore/tcell"
"github.com/windmilleng/tilt/internal/rty"
)
func deployTimeText(t time.Time) rty.Component {
sb := rty.NewStringBuilder()
if t.IsZero() {
sb.Text("-")
} else {
sb.Textf("%s ago", formatDeployAge(time.Since(t)))
}
return sb.Build()
}
func deployTimeCell(t time.Time, color tcell.Color) rty.Component {
return rty.NewMinLengthLayout(DeployCellMinWidth, rty.DirHor).
SetAlign(rty.AlignEnd).
Add(rty.Fg(deployTimeText(t), color))
}
func middotText() rty.Component {
return rty.ColoredString(" • ", cLightText)
}
const abbreviatedLogLineCount = 6
func abbreviateLog(s string) []string {
lines := strings.Split(s, "\n")
start := len(lines) - abbreviatedLogLineCount
if start < 0 {
start = 0
}
// skip past leading empty lines
for {
if start < len(lines) && len(strings.TrimSpace(lines[start])) == 0 {
start++
} else {
break
}
}
return lines[start:]
}