mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
The agent runs in the top rows of one window and the scape paints the rows below it. Not a terminal emulator: the agent's bytes reach the terminal untouched but for the one three-byte sequence that would free it from its band, so nothing the host fails to understand about Claude Code's output can be corrupted by it. internal/host carries the pieces, each measured rather than assumed: - Filter removes DECSTBM from the child's stream. Claude emits ESC[r once at startup, which resets the region to the whole screen and would let its next scroll walk over the scape. Handles the sequence arriving split across reads. - Band splits the window. The agent's rows must start at row 1 -- lines scrolled out of a region reach the scrollback only when the region is top-anchored, measured in Terminal.app: rows 1-10 keeps every line, rows 5-14 keeps none. So the scape reads downward from the agent instead of upward from the bottom. - EnterBand/BeginPaint/EndPaint carry the ordering rules. The cursor is saved before the region is touched because DECSTBM homes it; origin mode is on so the agent's resize-time ESC[H lands in the band rather than on the screen. - openPTY and makeRaw, on stdlib syscalls, so the project keeps its no- dependency rule. Darwin and Linux. main gains 'xscapes inside [command]'. frames.go extracts the frame producer that the live pane and the band now share, so the two cannot drift. The old tmux launcher is untouched and still works.
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
//go:build darwin
|
|
|
|
package host
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
// openPTY opens a pseudo-terminal pair the BSD way: /dev/ptmx hands back a
|
|
// master, then three ioctls grant, unlock and name the slave.
|
|
func openPTY() (*pty, error) {
|
|
m, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("open /dev/ptmx: %w", err)
|
|
}
|
|
if err := ioctl(m.Fd(), syscall.TIOCPTYGRANT, 0); err != nil {
|
|
m.Close()
|
|
return nil, fmt.Errorf("grant pty: %w", err)
|
|
}
|
|
if err := ioctl(m.Fd(), syscall.TIOCPTYUNLK, 0); err != nil {
|
|
m.Close()
|
|
return nil, fmt.Errorf("unlock pty: %w", err)
|
|
}
|
|
var name [128]byte
|
|
if err := ioctl(m.Fd(), syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&name[0]))); err != nil {
|
|
m.Close()
|
|
return nil, fmt.Errorf("name pty: %w", err)
|
|
}
|
|
path := string(bytes.TrimRight(name[:], "\x00"))
|
|
s, err := os.OpenFile(path, os.O_RDWR|syscall.O_NOCTTY, 0)
|
|
if err != nil {
|
|
m.Close()
|
|
return nil, fmt.Errorf("open %s: %w", path, err)
|
|
}
|
|
return &pty{master: m, slave: s}, nil
|
|
}
|