-
Notifications
You must be signed in to change notification settings - Fork 303
/
tabview.go
92 lines (80 loc) · 1.95 KB
/
tabview.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package hud
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/windmilleng/tilt/internal/hud/view"
"github.com/windmilleng/tilt/internal/rty"
"github.com/windmilleng/tilt/pkg/model"
)
type TabView struct {
view view.View
viewState view.ViewState
tabState view.TabState
}
func NewTabView(v view.View, vState view.ViewState) *TabView {
return &TabView{
view: v,
viewState: vState,
tabState: vState.TabState,
}
}
func (v *TabView) Build() rty.Component {
l := rty.NewConcatLayout(rty.DirVert)
l.Add(v.buildTabs(false))
log := rty.NewTextScrollLayout("log")
log.Add(rty.TextString(v.log()))
l.Add(log)
return l
}
func (v *TabView) log() string {
var ret model.Log
switch v.tabState {
case view.TabAllLog:
ret = v.view.Log
case view.TabBuildLog:
_, resource := selectedResource(v.view, v.viewState)
if !resource.CurrentBuild.Empty() {
ret = resource.CurrentBuild.Log
} else {
ret = resource.LastBuild().Log
}
case view.TabPodLog:
_, resource := selectedResource(v.view, v.viewState)
if resource.ResourceInfo != nil {
ret = resource.ResourceInfo.RuntimeLog()
}
}
if !ret.Empty() {
return ret.Tail(logLineCount).String()
} else {
return "(no logs received)"
}
}
func (v *TabView) buildTab(text string) rty.Component {
return rty.TextString(fmt.Sprintf(" %s ", text))
}
func (v *TabView) buildTabs(isMax bool) rty.Component {
l := rty.NewLine()
if v.tabState == view.TabAllLog {
l.Add(v.buildTab("1: ALL LOGS"))
} else {
l.Add(v.buildTab("1: all logs"))
}
l.Add(rty.TextString("│"))
if v.tabState == view.TabBuildLog {
l.Add(v.buildTab("2: BUILD LOG"))
} else {
l.Add(v.buildTab("2: build log"))
}
l.Add(rty.TextString("│"))
if v.tabState == view.TabPodLog {
l.Add(v.buildTab("3: POD LOG"))
} else {
l.Add(v.buildTab("3: pod log"))
}
l.Add(rty.TextString("│ "))
l.Add(renderPaneHeader(isMax))
result := rty.Bg(l, tcell.ColorWhiteSmoke)
result = rty.Fg(result, cText)
return result
}