terminal_helpers.ts

view source

Declarations
#

14 declarations

format_terminal_command
#

terminal_helpers.ts view source

(command: string, args: readonly string[]): string import {format_terminal_command} from '@fuzdev/zzz/terminal_helpers.js';

Formats a command and its args as the line typed into the terminal's shell. Each arg follows a space, except one that starts with whitespace, which carries its own separator — how parse_terminal_command keeps a typed line verbatim.

command

type string

args

type readonly string[]

returns

string

parse_terminal_command
#

terminal_helpers.ts view source

(text: string): { command: string; args: string[]; } | null import {parse_terminal_command} from '@fuzdev/zzz/terminal_helpers.js';

Splits a typed command line, trimmed, into its first whitespace-delimited word — the command, used for display and a preset's default name — and the rest of the line verbatim, whitespace separator included, as the one arg. The terminal types the line into sh (see format_terminal_command), so nothing is parsed here: quotes, comments, and unterminated lines are the shell's to interpret, and the line it gets is exactly the trimmed line that was typed.

text

type string

returns

{ command: string; args: string[]; } | null

the command and args, or null for a blank line

TERMINAL_ACK_DELAY
#

terminal_helpers.ts view source

100 import {TERMINAL_ACK_DELAY} from '@fuzdev/zzz/terminal_helpers.js';

How long (ms) consumed output under the threshold waits to be acked.

TERMINAL_ACK_RETRY_DELAY
#

terminal_helpers.ts view source

1000 import {TERMINAL_ACK_RETRY_DELAY} from '@fuzdev/zzz/terminal_helpers.js';

How long (ms) before a failed ack is sent again.

TERMINAL_ACK_THRESHOLD_BYTES
#

terminal_helpers.ts view source

number import {TERMINAL_ACK_THRESHOLD_BYTES} from '@fuzdev/zzz/terminal_helpers.js';

Consumed output a terminal acks at once rather than after TERMINAL_ACK_DELAY — see TerminalOutputAcker.

It must not exceed the backend's low-water mark (256 KiB, the unacked output at or under which a paused terminal reads again). While the backend holds a terminal paused, more than that mark is unacked; so a client that has consumed everything it was sent has at least this much waiting, and acks at once instead of leaving the process blocked for the delay. The cross-backend terminal suite pins the relation against the backend.

TERMINAL_INPUT_PENDING_MAX_LENGTH
#

terminal_helpers.ts view source

number import {TERMINAL_INPUT_PENDING_MAX_LENGTH} from '@fuzdev/zzz/terminal_helpers.js';

Max characters of input queued per terminal while a send is in flight or waiting to retry. Input past this is refused and surfaced, not queued.

TERMINAL_LOST_TO_RESTART_MESSAGE
#

terminal_helpers.ts view source

"lost: zzzd restarted, ending this terminal" import {TERMINAL_LOST_TO_RESTART_MESSAGE} from '@fuzdev/zzz/terminal_helpers.js';

Why a terminal is lost when a session snapshot from a restarted backend lacks it.

TERMINAL_LOST_WHILE_DISCONNECTED_MESSAGE
#

terminal_helpers.ts view source

"lost: the terminal ended while the connection was down" import {TERMINAL_LOST_WHILE_DISCONNECTED_MESSAGE} from '@fuzdev/zzz/terminal_helpers.js';

Why a terminal is lost when a session snapshot from the same backend lacks it — it exited, or was closed from another tab, while the connection was down.

TERMINAL_NOT_FOUND_MESSAGE
#

terminal_helpers.ts view source

"lost: the backend no longer has this terminal — zzzd may have restarted" import {TERMINAL_NOT_FOUND_MESSAGE} from '@fuzdev/zzz/terminal_helpers.js';

Why a terminal is lost when the backend answers not_found for it.

TERMINAL_OUTPUT_MAX_LENGTH
#

terminal_helpers.ts view source

1000000 import {TERMINAL_OUTPUT_MAX_LENGTH} from '@fuzdev/zzz/terminal_helpers.js';

