Skip to content

Support terminals without a process and snapshot restore - #785

Merged
dakra merged 5 commits into
mainfrom
feat/processless-term
Nov 4, 2026
Merged

dakra merged 5 commits into
mainfrom
feat/processless-term

Conversation

@dakra

@dakra dakra commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Lets a ghostel buffer run a terminal that has no process, so a client can feed it from its own transport. rexel, a client for the Rex multiplexer, uses this: Rex streams each terminal as a libghostty snapshot followed by the raw PTY bytes, and rexel feeds that into a ghostel buffer.

What's new

  • ghostel-pty-out-function: buffer-local function that receives outbound bytes, meaning typed input and the terminal's own replies.
  • ghostel-resize-function: buffer-local function that receives the fitted rows and columns instead of ghostel resizing the terminal. The terminal resizes when the owner reports the size back in the stream.
  • ghostel-snapshot-restore: replaces the terminal's state with a libghostty snapshot, then reapplies the colors and cell size and schedules a redraw. It refuses a terminal with a native process and must run before the terminal has seen any output.

A restored terminal keeps the host's scrollback and kitty limits and its default modes. If a restore fails, the terminal stays as it was.

ghostel--commit-final-frame is renamed to ghostel--commit-frame, since clients also need it when a size arrives in the output stream.

dakra added 5 commits November 4, 2026 18:47
Outbound bytes of a terminal that has no native process go through
`ghostel--pty-out', which dispatches to the buffer-local
`ghostel-pty-out-function' when set and to the Emacs process
otherwise.  A set hook counts as a live terminal for insert
forwarding, so multiplexer clients can bridge a terminal's I/O over
their own transport.

`ghostel--restore-snapshot' replaces a terminal's state with a
libghostty snapshot: the terminal is decoded and swapped in place, the
renderer rebuilt on it and the snapshot's VT continuation replayed.
`ghostel--encode-snapshot' is its counterpart.
A restored terminal takes the snapshot's scrollback and kitty limits
and reset-mode defaults; those are host policy, so the terminal's own
creation options are re-applied after decoding.

The old terminal and renderer now stay intact until the renderer for
the restored terminal exists, so a failed restore leaves the terminal
as it was instead of a torn-down renderer.
Terminals without a process can have their size owned elsewhere, such
as a multiplexer server that applies a requested size and reports it
back in the stream.  ghostel--adjust-size required a process, so such
buffers got none of its handling: the smallest-window computation
through window-adjust-process-window-size-function, text-scale and
line-spacing refits, the minibuffer rows-only exception, and the
window-removal refit.

Add ghostel-resize-function, the sizing counterpart of
ghostel-pty-out-function.  When set, ghostel--adjust-size accepts the
buffer without a process and hands the fitted rows and columns to the
function instead of resizing the terminal and redrawing; the terminal
resizes when the owner reports the size back.  The same-size check
compares against the reported grid, so the function may be called
repeatedly with the same size until that arrives.
The function renders a terminal whether or not its buffer is displayed
and commits any pending resize, which is also what a size arriving in
an output stream needs, so the name no longer ties it to process exit.
Add the public ghostel-snapshot-restore, which also reapplies the
colors and the cell size and schedules a redraw, so clients no longer
need ghostel's internals for that.  It works in a read-only buffer.

ghostel--restore-snapshot now takes exactly one snapshot and refuses a
terminal with a native process.  A terminal without scrollback drops the
snapshot's history.

Drop ghostel--encode-snapshot, which only tests used.  They restore a
copy of ghostty's snapshot testdata instead, which also fails when a
libghostty bump changes the format.
@dakra
dakra merged commit 1c8abe0 into main Nov 4, 2026
34 of 36 checks passed
@dakra
dakra deleted the feat/processless-term branch November 4, 2026 22:22

This branch was previously deployed

1 inactive deployment
github-pages — 1c8abe0b Deployed Nov 4, 2026 by dakra via deploy #246
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