github.com/grahambrereton-form3/tilt@v0.10.18/internal/hud/text.go (about)

     1  package hud
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  
     7  	"github.com/gdamore/tcell"
     8  
     9  	"github.com/windmilleng/tilt/internal/rty"
    10  )
    11  
    12  // The most lines we can reasonably put in the log pane. If the log pane sticks
    13  // around in the long term, we might want to compute this dynamically based on
    14  // the window size.
    15  const logLineCount = 50
    16  
    17  func deployTimeText(t time.Time) rty.Component {
    18  	sb := rty.NewStringBuilder()
    19  	if t.IsZero() {
    20  		sb.Text("-")
    21  	} else {
    22  		sb.Textf("%s ago", formatDeployAge(time.Since(t)))
    23  	}
    24  	return sb.Build()
    25  }
    26  
    27  func deployTimeCell(t time.Time, color tcell.Color) rty.Component {
    28  	return rty.NewMinLengthLayout(DeployCellMinWidth, rty.DirHor).
    29  		SetAlign(rty.AlignEnd).
    30  		Add(rty.Fg(deployTimeText(t), color))
    31  }
    32  
    33  func middotText() rty.Component {
    34  	return rty.ColoredString(" • ", cLightText)
    35  }
    36  
    37  const abbreviatedLogLineCount = 6
    38  
    39  func abbreviateLog(s string) []string {
    40  	lines := strings.Split(s, "\n")
    41  	start := len(lines) - abbreviatedLogLineCount
    42  	if start < 0 {
    43  		start = 0
    44  	}
    45  
    46  	// skip past leading empty lines
    47  	for {
    48  		if start < len(lines) && len(strings.TrimSpace(lines[start])) == 0 {
    49  			start++
    50  		} else {
    51  			break
    52  		}
    53  	}
    54  
    55  	return lines[start:]
    56  }