Max characters of output kept per terminal for replay into a (re)mounted view. Counted in UTF-16 code units — about 1-2 MB of memory. The oldest output is dropped first.

TerminalAckOutcome
#

terminal_helpers.ts view source

TerminalAckOutcome

type "ok" | "retry" | "stop"

import type {TerminalAckOutcome} from '@fuzdev/zzz/terminal_helpers.js';

How a terminal_ack ended: ok, retry (it failed and is worth sending again), or stop (the backend no longer has the terminal).

TerminalOutputAcker
#

terminal_helpers.ts view source

import {TerminalOutputAcker} from '@fuzdev/zzz/terminal_helpers.js';

Batches one terminal's output acks. The backend stops reading a terminal whose output runs too far ahead of what this client has acked, so acks must keep up with consumption without doubling the message rate.

Counts are the backend's: each terminal_data carries sent_bytes, the terminal's running output total, and an ack echoes the sent_bytes of the last chunk consumed. Acks are cumulative, so a lost one is covered by the next.

An ack is sent at once when threshold_bytes of consumed output are waiting, and after delay when fewer are — so the last of a burst is always acked. At most one ack is in flight: output consumed meanwhile waits for it to return and is then acked by the same rule, so under a flood acks go out per threshold_bytes consumed, not per round trip (each ack is a request the backend runs in a transaction).

Acks can't stall a terminal the backend has paused, as long as threshold_bytes is at most the backend's low-water mark (see TERMINAL_ACK_THRESHOLD_BYTES): once everything sent is consumed, at least the threshold is waiting, and the ack goes out at once or as soon as the one in flight returns. delay bounds every other case. Not reactive.

constructor

type new (options: TerminalOutputAckerOptions): TerminalOutputAcker

options

consumed

Records that output through sent_bytes has been consumed. Counts only move forward — a lower value is ignored.

type (sent_bytes: number): void

sent_bytes

type number
returns void

flush

Acks what's been consumed now, unless an ack is in flight (what it leaves is acked when it returns) or nothing is waiting.

type (): void

returns void

stop

Stops acking for good — pending and later output is never acked.

type (): void

returns void

acked

The highest sent_bytes an ack has succeeded for.

type number

getter

TerminalOutputAckerOptions
#

terminal_helpers.ts view source

TerminalOutputAckerOptions import type {TerminalOutputAckerOptions} from '@fuzdev/zzz/terminal_helpers.js';

send

Sends a terminal_ack for output consumed through bytes. Must not throw.

type (bytes: number): Promise<TerminalAckOutcome>

bytes

type number
returns Promise<TerminalAckOutcome>

threshold_bytes?

type number

delay?

type number

retry_delay?

type number

TerminalOutputBuffer
#

terminal_helpers.ts view source

import {TerminalOutputBuffer} from '@fuzdev/zzz/terminal_helpers.js';

Bounded buffer of terminal output chunks — keeps about the most recent max_length characters, dropping the oldest first. Not reactive.

Trimming cuts after a newline where the oldest chunk has one past the trim point, and otherwise drops that whole chunk, so a replay starts at a line or chunk boundary rather than at an arbitrary character. Backend chunk boundaries are arbitrary too, so a replay can still start inside an escape sequence — xterm's parser starts in its ground state and prints the tail of the sequence as text.

max_length

type number

readonly

constructor

type new (max_length?: number): TerminalOutputBuffer

max_length

type number
default TERMINAL_OUTPUT_MAX_LENGTH

push

Appends data, then drops the oldest output past max_length.

type (data: string): void

data

type string
returns void

mark_dropped

Records that output was dropped before reaching this buffer, e.g. from a buffer whose content was handed over.

type (): void

returns void

clear

type (): void

returns void

length

Buffered length in UTF-16 code units.

type number

getter

dropped

Whether any output has been dropped to stay under max_length.

type boolean

getter

text

The buffered output as one string. Doesn't merge the stored chunks — trimming drops whole chunks when there's no newline to cut at, so one merged chunk would be dropped all at once.

type string

getter

Imported by
#