Marquee long sidebar names; truncate with ellipsis otherwise
Sidebar rows that overflow the rail width used to spill characters into the main viewport. They now truncate with a trailing "…" when unfocused (or when the focused name still fits). The focused row whose name overflows runs a pause-scroll-pause marquee: 1 s hold on the head, ~150 ms per cell scroll, 1 s hold on the tail, snap back. The row's geometry never moves while it animates, so nothing below shifts. A dedicated 150 ms goroutine flips sidebarDirty only while a row is actively animating; the chrome ticker does the actual repaint. Idle is a single cheap wakeup. focus / spawn / exit / restart all reset the marquee state so the new focused row starts from frame zero. When the row's budget is tight, the trailing timer indicator drops before the name ellipses since the name is the only identifier the row carries. clampVisible() is a defensive net inside write(): even if a row's decoration size were mis-computed, it will not spill past the sidebar band into the PTY area.
This commit is contained in:
@@ -12,6 +12,128 @@ const (
|
||||
statusRows = 1
|
||||
)
|
||||
|
||||
// fitName returns name truncated to fit budget visible cells, with a
|
||||
// trailing "…" when it overflows. Operates on RAW (unstyled) input;
|
||||
// the caller wraps the result in SGR. Returns "" when budget <= 0.
|
||||
func fitName(name string, budget int) string {
|
||||
if budget <= 0 {
|
||||
return ""
|
||||
}
|
||||
runes := []rune(name)
|
||||
if len(runes) <= budget {
|
||||
return name
|
||||
}
|
||||
if budget == 1 {
|
||||
return "…"
|
||||
}
|
||||
return string(runes[:budget-1]) + "…"
|
||||
}
|
||||
|
||||
// marqueeWindow returns the window of name starting at offset, exactly
|
||||
// budget cells wide. Pre: caller has decided the name overflows budget
|
||||
// and offset is in [0, len([]rune(name))-budget]. Operates on RAW
|
||||
// (unstyled) input.
|
||||
func marqueeWindow(name string, budget, offset int) string {
|
||||
if budget <= 0 {
|
||||
return ""
|
||||
}
|
||||
runes := []rune(name)
|
||||
if len(runes) <= budget {
|
||||
return name
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
end := offset + budget
|
||||
if end > len(runes) {
|
||||
end = len(runes)
|
||||
offset = end - budget
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
}
|
||||
return string(runes[offset:end])
|
||||
}
|
||||
|
||||
// clampVisible truncates s so that its visible (non-SGR) length is at
|
||||
// most width cells, preserving any active style by appending a reset.
|
||||
// Used as a defensive net by write() so a row whose decoration was
|
||||
// mis-sized still cannot spill past the sidebar band into the PTY area.
|
||||
func clampVisible(s string, width int) string {
|
||||
if width <= 0 {
|
||||
return ""
|
||||
}
|
||||
if visibleLen(s) <= width {
|
||||
return s
|
||||
}
|
||||
var b strings.Builder
|
||||
b.Grow(len(s))
|
||||
visible := 0
|
||||
inEsc := false
|
||||
for _, r := range s {
|
||||
if inEsc {
|
||||
b.WriteRune(r)
|
||||
if r == 'm' || r == 'H' {
|
||||
inEsc = false
|
||||
}
|
||||
continue
|
||||
}
|
||||
if r == 0x1b {
|
||||
inEsc = true
|
||||
b.WriteRune(r)
|
||||
continue
|
||||
}
|
||||
if visible >= width {
|
||||
break
|
||||
}
|
||||
b.WriteRune(r)
|
||||
visible++
|
||||
}
|
||||
b.WriteString(styleReset)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// chooseSidebarSuffix decides whether to keep or drop the trailing
|
||||
// timer indicator from a sidebar row's suffix. When the row's name
|
||||
// would have to ellipsise with the timer present, but the budget
|
||||
// freed by dropping the timer still leaves at least 6 cells for the
|
||||
// name, the timer is dropped. The name is the only identifier the
|
||||
// user has for that row; the timer is recoverable from the status
|
||||
// line and palette.
|
||||
func chooseSidebarSuffix(nameRuneLen, width int, prefix, suffix, timer string) (string, int) {
|
||||
prefixCost := visibleLen(prefix)
|
||||
budget := width - prefixCost - visibleLen(suffix)
|
||||
if nameRuneLen <= budget || timer == "" {
|
||||
return suffix, budget
|
||||
}
|
||||
slim := strings.TrimSuffix(suffix, timer)
|
||||
if slim == suffix {
|
||||
return suffix, budget
|
||||
}
|
||||
slimBudget := width - prefixCost - visibleLen(slim)
|
||||
if slimBudget >= 6 {
|
||||
return slim, slimBudget
|
||||
}
|
||||
return suffix, budget
|
||||
}
|
||||
|
||||
// rowNameSlot returns the unstyled name cell for a sidebar row.
|
||||
// Unfocused (or focused-and-fitting) rows get fitName with a trailing
|
||||
// "…" on overflow. The focused row, when its name overflows the
|
||||
// budget, gets the current marquee window — exactly budget cells
|
||||
// wide so the surrounding row geometry stays put while it animates.
|
||||
func (st *uiState) rowNameSlot(id, rawName string, budget int, focused bool) string {
|
||||
if budget <= 0 {
|
||||
return ""
|
||||
}
|
||||
runes := []rune(rawName)
|
||||
if !focused || len(runes) <= budget {
|
||||
return fitName(rawName, budget)
|
||||
}
|
||||
off, _, _ := st.marquee.step(id, len(runes), budget, time.Now())
|
||||
return marqueeWindow(rawName, budget, off)
|
||||
}
|
||||
|
||||
// formatShortDuration renders a duration as a short, sidebar-friendly
|
||||
// suffix: ms under 1s, "12s" under 60s, "3m" otherwise.
|
||||
func formatShortDuration(d time.Duration) string {
|
||||
@@ -73,6 +195,9 @@ func (st *uiState) drawSidebar() {
|
||||
if row > maxRow {
|
||||
return
|
||||
}
|
||||
if visibleLen(content) > width {
|
||||
content = clampVisible(content, width)
|
||||
}
|
||||
pad := width - visibleLen(content)
|
||||
if pad < 0 {
|
||||
pad = 0
|
||||
@@ -154,14 +279,19 @@ func (st *uiState) drawSidebar() {
|
||||
if c.AutoRestart() {
|
||||
marker = " " + styleDim + "⟳" + styleReset
|
||||
}
|
||||
var line string
|
||||
timer := timerIndicator(c)
|
||||
var prefix, openStyle string
|
||||
if focused {
|
||||
line = " " + styleAccent + "▎" + styleReset + " " + glyph + " " +
|
||||
styleBold + c.DisplayName() + styleReset + marker + timerIndicator(c)
|
||||
prefix = " " + styleAccent + "▎" + styleReset + " " + glyph + " "
|
||||
openStyle = styleBold
|
||||
} else {
|
||||
line = " " + glyph + " " + styleHint + c.DisplayName() + styleReset + marker + timerIndicator(c)
|
||||
prefix = " " + glyph + " "
|
||||
openStyle = styleHint
|
||||
}
|
||||
write(line)
|
||||
raw := c.DisplayName()
|
||||
suffix, budget := chooseSidebarSuffix(len([]rune(raw)), width, prefix, marker+timer, timer)
|
||||
nameCell := st.rowNameSlot(c.ID, raw, budget, focused)
|
||||
write(prefix + openStyle + nameCell + styleReset + suffix)
|
||||
}
|
||||
|
||||
// Agent Tree section — formerly "Session tree". Shows the active
|
||||
@@ -186,14 +316,19 @@ func (st *uiState) drawSidebar() {
|
||||
}
|
||||
focused := c.ID == focus
|
||||
glyph := statusGlyph(c, focused)
|
||||
var line string
|
||||
timer := timerIndicator(c)
|
||||
var prefix, openStyle string
|
||||
if focused {
|
||||
line = " " + styleAccent + "▎" + styleReset + " " + indent + glyph + " " +
|
||||
styleBold + c.DisplayName() + styleReset + timerIndicator(c)
|
||||
prefix = " " + styleAccent + "▎" + styleReset + " " + indent + glyph + " "
|
||||
openStyle = styleBold
|
||||
} else {
|
||||
line = " " + indent + glyph + " " + styleHint + c.DisplayName() + styleReset + timerIndicator(c)
|
||||
prefix = " " + indent + glyph + " "
|
||||
openStyle = styleHint
|
||||
}
|
||||
write(line)
|
||||
raw := c.DisplayName()
|
||||
suffix, budget := chooseSidebarSuffix(len([]rune(raw)), width, prefix, timer, timer)
|
||||
nameCell := st.rowNameSlot(c.ID, raw, budget, focused)
|
||||
write(prefix + openStyle + nameCell + styleReset + suffix)
|
||||
}
|
||||
|
||||
// Scratchpads list — names only. The preview pane used to live
|
||||
@@ -212,14 +347,18 @@ func (st *uiState) drawSidebar() {
|
||||
if row > maxRow {
|
||||
break
|
||||
}
|
||||
var line string
|
||||
if e.Name == focusPad {
|
||||
line = " " + styleAccent + "▎" + styleReset + " " +
|
||||
styleBold + e.Name + styleReset
|
||||
focused := e.Name == focusPad
|
||||
var prefix, openStyle string
|
||||
if focused {
|
||||
prefix = " " + styleAccent + "▎" + styleReset + " "
|
||||
openStyle = styleBold
|
||||
} else {
|
||||
line = " " + styleHint + e.Name + styleReset
|
||||
prefix = " "
|
||||
openStyle = styleHint
|
||||
}
|
||||
write(line)
|
||||
budget := width - visibleLen(prefix)
|
||||
nameCell := st.rowNameSlot("pad:"+e.Name, e.Name, budget, focused)
|
||||
write(prefix + openStyle + nameCell + styleReset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user