From 7112e45ca22b85c36494cb277528646586ad297d Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Wed, 13 May 2026 17:51:16 +0000 Subject: [PATCH 1/2] LAB-1803: Cover styled blank scrollback trimming --- vt/scrollback_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vt/scrollback_test.go b/vt/scrollback_test.go index 049b0784..669c3a6a 100644 --- a/vt/scrollback_test.go +++ b/vt/scrollback_test.go @@ -1,7 +1,10 @@ package vt import ( + "image/color" "testing" + + uv "github.com/charmbracelet/ultraviolet" ) func TestScrollback(t *testing.T) { @@ -68,6 +71,30 @@ func TestScrollback(t *testing.T) { } }) + t.Run("trims trailing styled blanks", func(t *testing.T) { + sb := NewScrollback(1) + line := make(uv.Line, 12) + for i := range line { + line[i] = uv.Cell{ + Content: " ", + Style: uv.Style{Bg: color.RGBA{R: 24, G: 28, B: 36, A: 255}}, + Width: 1, + } + } + for i, r := range "prompt" { + line[i] = uv.Cell{Content: string(r), Width: 1} + } + + sb.Push(line) + + if got := len(sb.Line(0)); got != len("prompt") { + t.Fatalf("stored line length = %d, want %d", got, len("prompt")) + } + if got := sb.Line(0).String(); got != "prompt" { + t.Fatalf("stored line text = %q, want %q", got, "prompt") + } + }) + t.Run("clear scrollback", func(t *testing.T) { e := NewEmulator(20, 5) From fc372e8574ca67ce336b0de4f0372fc130bb4bab Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Wed, 13 May 2026 17:51:46 +0000 Subject: [PATCH 2/2] LAB-1803: Trim trailing styled blanks in vt scrollback --- vt/scrollback.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vt/scrollback.go b/vt/scrollback.go index 9688d025..9d1c8406 100644 --- a/vt/scrollback.go +++ b/vt/scrollback.go @@ -115,8 +115,7 @@ func (s *Scrollback) CellAt(x, y int) *uv.Cell { func trimTrailingEmptyCells(line uv.Line) uv.Line { lastNonEmpty := -1 for i := len(line) - 1; i >= 0; i-- { - c := &line[i] - if !c.IsZero() && !c.Equal(&uv.EmptyCell) { + if !isTrailingScrollbackBlank(&line[i]) { lastNonEmpty = i break } @@ -124,3 +123,16 @@ func trimTrailingEmptyCells(line uv.Line) uv.Line { return line[:lastNonEmpty+1] } + +func isTrailingScrollbackBlank(cell *uv.Cell) bool { + if cell == nil { + return true + } + if cell.IsZero() || cell.Equal(&uv.EmptyCell) { + return true + } + if cell.Width == 0 { + return false + } + return cell.Content == "" || cell.Content == " " +}