terminals.svelte.ts

view source

Declarations
#

4 declarations

Terminals
#

terminals.svelte.ts view source

import {Terminals} from '@fuzdev/zzz/terminals.svelte.js';

App-level collection of terminal runs — outlives the views that render them, so navigating away and back reattaches to live terminals and their output.

Every terminal spawns a shell (sh) and types its command line into it, so the session stays alive for follow-up input.

After a reconnect, reconcile marks the terminals the backend no longer has as lost (from the session_load snapshot's terminal_ids).

TODO the list is in-memory, so a page reload loses it while the backend PTYs keep running — session_load lists their ids, but reattaching would also need their commands and output.

inheritance

extends: Cell<typeof TerminalsJson>

items

type IndexedCollection<Terminal>

readonly

constructor

type new (options: TerminalsOptions): Terminals

options

get_by_terminal_id

Looks up a terminal by its backend terminal_id.

type (terminal_id: string & $brand<"Uuid">): Terminal | undefined

terminal_id

type Uuid
returns Terminal | undefined

add

Adds a terminal cell without spawning a process. See create to spawn one.

type (json?: { id?: string | undefined; created?: string | undefined; updated?: string | undefined; name?: string | undefined; command?: string | undefined; args?: string[] | undefined; cwd?: string | undefined; ... 4 more ...; preset_id?: string | ... 1 more ... | undefined; } | undefined): Terminal

json?

optional
returns Terminal

create

Adds a terminal and spawns its process. A spawn failure is recorded on the terminal (status: 'failed' + error_message), so this doesn't reject.

type (json: Pick<{ id?: string | undefined; created?: string | undefined; updated?: string | undefined; name?: string | undefined; command?: string | undefined; args?: string[] | undefined; cwd?: string | undefined; ... 4 more ...; preset_id?: string | ... 1 more ... | undefined; }, "name" | ... 3 more ... | "preset_id">): Promise<...>

json

type Pick<TerminalJsonInput, "name" | "command" | "args" | "cwd" | "preset_id">
returns Promise<Terminal>

restart

Closes the terminal's process if it's running, then spawns a fresh one with a new terminal_id and cleared output. Does nothing if the close fails — the error is on the terminal — to avoid orphaning a live process.

type (terminal: Terminal): Promise<void>

terminal

returns Promise<void>

remove

Closes the terminal's process if it's running, then removes and disposes the terminal. Keeps it if the close fails, so the process stays reachable. A terminal removed while starting has its process closed once spawned.

type (terminal: Terminal): Promise<void>

terminal

returns Promise<void>

clear

Removes and disposes every terminal without closing their processes.

type (): void

returns void

receive_output

Routes a terminal_data notification to its terminal, buffering it whether or not a view is mounted.

type (terminal_id: string & $brand<"Uuid">, data: string, sent_bytes: number): void

terminal_id

type Uuid

data

type string

sent_bytes

type number
returns void

receive_exited

Routes a terminal_exited notification to its terminal, recording the exit whether or not a view is mounted.

type (terminal_id: string & $brand<"Uuid">, exit_code: number | null): void

terminal_id

type Uuid

exit_code

type number | null
returns void

running_terminal_ids

The backend ids of the running terminals.

type (): Set<string & $brand<"Uuid">>

returns Set<Uuid>

mark_output_gap

Marks every running terminal as possibly missing output (see Terminal.output_gap) — called when the socket reconnects.

type (): void

returns void

reconcile

Reconciles with the backend's live terminals from a session snapshot: a running terminal it doesn't list is marked lost, since its terminal_exited (if any) was missed.

type (live_terminal_ids: ReadonlySet<string & $brand<"Uuid">>, known_terminal_ids: ReadonlySet<string & $brand<"Uuid">>, reason: string): void

live_terminal_ids

the snapshot's terminal_ids

type ReadonlySet<Uuid>

known_terminal_ids

the ids running when the snapshot was requested; only these are judged, since a terminal started after the request may postdate the snapshot

type ReadonlySet<Uuid>

reason

the lost terminals' error_message

type string
returns void

dispose

type (): void

returns void

TerminalsJson
#

terminals.svelte.ts view source

value + type

{ id: string & $brand<"Uuid">; created: string & $brand<"Datetime">; updated: string & $brand<"Datetime">; items: { id: string & $brand<"Uuid">; ... 10 more ...; cwd?: string | undefined; }[]; } import {TerminalsJson} from '@fuzdev/zzz/terminals.svelte.js';

id

type string & $brand<"Uuid">

created

type string & $brand<"Datetime">

updated

Required and initially equal to created.

type string & $brand<"Datetime">

items

type TerminalJson[]

TerminalsJsonInput
#

terminals.svelte.ts view source

{ id?: string | undefined; created?: string | undefined; updated?: string | undefined; items?: { id?: string | undefined; created?: string | undefined; updated?: string | undefined; name?: string | undefined; ... 7 more ...; preset_id?: string | ... 1 more ... | undefined; }[] | undefined; } import type {TerminalsJsonInput} from '@fuzdev/zzz/terminals.svelte.js';

id?

type string

created?

type string

updated?

Required and initially equal to created.

type string

items?

type TerminalJsonInput[]

TerminalsOptions
#

terminals.svelte.ts view source

TerminalsOptions import type {TerminalsOptions} from '@fuzdev/zzz/terminals.svelte.js';

inheritance

extends: CellOptions<typeof TerminalsJson>

Depends on
#

Imported by
#