fix(ui): caret mode no longer panics under the Ascii color profile (U-P0-3)

The background-preserving reset was built by slicing lipgloss output,
which is empty without colors (NO_COLOR, dumb terminals). It is now
derived from the active termenv profile and skipped when there are no
colors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-31 23:09:23 +03:00
parent f57565989c
commit 6696fea67a
2 changed files with 64 additions and 5 deletions

View file

@ -3398,14 +3398,30 @@ func (m *Model) renderTextCursorContent() string {
// foreground and text attributes, then restore the panel background
// so that gutter markers, cursor highlights, and selection highlights
// don't break the panel background for subsequent text on the line.
panelBG := lipgloss.NewStyle().Background(m.palette.Panel).Render("")
bgCode := strings.TrimSuffix(panelBG, "\x1b[0m")
inner := bgCode[2 : len(bgCode)-1]
safeReset := "\x1b[39;22;23;24;59;" + inner + "m"
result = strings.ReplaceAll(result, "\x1b[0m", safeReset)
// The background sequence comes from the active color profile instead
// of slicing lipgloss output, which is empty under the Ascii profile
// (NO_COLOR, dumb terminals) and used to panic (U-P0-3).
if safeReset, ok := backgroundPreservingReset(m.palette.Panel); ok {
result = strings.ReplaceAll(result, "\x1b[0m", safeReset)
}
return result
}
// backgroundPreservingReset returns an SGR sequence that resets foreground
// and text attributes but sets the background to bg. ok is false when the
// current profile has no colors (then a plain reset loses nothing).
func backgroundPreservingReset(bg lipgloss.Color) (string, bool) {
c := lipgloss.ColorProfile().Color(string(bg))
if c == nil {
return "", false
}
seq := c.Sequence(true)
if seq == "" {
return "", false
}
return "\x1b[39;22;23;24;59;" + seq + "m", true
}
func (m *Model) moveTextCursorWordForward() {
if !m.cursorMode {
return