Files
donlucasandClaude Opus 5 9452bc6040 The main screen reflows on width, so scrollback cannot come from the terminal
He said scrollback matters, and only the main screen has any, so both axes
were measured there before writing a line of code.

Height, 120x30 -> 120x47: ANCHORED TOP. ROW 01 stayed put and the blanks
appeared at the bottom -- the opposite of the alternate screen, and needing no
correction at all. (⚠ on a screen with nearly no history above it. The
2026-09-02 note says a grow pulls scrolled-off lines back in, and with nothing
in history there is nothing to pull. Not generalised.)

Width, 120x47 -> 78x47: TOTAL REFLOW. Every full-width row re-wrapped into two,
and the view shifted so the top showed the previous row's tail. Claude Code's
UI is full-width lines almost exclusively -- the box borders, the status line --
so any narrowing doubles all of them.

That kills the idea. Everything the host can do moves whole ROWS; reflow changes
how many rows a logical LINE takes, and the host does not model logical lines,
so there is no correction available. The alternate screen never reflows, which
is precisely the property that makes the band work at all.

So Terminal.app will not give both. Scrollback and the band are exclusive, and
if xscapes wants scrollback it has to own it.

Worth saying plainly: this is the first time today a measurement was taken
BEFORE the code rather than after a wrong fix, and it saved building something
that could not have worked.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R1u8vp8AgrTuaCCcLv6HVi
2026-09-03 16:00:59 -07:00

105 lines
3.1 KiB
Go

// contentprobe measures whether Terminal.app moves CONTENT when the window
// grows, in the configuration xscapes actually runs in.
//
// The earlier anchorprobe measured the CURSOR and its result was written up as
// a fact about content. That was wrong: the cursor can stay at its absolute row
// while the content moves out from under it, which is exactly what the failure
// traces imply. There is no escape sequence that reads cells back from
// Terminal.app, so this one is read by eye -- one number.
//
// Production's configuration exactly: alternate screen, DECSTBM band pinned at
// the top, origin mode on.
package main
import (
"bufio"
"fmt"
"os"
"strings"
"syscall"
"unsafe"
)
type winsize struct{ rows, cols, xpixel, ypixel uint16 }
func termSize() (int, int) {
fds := []uintptr{os.Stdout.Fd(), os.Stderr.Fd(), os.Stdin.Fd()}
if f, err := os.OpenFile("/dev/tty", os.O_RDONLY, 0); err == nil {
defer f.Close()
fds = append(fds, f.Fd())
}
for _, fd := range fds {
var ws winsize
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, fd,
uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws)))
if errno == 0 && ws.cols >= 8 && ws.rows >= 4 {
return int(ws.cols), int(ws.rows)
}
}
return 0, 0
}
func main() {
w, h := termSize()
if w == 0 {
fmt.Println("run this in a Terminal.app window")
return
}
band := h * 9 / 20
band = h - band // agent rows, the way host.Band does it
// -main measures the MAIN screen, which is the one that HAS scrollback.
// The alternate screen's behaviour says nothing about it: they were already
// measured moving the cursor in opposite directions.
alt := true
for _, a := range os.Args[1:] {
if a == "-main" {
alt = false
}
}
if alt {
fmt.Print("\x1b[?1049h") // alternate screen
}
fmt.Printf("\x1b[1;%dr\x1b[?6h", band) // the band, and origin mode
defer func() {
fmt.Print("\x1b[?6l\x1b[r")
if alt {
fmt.Print("\x1b[?1049l")
}
}()
// Fill every row with its own number, both edges, so the top row is
// readable no matter how far the window is dragged.
for r := 1; r <= h; r++ {
tag := fmt.Sprintf(" ROW %02d ", r)
mid := strings.Repeat("-", max(0, w-2*len(tag)))
fmt.Printf("\x1b[?6l\x1b[%d;1H\x1b[2K%s%s%s\x1b[?6h", r, tag, mid, tag)
}
msg := fmt.Sprintf(" %dx%d, band 1..%d. STRETCH THE WINDOW TALLER, then look at the TOP row. ", w, h, band)
fmt.Printf("\x1b[?6l\x1b[%d;1H\x1b[7m%s\x1b[0m\x1b[?6h", h/2, msg)
bufio.NewReader(os.Stdin).ReadString('\n')
_, h2 := termSize()
fmt.Print("\x1b[?6l\x1b[r")
if alt {
fmt.Print("\x1b[?1049l")
}
fmt.Printf("\n screen: %s\n height %d -> %d (change %+d)\n\n",
map[bool]string{true: "ALTERNATE", false: "MAIN (the one with scrollback)"}[alt], h, h2, h2-h)
fmt.Println(" Which row number was at the very TOP of the window after you stretched it?")
fmt.Println()
fmt.Println(" ROW 01 -> content did NOT move. I am wrong again.")
fmt.Printf(" blank, or ROW %02d -> content was PUSHED DOWN by the grow. That is the bug.\n", 1)
fmt.Println()
fmt.Println(" (If the top was blank, say so -- that is the same answer as 'pushed down'.)")
}
func max(a, b int) int {
if a > b {
return a
}
return b
}