Real-image posters: blocks while the window is being resized; ARR_TUI_DEBUG_GFX log

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 00:35:19 +02:00
co-authored by Claude Sonnet 5.5
parent ce0d441a2e
commit 55810bb1e2
6 changed files with 90 additions and 4 deletions
+50
View File
@@ -10,6 +10,7 @@ import (
"regexp"
"strings"
"testing"
"time"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
@@ -318,3 +319,52 @@ func TestPosterSource(t *testing.T) {
}
}
}
func TestGraphicsAreHeldWhileTheWindowChanges(t *testing.T) {
sim := tcell.NewSimulationScreen("")
if err := sim.Init(); err != nil {
t.Fatal(err)
}
defer sim.Fini()
sim.SetSize(40, 20)
screen := trueColor{sim}
rec := &recorder{}
k := newKittyGraphics(rec.write)
c := newCoverView(quadrantStyle, k, nil)
c.setImage(stripes(40, 60))
c.SetRect(0, 0, 30, 10)
k.hold()
if !k.settling() {
t.Fatal("hold must start the settling period")
}
c.Draw(screen)
if len(rec.cmds) != 0 {
t.Fatalf("graphics commands while the window changes: %q", rec.cmds)
}
if ch, _, _, _ := sim.GetContent(29, 9); ch == placeholderRune {
t.Error("placeholders drawn while settling; blocks are the stand-in")
}
k.holdUntil = time.Now().Add(-time.Millisecond) // the period is over
c.Draw(screen)
if len(rec.cmds) != 2 {
t.Errorf("after settling: %d commands, want upload + placement", len(rec.cmds))
}
if ch, _, _, _ := sim.GetContent(29, 9); ch != placeholderRune {
t.Error("real image not shown after settling")
}
}
func TestGraphicsDebugReportsUploads(t *testing.T) {
rec := &recorder{}
k := newKittyGraphics(rec.write)
var lines []string
k.debug = func(s string) { lines = append(lines, s) }
img := noisy(10, 15)
k.show(img, img.Bounds(), 12, 8)
if len(lines) != 1 || !strings.Contains(lines[0], "id 1") || !strings.Contains(lines[0], "12x8 cells") || !strings.Contains(lines[0], "10x15 px") {
t.Errorf("debug lines = %q", lines)
}
}