github.com/grahambrereton-form3/tilt@v0.10.18/internal/hud/tabview.go (about) 1 package hud 2 3 import ( 4 "fmt" 5 6 "github.com/gdamore/tcell" 7 8 "github.com/windmilleng/tilt/internal/hud/view" 9 "github.com/windmilleng/tilt/internal/rty" 10 "github.com/windmilleng/tilt/pkg/model" 11 ) 12 13 type TabView struct { 14 view view.View 15 viewState view.ViewState 16 tabState view.TabState 17 } 18 19 func NewTabView(v view.View, vState view.ViewState) *TabView { 20 return &TabView{ 21 view: v, 22 viewState: vState, 23 tabState: vState.TabState, 24 } 25 } 26 27 func (v *TabView) Build() rty.Component { 28 l := rty.NewConcatLayout(rty.DirVert) 29 l.Add(v.buildTabs(false)) 30 31 log := rty.NewTextScrollLayout("log") 32 log.Add(rty.TextString(v.log())) 33 l.Add(log) 34 35 return l 36 } 37 38 func (v *TabView) log() string { 39 var ret model.Log 40 switch v.tabState { 41 case view.TabAllLog: 42 ret = v.view.Log 43 case view.TabBuildLog: 44 _, resource := selectedResource(v.view, v.viewState) 45 if !resource.CurrentBuild.Empty() { 46 ret = resource.CurrentBuild.Log 47 } else { 48 ret = resource.LastBuild().Log 49 } 50 case view.TabPodLog: 51 _, resource := selectedResource(v.view, v.viewState) 52 if resource.ResourceInfo != nil { 53 ret = resource.ResourceInfo.RuntimeLog() 54 } 55 } 56 57 if !ret.Empty() { 58 return ret.Tail(logLineCount).String() 59 } else { 60 return "(no logs received)" 61 } 62 } 63 64 func (v *TabView) buildTab(text string) rty.Component { 65 return rty.TextString(fmt.Sprintf(" %s ", text)) 66 } 67 68 func (v *TabView) buildTabs(isMax bool) rty.Component { 69 l := rty.NewLine() 70 if v.tabState == view.TabAllLog { 71 l.Add(v.buildTab("1: ALL LOGS")) 72 } else { 73 l.Add(v.buildTab("1: all logs")) 74 } 75 l.Add(rty.TextString("│")) 76 if v.tabState == view.TabBuildLog { 77 l.Add(v.buildTab("2: BUILD LOG")) 78 } else { 79 l.Add(v.buildTab("2: build log")) 80 } 81 l.Add(rty.TextString("│")) 82 if v.tabState == view.TabPodLog { 83 l.Add(v.buildTab("3: POD LOG")) 84 } else { 85 l.Add(v.buildTab("3: pod log")) 86 } 87 l.Add(rty.TextString("│ ")) 88 l.Add(renderPaneHeader(isMax)) 89 result := rty.Bg(l, tcell.ColorWhiteSmoke) 90 result = rty.Fg(result, cText) 91 return result 92 }