package tui
import (
"strings"
"github.com/charmbracelet/lipgloss"
)
// mascot is drawn with half-blocks from the box-drawing range, so it needs no
// patched font and degrades to something recognisable in a plain xterm.
var mascot = []string{
" ▄▄▄▄▄▄ ",
"▐▀█▀█▀█▌",
"▐██████▌",
" ▀▀ ▀▀ ",
}
const mascotGap = " "
// splash is the welcome block. It goes into the scrollback rather than into
// fixed chrome, so it scrolls away once there is real work to look at instead
// of permanently taxing four rows of a small terminal.
//
// On a narrow terminal the mascot is dropped rather than sliced: half a mascot
// reads as a rendering bug, where the three text lines alone read as a choice.
func splash(o Options, width int) string {
name := styHeading.Render("harness")
if o.Version != "" {
name += " " + styDim.Render(o.Version)
}
lines := []string{
name,
styDim.Render(prettyModel(o.Client.Model) + " · " + endpointLabel(o.Client)),
styDim.Render(shortenHome(o.Root)),
}
// The mascot is dropped only when the terminal cannot hold it beside a
// readable amount of text. It is measured against a minimum rather than
// against the longest line, or a deeply nested working directory would
// silently cost you the whole welcome block.
art := mascot
if width < artWidth()+minSplashText {
art = nil
}
var b strings.Builder
for i := 0; i < maxInt(len(art), len(lines)); i++ {
var line string
if i < len(art) {
line = styCoral.Render(art[i]) + mascotGap
}
if i < len(lines) {
line += lines[i]
}
b.WriteString(truncateStyled(line, maxInt(1, width)) + "\n")
}
return b.String()
}
// minSplashText is how much room the text beside the mascot needs before the
// mascot stops being worth its columns.
const minSplashText = 24
func artWidth() int { return lipgloss.Width(mascot[1]) + lipgloss.Width(mascotGap) }