Skip to content

Add ghostel-control-mode-function for tmux control mode - #792

Merged
dakra merged 1 commit into
mainfrom
feat/control-mode-hook
Nov 6, 2026
Merged

dakra merged 1 commit into
mainfrom
feat/control-mode-hook

Conversation

@dakra

@dakra dakra commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Adds a hook that hands tmux control mode (tmux -CC) output to another package, so tmux panes can be shown as Emacs buffers without tmux-specific code in ghostel. Refs #116.

What's new

  • ghostel-control-mode-function: called in the terminal's buffer with enter when the control-mode DCS (ESC P 1000 p) opens, data with the next part of its body as a unibyte string, and exit when it closes. Parts split anywhere, also inside a line or a character. While it is nil the body is discarded.

How it works

  • Only the VT parser can tell the frame apart from terminal output, so GhostelHandler intercepts it. Other DCS sequences still reach libghostty's handler.
  • Body bytes are buffered and delivered once per input chunk and when the frame closes, on both the Emacs PTY and the native PTY path.
  • The native event pipe decodes as utf-8-unix instead of the process coding default. With a non-UTF-8 locale the default corrupted UTF-8 event strings and the control-mode body.

Notes

  • A terminal that never sees the frame pays one length check per input chunk.
  • With no function set, the body of a tmux -CC frame is passed to Elisp and dropped there; libghostty used to discard it natively. The terminal shows the same either way.

Testing

  • make -j8 all passes.
  • test/ghostel-control-mode-test.el covers a whole frame, split writes including a split character, every byte value, other DCS sequences, no function set, and a round trip through a real PTY on both backends (POSIX only).
  • Live with real tmux -CC through a package that uses the hook (not published yet): takeover, UTF-8 pane output, resize, detach and reset, on bash, zsh and fish, each on the native and the Emacs PTY path.

A package that shows tmux panes as buffers needs the control-mode
stream that `tmux -CC' writes into an ordinary shell's output.  Its
DCS frame (ESC P 1000 p ... ST) can only be told apart from terminal
output by the VT parser, including on the native PTY reader thread.

GhostelHandler intercepts that frame: dcs_hook with no intermediates,
params [1000] and final `p', then dcs_put and dcs_unhook.  Body bytes
are buffered and delivered once per input chunk and on unhook, on both
inbound paths.  Other DCS sequences still reach the standard handler.

Elisp receives the frame through ghostel-control-mode-function, called
in the terminal's buffer with `enter', `data' and a unibyte string, or
`exit'.  While it is nil the body is discarded.

The native event pipe decodes as utf-8-unix instead of the process
coding default, so the body bytes survive a non-UTF-8 locale.

Refs #116
@dakra
dakra force-pushed the feat/control-mode-hook branch from f45aaa4 to 67928cb Compare November 6, 2026 21:32
@dakra
dakra merged commit 67928cb into main Nov 6, 2026
27 checks passed
@dakra
dakra deleted the feat/control-mode-hook branch November 6, 2026 21:32

This branch was previously deployed

1 inactive deployment
github-pages — 67928cb4 Deployed Nov 6, 2026 by dakra via deploy #252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant