KetraTerm
API · DevelopmentAll versions

TerminalShellIntegration

Selected producer of a terminal's shell metadata and active editing context.

A session owns observation, not the producer's lifetime. Implementations must not start background jobs during construction. commandLineChanges supports independent subscriptions; the session shares its collection and cancels it when no consumer needs it. state is the bounded terminal-facing projection of the producer's model. Only that producer may write it; OSC reports never supplement a host model.

Host adapters normally use TerminalShellIntegrationFactory.host rather than implement this runtime contract. The optional OSC implementation uses the synchronous protocol callbacks below; they run under session serialization.

Properties

Link copied to clipboard
abstract val commandLineChanges: Flow<Long>

Opaque nonnegative edit revisions; unavailable/equal intermediate states may conflate.

Link copied to clipboard

Whether the host configured this producer to supply prompt markers from startup.

Link copied to clipboard
abstract val promptReady: StateFlow<Boolean>

True only while the shell can accept a startup command at its live prompt.

Link copied to clipboard

Thread-safe command metadata and primitive viewport projection.

Functions

Link copied to clipboard

Current immutable editing context, or null when unavailable; must be safe from any thread.

Link copied to clipboard

Reports a local clear after the active screen and history have been erased. Called synchronously under session mutation serialization, before later output. Invalidate producer-owned anchors for buffer; preserve metadata for the other buffer. Old line identities cannot resolve after this callback. Host models keep ownership of their text, metadata, and notifications. Do not block on UI work, mutate the session, or close it. Exceptions propagate to the clear caller after the grid has changed.

Link copied to clipboard

Optional OSC 133 interpretation, called at the marker's exact output position.

Link copied to clipboard

Optional accepted OSC 7 interpretation. Hosts keep their own directory authority.

Link copied to clipboard
open fun outputProcessed()

Optional synchronous finalization after a parser batch, before startup submission.

Link copied to clipboard
open fun <T> withCommandLine(action: (revision: Long, snapshot: TerminalShellCommandLineSnapshot?) -> T): T?

Runs a short conditional-edit action under the producer's revision guard. The revision must change for every authoritative editing update, including changes away from and back to an equal snapshot. The callback must finish before another producer update can become visible.