KetraTerm
API · v0.3.0All versions

TerminalSession

class TerminalSession(val terminal: TerminalBuffer, val renderPublisher: TerminalRenderPublisher, renderReader: TerminalRenderFrameReader, responseReader: TerminalHostResponseReader, connector: TerminalConnector, parser: TerminalOutputParser, inputEncoder: TerminalInputEncoder, hyperlinkResolver: TerminalHyperlinkResolver = TerminalHyperlinkResolver.NONE, outboundWriteLock: Any = Any(), val shellIntegrationState: TerminalShellIntegrationState = TerminalShellIntegrationState(), hostCommandAdapter: HostCommandAdapter? = null, inputPolicy: TerminalInputPolicy = TerminalInputPolicy(), workerDispatcher: CoroutineDispatcher = Dispatchers.Default, ioDispatcher: CoroutineDispatcher = Dispatchers.IO) : TerminalConnectorListener, TerminalInputEncoder, TerminalRenderFrameReader, AutoCloseable

Runtime terminal session that binds core, parser, input encoding, and a transport connector.

The connector owns transport threads. This session owns parser/core mutation serialization and all host-bound write ordering.

A session publishes one active render viewport. Two independently scrolling renderers must use separate sessions so their viewport requests do not race.

Constructors

Link copied to clipboard
constructor(terminal: TerminalBuffer, renderPublisher: TerminalRenderPublisher, renderReader: TerminalRenderFrameReader, responseReader: TerminalHostResponseReader, connector: TerminalConnector, parser: TerminalOutputParser, inputEncoder: TerminalInputEncoder, hyperlinkResolver: TerminalHyperlinkResolver = TerminalHyperlinkResolver.NONE, outboundWriteLock: Any = Any(), shellIntegrationState: TerminalShellIntegrationState = TerminalShellIntegrationState(), hostCommandAdapter: HostCommandAdapter? = null, inputPolicy: TerminalInputPolicy = TerminalInputPolicy(), workerDispatcher: CoroutineDispatcher = Dispatchers.Default, ioDispatcher: CoroutineDispatcher = Dispatchers.IO)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Revision of the active shell command line, tracked only while collected.

Link copied to clipboard

Remote process exit code after onClosed receives one.

Link copied to clipboard

Transport failure reported by onError, or null when the remote closed normally or the session was locally closed.

Link copied to clipboard
val foregroundProcessName: StateFlow<String?>

Best-effort foreground executable name, or null when unavailable.

Link copied to clipboard

Returns true after either local shutdown, remote closure, or transport failure has made the session unable to accept more input.

Link copied to clipboard

Current immutable effective palette, read under the session mutation lock.

Link copied to clipboard
val renderGeneration: StateFlow<Long>

Latest successfully published render generation, or -1 before the first frame is available.

Link copied to clipboard

the render publisher responsible for frame updates.

Link copied to clipboard

shared host-side prompt and command marker state.

Link copied to clipboard

Retained startup submission outcome, or null when no command was configured.

Link copied to clipboard
val state: StateFlow<TerminalSessionState>

Lifecycle state retained for current and future collectors.

Link copied to clipboard

public terminal buffer mutated by host output.

Functions

Link copied to clipboard

Returns the active shell command-line snapshot, when OSC 133 prompt markers provide a trustworthy visible range.

Link copied to clipboard
open override fun close()

Requests local connector shutdown and closes parser input exactly once.

Link copied to clipboard

Returns the latest valid OSC 7 current-working-directory URI.

Link copied to clipboard
open override fun encodeFocus(event: TerminalFocusEvent)

Encodes a focus event and writes it to the connector unless closed.

Link copied to clipboard
open override fun encodeKey(event: TerminalKeyEvent)
Link copied to clipboard
open override fun encodeMouse(event: TerminalMouseEvent)

Encodes a mouse event and writes it to the connector unless closed.

Link copied to clipboard
open override fun encodePaste(event: TerminalPasteEvent)

Encodes a paste event and writes it to the connector unless closed.

Link copied to clipboard

Encodes a complete text replacement under one outbound lock acquisition.

Link copied to clipboard
fun hyperlinkUri(hyperlinkId: Int): String?

Resolves a primitive render-frame hyperlink id to a target URI.

Link copied to clipboard
open override fun onBytes(bytes: ByteArray, offset: Int, length: Int)

Consumes host bytes synchronously, mutating parser/core before returning.

Link copied to clipboard
open override fun onClosed(exitCode: Int?)

Records remote closure and closes the parser exactly once.

Link copied to clipboard
open override fun onError(error: Throwable)

Records transport failure and treats it as remote closure without a process exit code.

Link copied to clipboard
open override fun readRenderFrame(consumer: TerminalRenderFrameConsumer)

Reads a short-lived render frame while holding the terminal mutation lock.

open override fun readRenderFrame(scrollbackOffset: Int, consumer: TerminalRenderFrameConsumer)

Reads a render frame with a specified scrollback offset.

open override fun readRenderFrame(scrollbackOffset: Int, viewportRows: Int, consumer: TerminalRenderFrameConsumer)

Reads a render frame with a specified scrollback offset and viewport rows limit.

Link copied to clipboard
open override fun readRenderFrameForAbsoluteRange(startAbsoluteRow: Long, endAbsoluteRow: Long, consumer: TerminalRenderFrameConsumer)

Reads an absolute terminal row range while holding the mutation lock.

Link copied to clipboard
fun requestRender(scrollbackOffset: Int)

Requests a render-cache publication for a caller-owned scrollback viewport.

fun requestRender(scrollbackOffset: Int, viewportRows: Int)

Requests a render-cache publication with optional render-only viewport overscan rows.

Link copied to clipboard
fun resize(columns: Int, rows: Int, oldScrollbackOffset: Int = 0): Pair<Int, Int>

Resizes core and the active connector, then requests a new published frame.

Link copied to clipboard
fun resizeViewport(columns: Int, rows: Int, oldScrollbackOffset: Int = 0): TerminalViewportResizeResult

Resizes the terminal and connector and captures the viewport anchor and history baseline under the same mutation lock. This keeps viewport resizes ordered with application-requested column switches.

Link copied to clipboard

Updates the current and default cursor shape for the session.

Link copied to clipboard

Updates the active host security policy dynamically.

Link copied to clipboard
open override fun setInputPolicy(policy: TerminalInputPolicy)

Updates the active terminal input policy dynamically.

Link copied to clipboard

Updates only the active paste sanitization policy.

Link copied to clipboard

Sets the theme-configured color palette for the session.

Link copied to clipboard

Applies the host's East Asian Ambiguous width policy for future writes.

Link copied to clipboard
fun start(columns: Int, rows: Int)

Starts the connector after resizing core and transport to columns x rows.