Repository navigation
Support terminals without a process and snapshot restore - #785
Merged
Merged
Conversation
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.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-frameis renamed toghostel--commit-frame, since clients also need it when a size arrives in the output stream.