Commit Graph

2343 Commits

Author SHA1 Message Date
Mitchell Hashimoto
8d21035063 terminal: glyph protocol parser and response encoder
This adds the core parse/encode for the still in-development and experimental
terminal glyph protocol: https://github.com/raphamorim/rio/pull/1542

The only cross-cutting change necessary was changing the APC
identification logic which previously only looked at a single byte to
support multi-byte identifiers since the glyph protocol uses `25a1`.
2026-06-01 10:14:47 -07:00
Mitchell Hashimoto
90175950d5 libghostty-vt: preserve shell prompts on resize by default (#12653)
This PR makes libghostty-vt preserve shell prompts across resize unless
the shell explicitly opts into prompt clearing/redraw with `redraw=1`.
2026-05-29 06:41:23 -07:00
Mitchell Hashimoto
519a612beb libghostty: fix wasm build for selection gesture 2026-05-28 13:00:49 -07:00
Mitchell Hashimoto
3cf01e8445 libghostty: add utf-8 grapheme cell getter to C API
Add a render-state row-cells getter that encodes the current cell's
full grapheme cluster directly as UTF-8 into a caller-provided
GhosttyBuffer. The getter writes the base codepoint first, followed by
any extra grapheme codepoints, and follows the existing buffer-writer
convention where len is bytes written on success or required capacity
on GHOSTTY_OUT_OF_SPACE.

Previously C consumers could query grapheme codepoints, but bindings
that needed UTF-8 text had to reconstruct and encode the cluster
themselves. That duplicated terminal internals in downstream bindings
and made users pay for awkward cross-language struct handling. By
owning the UTF-8/grapheme behavior in libghostty, bindings can use one
stable C API and optionally wrap it with small binding-local helpers.
2026-05-28 12:33:36 -07:00
Mitchell Hashimoto
8beea5f92d libghostty: expose row cell styling bit
Add a render row-cells data key for querying whether the current cell has
explicit styling. This lets consumers avoid fetching a raw cell or full style
snapshot when all they need is the cell's HasStyling bit.

The new key is appended to the existing enum for ABI safety and is served by
the existing row-cells getter path. Existing data keys and function exports are
unchanged.
2026-05-27 21:10:26 -07:00
Mitchell Hashimoto
f730ee0557 libghostty: expose viewport active state
Expose whether the terminal viewport is currently pinned to the active
area through the libghostty-vt terminal data API. Previously embedders
could only infer this from scrollbar geometry, which was indirect and
could require the more expensive scrollbar calculation.

The new GHOSTTY_TERMINAL_DATA_VIEWPORT_ACTIVE value returns the exact
PageList viewport state as a bool. The scroll viewport test now verifies
the value while moving between the active area and scrollback.
2026-05-27 15:24:49 -07:00
Mitchell Hashimoto
4e2d7c314b libghostty: optimize bits for selection gesture validation fields 2026-05-27 11:05:33 -07:00
Mitchell Hashimoto
f0fcb10406 libghostty: selection gesture deep press 2026-05-27 10:57:50 -07:00
Mitchell Hashimoto
603684ba11 libghostty: selection gesture autotick 2026-05-27 10:55:15 -07:00
Mitchell Hashimoto
90fd1ec2e7 libghostty: selection gesture drag events 2026-05-27 10:53:10 -07:00
Mitchell Hashimoto
3fd2c66a04 libghostty: selection gesture release event 2026-05-27 10:49:18 -07:00
Mitchell Hashimoto
5ac8e6569a libghostty: add ghostty_selection_gesture_event 2026-05-27 10:47:26 -07:00
Mitchell Hashimoto
bbfa984aec libghostty: GhosttySelectionGestureEvent 2026-05-27 10:42:29 -07:00
Mitchell Hashimoto
2f61ba036e libghostty: starting the SelectionGesture API, just init/get 2026-05-27 09:02:25 -07:00
Mitchell Hashimoto
68959c5c63 terminal: fix selection gesture edge cases
Selection gestures now treat releases with invalidated anchors as dragged,
so a press that crosses screen boundaries cannot also activate links or
prompt clicks on release. Cell drags that create a same-cell selection also
mark the gesture as dragged, which keeps click-only actions from firing
after a threshold-crossing drag.

Autoscroll now resolves the drag pin after moving the viewport instead of
reusing the pin from before the scroll. This keeps the selection aligned
with the row currently under the pointer. The inspector also validates the
tracked click pin before displaying it so stale pins from inactive screens
are ignored.
2026-05-27 06:58:44 -07:00
Mitchell Hashimoto
7d4d1e5819 terminal: add configurable behaviors based on click count 2026-05-27 06:32:51 -07:00
Mitchell Hashimoto
82a73f2bf1 terminal: SelectionGesture press returns standard behaviors 2026-05-27 06:26:07 -07:00
Mitchell Hashimoto
9b00bb436a terminal: better SelectionGesture docs 2026-05-27 06:20:22 -07:00
Mitchell Hashimoto
f5f9d32d0a terminal: SelectionGesture deep press 2026-05-26 21:36:22 -07:00
Mitchell Hashimoto
df98b6d983 terminal: SelectionGesture autoscrollTick 2026-05-26 21:26:49 -07:00
Mitchell Hashimoto
141c7d44d2 SelectionGesture: release event 2026-05-26 21:17:03 -07:00
Mitchell Hashimoto
229f4c1f4f terminal: SelectionGesture handles word/line drag 2026-05-26 21:04:22 -07:00
Mitchell Hashimoto
c00cdd886b SelectionGesture: drag events 2026-05-26 20:56:49 -07:00
Mitchell Hashimoto
d86ff37a58 terminal: SelectionGesture, but only with mouse press 2026-05-25 15:48:16 -07:00
Mitchell Hashimoto
edf2da0157 libghostty: expose per-cell selection state
Render-state rows already expose their selected range, but
cell-oriented C API consumers had to fetch that row range separately
and duplicate the containment check while rendering.

Add a SELECTED row-cells data kind that carries the row selection into
the row-cells wrapper and returns whether the current cell column is in
that inclusive range. The field remains separate from cell colors and
style so selection stays an explicit render overlay policy.

For performance reasons, the span-based row getter is recommended still
but this is a convenient thing to do for cell-oriented folks.
2026-05-24 20:24:16 -07:00
Mitchell Hashimoto
c5946f4fef libghostty: detach tracked grid refs on free (#12795)
Tracked grid references previously held a raw terminal wrapper pointer
and were required to be freed before the terminal. If callers kept one
past terminal destruction, later tracked-ref calls could dereference
freed terminal or page-list memory before detecting that the reference
was no longer meaningful.

Track live C tracked-grid-ref handles from the terminal wrapper and
detach them before tearing down terminal storage. Detached refs now
report no value through the tracked-ref APIs and can still be freed by
the caller. Update the C API docs to describe this lifetime behavior and
add a regression test for using a tracked ref after terminal free.

This introduces some overhead but tracked pins shouldn't be numerous and
this dramatically improves safety.

No API changes due to this (just more safety).
2026-05-24 14:21:58 -07:00
Mitchell Hashimoto
03df613e39 libghostty: detach tracked grid refs on free
Tracked grid references previously held a raw terminal wrapper pointer and
were required to be freed before the terminal. If callers kept one past
terminal destruction, later tracked-ref calls could dereference freed
terminal or page-list memory before detecting that the reference was no
longer meaningful.

Track live C tracked-grid-ref handles from the terminal wrapper and detach
them before tearing down terminal storage. Detached refs now report no
value through the tracked-ref APIs and can still be freed by the caller.
Update the C API docs to describe this lifetime behavior and add a
regression test for using a tracked ref after terminal free.

This introduces some overhead but tracked pins shouldn't be numerous
and this dramatically improves safety.
2026-05-24 14:13:26 -07:00
Mitchell Hashimoto
2ce5db29ca libghostty: selection formatting 2026-05-24 14:01:35 -07:00
Mitchell Hashimoto
eb777b8036 libghostty: selectWordBetween in C 2026-05-24 13:53:31 -07:00
Mitchell Hashimoto
cc48312c08 libghostty: selection word/line/output/all helpers 2026-05-24 13:42:20 -07:00
Mitchell Hashimoto
847b8afc87 libghostty: remove selection validation, way too expensive 2026-05-23 18:31:20 -07:00
Mitchell Hashimoto
7b49d1f129 terminal: PageList.reset needs to reset page serial mins 2026-05-23 15:32:15 -07:00
Mitchell Hashimoto
ae839393d9 libghostty: add Selection equal and validate 2026-05-23 15:23:39 -07:00
Mitchell Hashimoto
2512fad940 libghostty: move selection functions to selection doxygen group 2026-05-23 15:20:45 -07:00
Mitchell Hashimoto
671c12fad9 libghostty: add selection contains API
Expose a C API for checking whether a GhosttyPoint is inside a
GhosttySelection. The new terminal helper validates the selection snapshot
against the active screen, resolves the point to a grid pin, and delegates
to the internal Selection.contains implementation so C consumers get the
same linear and rectangular selection semantics as Ghostty.

Wire the symbol through the C API exports and public headers, and add a
focused test covering linear containment and rectangular selection behavior.
2026-05-23 15:17:59 -07:00
Mitchell Hashimoto
4a77e81967 libghostty: add selection ordering APIs
Expose selection endpoint ordering through the libghostty-vt C API so
embedders can safely normalize selections whose start and end refs may be
reversed. The new APIs report the current order and return a fresh
untracked selection with forward or reverse bounds.

Selection.Order now uses lib.Enum, matching the existing adjustment enum
pattern and keeping the C ABI enum generated from the same Zig source of
truth. The new functions are wired through the C API re-export and lib-vt
export paths, with coverage for mirrored rectangular selection ordering.
2026-05-23 15:16:04 -07:00
Mitchell Hashimoto
15d8963681 libghostty: add selection adjustment api 2026-05-23 15:12:32 -07:00
Mitchell Hashimoto
24048ffd47 libghostty: expose row-local render selections
Render state already tracks the selected cell range for each viewport row,
but C renderers could only get the full terminal selection. That required
consumers to map global selection pins back into row-local spans themselves.

Add row selection data to the render-state row API. Querying the new row
data returns GHOSTTY_NO_VALUE for unselected rows and writes the inclusive
start and end columns for selected rows. The render example now demonstrates
setting a selection and reading the row-local range while iterating rows.
2026-05-23 15:03:51 -07:00
Mitchell Hashimoto
ae03d3cae4 libghostty: expose get/set active selection state
Add terminal set/get support for the active screen selection through the
existing option and data APIs. Setting a selection copies the C snapshot
into terminal-owned tracked state, while passing NULL clears the current
selection.

Getting the selection now returns an untracked GhosttySelection snapshot
or GHOSTTY_NO_VALUE when there is no selection. The C header documents
the different lifetimes for set and get so embedders know when input and
returned grid references remain valid.
2026-05-23 14:56:39 -07:00
Mitchell Hashimoto
af94eac1e1 libghostty: add tracked grid ref API (#12785)
Add a C API for tracked pins, known as a tracked grid ref in C.

The new API can create tracked refs from terminal points, snapshot them
back to regular grid refs for cell access, convert them to coordinates,
move them to a new point, report when their semantic location was lost,
and free the tracked pin bookkeeping. This is backed by PageList tracked
pins and exposed through the libghostty-vt export layer and headers.
2026-05-23 14:50:19 -07:00
Mitchell Hashimoto
2355550a94 libghostty: add tracked grid ref API
Add a C API for tracked pins, known as a tracked grid ref in C.

The new API can create tracked refs from terminal points, snapshot them
back to regular grid refs for cell access, convert them to coordinates,
move them to a new point, report when their semantic location was lost,
and free the tracked pin bookkeeping. This is backed by PageList tracked
pins and exposed through the libghostty-vt export layer and headers.
2026-05-23 14:37:59 -07:00
Mitchell Hashimoto
a03b52e18b fix: preserve active cursor position during reflow (#12598)
This PR fixes an issue where reflowing could leave the active cursor
attached to a clipped trailing blank cell instead of following the
current write position.
2026-05-22 09:03:52 -07:00
Riccardo Mazzarini
b771a3d4f1 libghostty-vt: preserve shell prompts on resize by default
This PR makes libghostty-vt preserve shell prompts across resize unless
the shell explicitly opts into prompt clearing/redraw with `redraw=1`.
2026-05-11 08:48:25 +02:00
Riccardo Mazzarini
c44afa6250 fix: preserve active cursor position during reflow
This PR fixes an issue where reflowing could leave the active cursor
attached to a clipped trailing blank cell instead of following the
current write position.
2026-05-06 14:56:52 +02:00
Riccardo Mazzarini
3f11e695d0 fix: apply variation selectors to preceding codepoint
This fixes a bug where the variation selectors (VS15 & VS16) were
checked against the first codepoint in a cell instead of the previous
codepoint in the cell's grapheme cluster, causing them to be dropped if
the first codepoint was not a valid base.
2026-05-06 10:45:47 +02:00
Riccardo Mazzarini
c20fcfa1b4 Fix zero-width grapheme attachment during pending wrap
This PR fixes an issue where a zero-width combining mark could attach to
the wrong cell when the preceding character was written in the final
column and the cursor had a pending wrap.
2026-05-04 23:16:41 +02:00
Jon Parise
8b90efd913 os: use GetTempPathW for allocTmpDir on Windows
`allocTmpDir` previously read `%TMP%` via `getenvW` and returned `null`
if the variable wasn't set, requiring each caller to to deal with the
nullable. Unfortunately, there isn't a platform-neutral default value
that makes sense for those cases (i.e. `/tmp` is POSIX-y).

We now use `GetTempPathW` on Windows, which is the official way to get
this directory: `TMP` → `TEMP` → `USERPROFILE` → `GetWindowsDirectoryW`.

With a real system call behind it, the function no longer needs to be
nullable: the only remaining failure modes are OOM (propagated) and the
syscall itself failing or returning data we can't decode. In those later
cases, we use `C:\Windows\Temp` as a fallback, similar to how we use
`/tmp` in the POSIX case.

The Windows path always allocates so it still must be paired with
`freeTmpDir`, which matches the existing contract.
2026-04-25 21:44:37 -04:00
Mitchell Hashimoto
0069e28cc6 libghostty: expose the APC max byte limits 2026-04-20 08:57:51 -07:00
Mitchell Hashimoto
0509f00ad2 terminal/apc: introduce a max_bytes parameter to prevent DoS 2026-04-20 08:53:02 -07:00
Mitchell Hashimoto
83027407e6 terminal: fix memory leak that could happen with invalid Kitty image cmd 2026-04-20 08:45:41 -07:00