Skip to content

windows.state

All a window reports: its views and where each comes from (builtin, manifest, user_init, workspace_init; live: true when live changes made one differ from the declared views, hiddenTabs the declared tabs that window closed), its added commands and bindings, its errors and widgets, its native desktop window (PRT-123, PRT-460, PRT-511, UI-1160).

/** Params naming one window (PRT-123). */
export type WindowRef = {
windowId: number;
};
/** `windows.state` result (PRT-123): all a window reports. */
export type WindowState = {
activeView?: string | null;
client: string;
commands: WindowCommand[];
defaultView?: string | null;
/** Its native desktop window (PRT-460); `null` in a browser. */
desktop: DesktopWindow | null;
/** The errors it shows of init files (UI-304). */
fileErrors: FileErrorReport[];
focused: boolean;
threadId?: string | null;
views: WindowView[];
/** The workspace and user widgets of its current view (PRT-043). */
widgets: WidgetReport[];
windowId: number;
workspaceId?: string | null;
};
/** A command registered beyond the built-ins (PRT-122). */
export type WindowCommand = {
aliases?: string[];
/** The keys bound to it, in every mode. */
bindings?: WindowBinding[];
/** Whether it runs now (a command may disable itself). */
enabled: boolean;
id: string;
source: CommandSource;
title: string;
/** The widget reference that registered it; `null` for an init file's. */
widget?: string | null;
};
/**
* The native window of an `omfp desktop` window (PRT-460, UI-1231, UI-1232), as its shell made it: the machine and
* process of the shell (every window of a data directory shares the process) and the window's current title, unique
* among the windows of the process. The window manager's list of windows finds it by `pid` and `title`; the title
* follows the window's thread, so read it right before matching.
*/
export type DesktopWindow = {
/** The host name of the machine the shell runs on. */
host: string;
/** The shell's process id. */
pid: number;
/** The native window's current title, `<thread or view> — omfp · <n>` or `omfp · <n>` (UI-1231). */
title: string;
};
/** One runtime error a window shows of an init file (UI-304). */
export type FileErrorReport = {
/** `user` for the user's init file, else `.omfp/init.ts`. */
file: string;
/** The error as the window shows it: a compile error with `file:line:column`, a throw, a render or layout error. */
message: string;
};
/** One view of a window (PRT-122). */
export type WindowView = {
/** The titles of the tabs the init files declare that this window closed in it (UI-1130, PRT-511). */
hiddenTabs?: string[];
id: string;
/** `true` while live changes make it differ from what the init files declare (UI-1133, PRT-511). */
live?: boolean;
source: ViewSource;
title: string;
/** The widget references of its layout. */
widgets: string[];
};
/** One widget instance as a window shows it (PRT-043). */
export type WidgetReport = {
/** Console errors and uncaught errors whose stack names the widget's module, oldest first. */
console: string[];
/** The compile stand-in's, import's and error boundary's errors (`file:line:column: message` when known). */
errors: string[];
/** The node's `instance` prop when it is a string, else its reference. */
instance: string;
/** Its `useJob` jobs (AGT-019). */
jobs: WidgetJobReport[];
/** The widget folder's name. */
name: string;
/** The view node's reference (`./widgets/tests`, or `omfp:<name>` overridden by the workspace). */
reference: string;
source: WidgetSource;
state: WidgetReportState;
/** The text the widget renders. */
text: string;
/** The folder version the window imported; `null` while nothing is imported. */
version?: string | null;
};
/** A key binding of a command (PRT-122). */
export type WindowBinding = {
args?: string[];
/** Tokens separated by spaces, e.g. `g h`. */
keys: string;
mode: KeymapMode;
};
/** Who registered a command of a window (PRT-122). */
export type CommandSource =
| "user_init" | "workspace_init"
/** A workspace or user widget (`widget` names it). */
| "widget";
/** Where a view of a window comes from (PRT-122). */
export type ViewSource =
/** The window's built-in default view: the workspace's views manifest has not arrived yet or is invalid. */
| "builtin"
/**
* The workspace's views manifest (its `views/<id>` topic): the views its init files and evals declare
* (`ctx.views.define`), the user's init file's when the workspace declares none, the default manifest when nothing
* declares any, or the live manifest replacing them (`views.set`, mounts); also when a window module changed its
* layout (UI-1160).
*/
| "manifest"
/** Added in this window by a window module the user's init file loads (`ctx.window.load`, `views.use`). */
| "user_init"
/** Added in this window by a window module the workspace's init files load (`ctx.window.load`, `views.use`). */
| "workspace_init";
/** A `useJob` job of a widget instance (AGT-019). */
export type WidgetJobReport = {
command: string;
exitCode?: number | null;
/** How many jobs the instance started for the command. */
runs: number;
signal?: number | null;
startedAt?: number | null;
/** `pending`, `running`, `succeeded` or `failed`. */
status: string;
/** The last output lines (stdout and stderr), oldest first. */
tail: string[];
};
/**
* Where a widget comes from: `workspace` a workspace's declarations (its `views/<id>` topic, served under its id),
* `user` the user host's (the `index` topic's `widgets`, served under the `user` scope, DMN-1290).
*/
export type WidgetSource = "workspace" | "user";
/** Where a widget instance stands in a window (PRT-043). */
export type WidgetReportState = "loading" | "rendered" | "compile_error" | "load_error" | "render_error";
/** The keymap mode a binding belongs to: `normal` (the layer Threads and View mode share), `threads`, `view`, `insert` or `cmdline`. */
export type KeymapMode = "normal" | "threads" | "view" | "insert" | "cmdline";