github.com/grahambrereton-form3/tilt@v0.10.18/internal/hud/buildstatus.go (about) 1 package hud 2 3 import ( 4 "time" 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 buildStatus struct { 14 edits []string 15 duration time.Duration 16 status string 17 deployTime time.Time 18 reason model.BuildReason 19 muted bool 20 } 21 22 func (bs buildStatus) defaultTextColor() tcell.Color { 23 if bs.muted { 24 return cLightText 25 } 26 return tcell.ColorDefault 27 } 28 29 func makeBuildStatus(res view.Resource, triggerMode model.TriggerMode) buildStatus { 30 status := "Pending" 31 duration := time.Duration(0) 32 edits := []string{} 33 deployTime := time.Time{} 34 reason := model.BuildReason(0) 35 36 if res.IsTiltfile { 37 return buildStatus{ 38 status: "N/A", 39 } 40 } 41 42 if !res.CurrentBuild.Empty() && !res.CurrentBuild.Reason.IsCrashOnly() { 43 status = "In prog." 44 duration = time.Since(res.CurrentBuild.StartTime) 45 edits = res.CurrentBuild.Edits 46 reason = res.CurrentBuild.Reason 47 } else if !res.PendingBuildSince.IsZero() && !res.PendingBuildReason.IsCrashOnly() { 48 status = "Pending" 49 if triggerMode.AutoOnChange() { 50 duration = time.Since(res.PendingBuildSince) 51 } 52 edits = res.PendingBuildEdits 53 reason = res.PendingBuildReason 54 } else if !res.LastBuild().FinishTime.IsZero() { 55 lastBuild := res.LastBuild() 56 if lastBuild.Error != nil { 57 status = "Error" 58 } else { 59 status = "OK" 60 } 61 duration = lastBuild.Duration() 62 edits = lastBuild.Edits 63 deployTime = res.LastDeployTime 64 reason = lastBuild.Reason 65 } 66 67 return buildStatus{ 68 status: status, 69 duration: duration, 70 edits: edits, 71 deployTime: deployTime, 72 reason: reason, 73 } 74 } 75 76 func buildStatusCell(bs buildStatus) rty.Component { 77 textColor := bs.defaultTextColor() 78 showingDuration := bs.duration != 0 79 lhsWidth := BuildStatusCellMinWidth 80 if !showingDuration { 81 lhsWidth += BuildDurCellMinWidth 82 } 83 lhs := rty.NewMinLengthLayout(lhsWidth, rty.DirHor). 84 Add(rty.ColoredString(bs.status, textColor)) 85 if !showingDuration { 86 return lhs 87 } 88 89 sb := rty.NewStringBuilder() 90 sb.Fg(cLightText).Text(" (") 91 sb.Fg(textColor).Text(formatBuildDuration(bs.duration)) 92 sb.Fg(cLightText).Text(")") 93 rhs := rty.NewMinLengthLayout(BuildDurCellMinWidth, rty.DirHor). 94 SetAlign(rty.AlignEnd). 95 Add(sb.Build()) 96 97 return rty.NewConcatLayout(rty.DirHor). 98 Add(lhs). 99 Add(rhs) 100 }