KetraTerm
API · DevelopmentAll versions

TerminalShellIntegrationState

class TerminalShellIntegrationState(capacity: Int = DEFAULT_CAPACITY, maxCommandTextLength: Int = 4096, epochMillis: () -> Long = System::currentTimeMillis) : TerminalShellIntegrationView

Bounded, protocol-neutral terminal projection of shell commands and prompts.

This model intentionally lives outside terminal core. Core owns bytes already committed to the terminal grid; shell commands and prompts are host metadata about prompt and command lifecycle. Records are anchored to stable core line identities, not absolute row numbers, so scrollback movement and resize reflow do not detach decorations from the content they describe.

Storage is data-oriented: each command field is a primitive column, records are append-only until bounded eviction, and paint paths consume only projected primitive arrays. One selected shell integration owns publication to this model; it may interpret terminal protocols or adapt a host's existing shell model. Readers never need to know which integration produced the records.

All methods are thread-safe. The producer must serialize its publications, including synchronous listener delivery, to preserve lifecycle event order. Concurrent producers retain storage safety but have no notification ordering guarantee. Observers and revision collectors run outside the storage lock.

Parameters

capacity

maximum retained command records before oldest-record eviction.

maxCommandTextLength

maximum retained UTF-16 command-text length per record; longer extracted text is stored as unknown.

epochMillis

Unix epoch-millisecond source sampled for command metadata, including abandonment. Hosts may supply their metadata clock domain; these wall-clock timestamps do not measure elapsed duration.

Constructors

Link copied to clipboard
constructor(capacity: Int = DEFAULT_CAPACITY, maxCommandTextLength: Int = 4096, epochMillis: () -> Long = System::currentTimeMillis)

Properties

Link copied to clipboard
open override val revision: StateFlow<Long>

Invalidation signal for prompt, command, and current-directory metadata.

Functions

Link copied to clipboard

Observes future explicit command completions without replay or conflation.

Link copied to clipboard
open override fun addCurrentWorkingDirectoryListener(listener: (String) -> Unit): AutoCloseable

Observes future changed directory URIs synchronously, without replay.

Link copied to clipboard
fun clear()

Clears all stored prompt and command timeline records.

Link copied to clipboard
open override fun commandAnchorLineId(recordId: Int): Long

Returns the preferred navigation anchor line for recordId.

Link copied to clipboard

Returns an immutable metadata snapshot for recordId.

Link copied to clipboard
open override fun commandRecordIdAtLine(lineId: Long): Int

Returns the retained command record that owns lineId.

Link copied to clipboard
open override fun commandText(recordId: Int): String?

Returns the retained command text for recordId.

Link copied to clipboard
open override fun commandWorkingDirectoryUri(recordId: Int): String?

Returns the working-directory URI snapshotted when recordId began.

Link copied to clipboard
open override fun copyCommandBlockRange(recordId: Int, destination: LongArray, destinationOffset: Int = 0): Boolean

Copies the selectable prompt/input-and-output line range for recordId.

Link copied to clipboard
open override fun copyCommandOutputRange(recordId: Int, destination: LongArray, destinationOffset: Int = 0): Boolean

Copies the command-output line range for recordId.

Link copied to clipboard
open override fun copyRecords(recordIds: IntArray, lifecycleStates: IntArray, promptStartLineIds: LongArray, promptEndLineIds: LongArray, commandStartLineIds: LongArray, commandEndLineIds: LongArray, exitCodes: IntArray, destinationOffset: Int, maxRecords: Int): Int

Copies retained shell command records into caller-owned primitive arrays.

Link copied to clipboard
open override fun copyViewport(lineIds: LongArray, rowCount: Int, promptStarts: BooleanArray, commandStarts: BooleanArray, commandEnds: BooleanArray, commandRecordIds: IntArray, commandLifecycleStates: IntArray, failedCommandRails: BooleanArray? = null, destinationOffset: Int = 0)

Copies projected shell decorations for a visible viewport.

Link copied to clipboard
open override fun currentWorkingDirectoryUri(): String?

Returns the latest recorded directory URI, or null before one is recorded.

Link copied to clipboard
open override fun hasRunningCommand(): Boolean

Returns true while shell integration reports a command between command-start and command-finished events.

Link copied to clipboard
open override fun latestCommandRecordId(): Int

Returns the newest retained command record id, skipping prompt-only records.

Link copied to clipboard
open override fun nextCommandRecordId(recordId: Int): Int

Returns the next retained command record after recordId.

Link copied to clipboard
open override fun nextCommandRecordIdAfterLine(lineId: Long): Int

Returns the nearest retained command record after lineId.

Link copied to clipboard
open override fun previousCommandRecordId(recordId: Int): Int

Returns the previous retained command record before recordId.

Link copied to clipboard
open override fun previousCommandRecordIdBeforeLine(lineId: Long): Int

Returns the nearest retained command record before lineId.

Link copied to clipboard

Corrects the active prompt's visual start to lineId.

Link copied to clipboard
fun recordCommandFinished(lineId: Long, exitCode: Int?)

Records command completion.

Link copied to clipboard
fun recordCommandStart(lineId: Long, includeLine: Boolean, commandText: String? = null, workingDirectoryUri: String? = null)

Records command execution start.

Link copied to clipboard
open override fun recordCount(): Int

Returns the current number of retained shell command records.

Link copied to clipboard

Records the latest host-validated current-working-directory URI.

Link copied to clipboard
fun recordPromptEnd(lineId: Long)

Records the end of the active shell prompt.

Link copied to clipboard
fun recordPromptStart(lineId: Long)

Records the start of a shell prompt.