github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/hud/text.go (about)

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