Skip to content

fix(tmux): answer pane queries for the 16 standard colors - #985

Draft
YoanWai wants to merge 5 commits into
mainfrom
fix/pane-palette-colors
Draft

YoanWai wants to merge 5 commits into
mainfrom
fix/pane-palette-colors

Conversation

@YoanWai

@YoanWai YoanWai commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

What changed

  • At startup the manager asks the host terminal for colors 0 to 15 (OSC 4) before the TUI takes the terminal over. One write carries a query per color and a closing device attributes request, so a host that answers costs one round trip. A host that answers nothing is bounded by the existing 200 ms terminal query deadline.
  • The answered colors go into tmux's pane-colours next to window-style, so a pane that asks for color 1 gets the color the host draws it in. A color the host leaves unanswered (mosh, terminals without OSC 4 replies) stays unset. The array is cleared before each write, so it holds only the current host's answers.
  • pane-colours arrived in tmux 3.3. set-option -q skips it on 3.1 and 3.2, the same way extended-keys is set today, so session creation keeps working there.
  • The text color (OSC 10) answers with the theme's text color since fix(ui): paint the theme backdrop so light themes hold on any terminal #678. Checked again on this branch.

What a pane gets back depends on its tmux:

  • tmux 3.6 and later answer all 16 colors and name the index in the reply.
  • tmux 3.3 to 3.5 answer colors 0 to 7, and leave the index out of the reply.
  • tmux 3.1 and 3.2 answer no color queries.

On Windows the host is not queried, so psmux gets no pane-colours.

How it was verified

  • Unit tests for OSC 4 reply parsing (16, 8 and 4 bit channels, BEL and ST, several replies, a reply cut off at the deadline, out of range and malformed answers), for the query exchange over a socket pair (colors answered, only device attributes, a silent host, partial answers), for the tmux command list, and for the pane theme keeping the host palette under every theme.
  • tmux tests on 3.1c, 3.2a, 3.3a, 3.5a and 3.7c. Sessions open with a palette on every version, a pane OSC 4 query gets the declared colors on 3.3a and later, and a color the host stops answering is cleared.
  • Live run of the built binary on an isolated socket, with a pty script standing in for the host terminal and answering OSC 4 for colors 1, 4 and 15. Under tmux 3.7c, printf '\e]4;1;?\a' in a managed pane got \e]4;1;rgb:cccc/2424/1d1d\a, and colors 4 and 15 matched as well. Color 2, which the host left unanswered, got no reply. The same run on main got no OSC 4 reply at all. A host that answers no OSC 4 left pane-colours empty and cleared a value an earlier run had set. Captured rows keep their color indexes (capture-pane -e still shows \e[31m).
  • go test -race ./..., go vet ./..., staticcheck, gofmt and the architecture checks pass.

Closes #684

At startup the manager asks the host terminal for colors 0 to 15 with
OSC 4, one query per color and a closing device attributes request in a
single write, within the existing terminal query deadline. The answered
colors go into tmux's pane-colours, so an agent that asks a pane for one
of them gets the color the host draws it in. A color the host leaves
unanswered stays unset.

pane-colours arrived in tmux 3.3. set-option -q skips it on 3.1 and 3.2,
so session creation keeps working there.
@agent-manager-bot agent-manager-bot Bot added area:themes Settings and themes area:tmux Multiplexer integration size:m 150 to 399 changed lines type:bug Something isn't working labels Nov 3, 2026
…rop what is left

A host that starts answering the OSC 4 queries before the 200 ms deadline
but finishes after it (tmux 3.6 holds the device attributes reply behind a
forwarded color for up to 500 ms, a slow link delivers the rest late) left
its remaining replies on the tty, where Bubble Tea read them as alt+] and a
run of runes typed into whatever input had focus. Once any reply has
arrived the read now waits for the device attributes reply for up to a
second, and the tty's unread input is flushed before the TUI takes over. A
silent host still costs only the deadline.
…ng c

A reply file read while tmux was midway through rgb:cccc/... also ended in
c, so the palette query test could compare a cut-off reply. The skip on
psmux now states only what is known: it has no pane-colours option. The
Palette and QueryPalette docs say what an unopenable tty and Windows do.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:themes Settings and themes area:tmux Multiplexer integration size:m 150 to 399 changed lines type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panes answer the background color but not the text color or the 16 standard colors

1 participant