❯_termy
Developerlibtermy

Ownership and API reference

Find C allocation/free pairs, thread and callback rules, status codes, and the Rust-to-C API map.

The C header is authoritative for signatures and layouts. The Rust exports identify the public Rust API. Generate local Rust documentation for your pinned checkout with cargo doc -p termy_core --no-deps.

API map

TaskRustC
Load user configload_config_from_default_pathtermy_config_load_default
Parse config textload_config_from_contentstermy_config_from_contents
Launch PTYTerminal::new and launch variantstermy_terminal_new_with_options
Create parser without PTYTerminal::new_displaytermy_display_terminal_new
Deliver process outputfeed_outputtermy_terminal_feed_output
Deliver output, return replies in orderfeed_output_with_repliestermy_terminal_feed_output_with_replies
Mirror another terminal without replyingset_protocol_replies_enabled(false)termy_terminal_set_protocol_replies_enabled
Save full terminal stateencode_snapshottermy_terminal_snapshot_encode
Restore full terminal staterestore_snapshottermy_terminal_snapshot_decode, termy_terminal_snapshot_restore
Send input to owned PTYwritetermy_terminal_write
Change dimensionsresizetermy_terminal_resize
Read full compact framesnapshottermy_terminal_snapshot
Consume compact updateframe_updatetermy_terminal_take_frame_update
Consume damage onlytake_damage_snapshottermy_terminal_take_damage
Read rich text and paletterender_read, visitorsNo equivalent rich-cell C API
Encode keyboard eventkeystroke_to_input_with_optionstermy_terminal_encode_key_with_options
Encode mouse eventencode_mouse_reporttermy_terminal_encode_mouse
Drain events and repliesdrain_events with TerminalReplyHosttermy_terminal_drain_events_with_clipboard
Search buffersearch_with_optionstermy_terminal_search_with_options
Find OSC 8 linkhyperlink_attermy_terminal_hyperlink_at
Scroll viewportscroll_display, scroll_to_bottomtermy_terminal_scroll_display, termy_terminal_scroll_to_bottom
Change history limitset_scrollback_historytermy_terminal_set_scrollback_history
Clear historyclear_scrollbacktermy_terminal_clear_scrollback
Plan special glyphsterminal_glyph_plantermy_cells_build_glyph_render_plan
Read image placementskitty_graphics_snapshottermy_terminal_kitty_graphics_placements

C constructors without a config use runtime defaults; they do not implicitly load all of the user's application settings. Choose the config-aware constructor when you want that behavior.

Allocation ownership

Zero-initialize output structs and check the returned status before reading them. Free an existing successful result before reusing its output variable: the next call does not release the previous allocation for you.

Owned resultMatching releaseNested data owned by that result
TermyFfiTerminal *termy_terminal_freeTerminal and wake channel
TermyFfiConfig *termy_config_freeParsed configuration
TermyFfiFrametermy_frame_freeCell array
TermyFfiFrameUpdatetermy_frame_update_freeCell and dirty-span arrays
TermyFfiDamagetermy_damage_freeDirty-span array
TermyFfiGlyphRenderPlantermy_glyph_render_plan_freeEntries, rectangles, strokes
TermyFfiEventBatchtermy_event_batch_freeEvents and each event's payload
TermyFfiSearchBatchtermy_search_batch_freeMatches and each match's line
TermyFfiHyperlinktermy_hyperlink_freeURI bytes
TermyFfiConfigDiagnosticBatchtermy_config_diagnostics_freeDiagnostics and their messages
TermyFfiRenderConfigtermy_render_config_freeFont-family and active-theme bytes
TermyFfiKittyGraphicsBatchtermy_kitty_graphics_batch_freePlacements and their PNG buffers
Standalone TermyFfiBytes (including snapshots and replies)termy_buffer_freeIts byte buffer

Never free a nested byte field separately from its owning batch. Do not edit returned allocation pointers, lengths, or capacities; the free functions need them to reconstruct Rust-owned allocations. Copying an owning C struct does not create another owned allocation: freeing both copies double-frees the same data.

TermyFfiByteSlice is borrowed and has no free function. Its lifetime comes from the call or callback that supplies it. Standalone TermyFfiBytes from an encoder or config string getter is owned; TermyFfiBytes inside a batch belongs to that batch. The containing API determines ownership, not just the field's type.

Threading and shutdown

A TermyFfiTerminal handle is not internally synchronized at the FFI boundary. Serialize every call taking that handle, including reads and encoding calls. Separate handles can be driven independently. The only documented exceptions are termy_terminal_wait_for_wakeup and termy_terminal_notify_wakeup, which access the wake channel rather than terminal state.

A safe shutdown sequence for a host with a waiter is:

  1. Stop scheduling new terminal work and set the host's shutdown flag.
  2. Let any in-flight serialized terminal call finish.
  3. Call termy_terminal_notify_wakeup so the waiter can observe shutdown.
  4. Join the waiter; ensure queued callbacks/tasks cannot access the handle.
  5. Call termy_terminal_free exactly once and clear the host pointer.

Notify alone is insufficient: the waiter must exit rather than immediately waiting again. Never free while any call, including a blocking wait, is still using the handle. Clipboard callbacks cannot re-enter it even on the same thread.

Rust types have their own synchronization and borrowing contracts; the C concurrency rule is not a substitute for reading the Rust method docs. In particular, locked visitors must not re-enter the same terminal.

Status codes

StatusValueInterpretation
TERMY_FFI_OK0Call succeeded; check result fields for empty/no-result cases
TERMY_FFI_NULL1A required pointer was null
TERMY_FFI_INVALID_UTF82Text input was not valid UTF-8
TERMY_FFI_SPAWN_FAILED3Terminal child startup failed
TERMY_FFI_CONFIG_LOAD_FAILED4Configuration could not be loaded
TERMY_FFI_UNKNOWN_KEY5A key/value kind was unsupported by that API
TERMY_FFI_WRITE_FAILED6An operation reporting write failure failed
TERMY_FFI_SERIALIZE_FAILED7Serialization failed
TERMY_FFI_PANICKED8A Rust panic was caught at the ABI boundary
TERMY_FFI_INVALID_ARGUMENT9Arguments were rejected
TERMY_FFI_UNSUPPORTED_SNAPSHOT_VERSION10A snapshot was written by an incompatible format version
TERMY_FFI_INVALID_SNAPSHOT11The bytes are not a snapshot, or it is truncated or corrupt

Not every function returns every status. For example, OK from an encoder can mean no bytes were produced; OK from a search can mean no matches. Function success is not proof that the child has processed input or exited successfully.

On failure, do not consume the output as a successful result. Report the API name and status, and use a controlled teardown/recreation policy after an unexpected panic. Panic catching does not make invalid pointers, mismatched headers, or concurrent handle access safe.

Adjacent host APIs

The header also exposes settings persistence, CLI installation, native config getters, and tmux control helpers. They are not required to embed one terminal. Settings and installation calls have filesystem side effects. A tmux control handle is a different type with its own lifetime: close it with termy_tmux_control_close, release notification batches with termy_tmux_control_notifications_free, and release standalone command output with termy_buffer_free.

Keep session-manager features separate from the terminal frame loop. Use the matching header and implementation when adopting these additional APIs.

On this page