smudgy:widgets
Generated from smudgy v0.3.5 (smudgy-widgets.d.ts @ 9f2a8e811d12). Index: scriptref.
Script-driven UI: build widget trees from the components below (directly or with JSX in a .tsx module) and put them on screen with createWidget. Import from smudgy:widgets.
Mounting widgets
createWidget
export function createWidget(
name: string,
element: SmudgyElement,
options?: CreateWidgetOptions,
): void;
Put a widget on screen (or replace the one already mounted under name).
Re-mounting an existing name keeps its enabled state, and moves the
widget when options.pane changes.
removeWidget
export function removeWidget(name: string): void;
Remove a previously-mounted named widget.
CreateWidgetOptions
export interface CreateWidgetOptions {
pane?: Pane | string;
}
Options for createWidget.
pane— The session pane to mount into: aPanehandle fromsmudgy:core, or a pane name ("main"is the main pane). Defaults to the main pane.
Components
Column
export function Column(props?: ColumnProps, children?: WidgetChildren): SmudgyElement;
A vertical layout. Children are laid out top-to-bottom.
ColumnProps
export interface ColumnProps {
width?: WidgetLength;
height?: WidgetLength;
spacing?: number;
padding?: number;
children?: WidgetChildren;
}
Props common to the linear layout containers.
spacing— Gap between children, in pixels.padding— Padding around the children, in pixels.
Row
export function Row(props?: RowProps, children?: WidgetChildren): SmudgyElement;
A horizontal layout. Children are laid out left-to-right.
RowProps
export type RowProps = ColumnProps;
Stack
export function Stack(props?: StackProps, children?: WidgetChildren): SmudgyElement;
A layering layout. Children are stacked front-to-back.
StackProps
export interface StackProps {
width?: WidgetLength;
height?: WidgetLength;
children?: WidgetChildren;
}
Props for the layering container (children stack front-to-back).
Container
export function Container(props?: ContainerProps, children?: WidgetChildren): SmudgyElement;
A single-child wrapper with alignment/background. Only the first child is used.
ContainerProps
export interface ContainerProps {
width?: WidgetLength;
height?: WidgetLength;
align_x?: HorizontalAlign;
align_y?: VerticalAlign;
background?: string;
children?: WidgetChildren;
}
Props for the single-child wrapper. Only the first child is used.
background— A CSS color string for the background.
Text
export function Text(props?: TextProps, children?: WidgetChildren): SmudgyElement;
A run of (optionally colored) text.
TextProps
export interface TextProps {
color?: string;
size?: number;
children?: WidgetChildren;
}
Props for a run of text. The children are concatenated as the text content.
color— A CSS color string.size— Text size in pixels.
ProgressBar
export function ProgressBar(props?: ProgressBarProps, children?: WidgetChildren): SmudgyElement;
A progress/health bar.
ProgressBarProps
export interface ProgressBarProps {
min?: number;
max?: number;
value?: number;
background?: string;
color?: string;
width?: WidgetLength;
height?: WidgetLength;
vertical?: boolean;
}
Props for a progress/health bar (a leaf – children are ignored).
min— Range minimum (default 0).max— Range maximum (default 100).value— Current value, clamped to [min, max] (default 0).background— A CSS color string for the track background.color— A CSS color string for the filled bar.vertical— Render vertically (width/height are swapped). Default false.
Button
export function Button(props?: ButtonProps, children?: WidgetChildren): SmudgyElement;
A clickable button.
ButtonProps
export interface ButtonProps {
width?: WidgetLength;
height?: WidgetLength;
variant?: ButtonVariant;
onPress?: () => void;
children?: WidgetChildren;
}
Props for a clickable button. A single non-text child is used as the label element; otherwise the text children are rendered as the label.
variant— Emphasis style. Default “subtle”.onPress— Called when the button is pressed.
ButtonVariant
export type ButtonVariant = "primary" | "secondary" | "subtle" | "link";
A button emphasis variant, mapping to the theme's named button styles.
Scrollable
export function Scrollable(props?: ScrollableProps, children?: WidgetChildren): SmudgyElement;
A scrollable single-child viewport. Only the first child is used.
ScrollableProps
export interface ScrollableProps {
width?: WidgetLength;
height?: WidgetLength;
direction?: ScrollDirection;
anchor?: "start" | "end";
children?: WidgetChildren;
}
Props for a scrollable single-child viewport. Only the first child is used.
direction— Scroll axis. Default “vertical”.anchor— Where the view rests. “end” sticks to the bottom (or right, when horizontal) so growing content keeps its newest line visible. Default “start”.
ScrollDirection
export type ScrollDirection = "vertical" | "horizontal" | "both";
A scroll axis. Vertical by default.
Markdown
export function Markdown(props?: MarkdownProps, children?: WidgetChildren): SmudgyElement;
A rendered Markdown document. Children are concatenated as the Markdown source.
MarkdownProps
export interface MarkdownProps {
size?: number;
onLink?: (url: string) => void;
children?: WidgetChildren;
}
Props for a rendered Markdown document. The children are concatenated as the source.
Styling follows the terminal color scheme. Links render as clickable command chips, and code renders monospace on a panel; a fenced block whose opening fence names a language (like js) is syntax-highlighted.
Links can stand in for MUD commands, two ways:
- Command autolink: a bare
<command>renders as a command link that sends that text, so<go north>sendsgo northand<look>sendslook. It is shorthand for[go north](<go north>). Works for word and multi-word commands; a command containing=,/, quotes, or other non-word punctuation (e.g.<say hi!>) is left as literal text; use the explicit form below for those (it also lets the visible label differ from the sent text). - Explicit link:
[label](destination). A bare destination cannot contain spaces ([north gate](go north gate)will not parse), so wrap a spaced destination in angle brackets:[north gate](<go north gate>)sendsgo north gate. The angle-bracket wrapper may not itself contain<,>, or a newline.
Real URLs (<http://...>) stay ordinary links, and inline code / fenced code blocks are
left literal.
size— Base text size in pixels; heading sizes scale from it. Default 16.onLink— Called with a link's URL when it is clicked. Defaults to sending the URL to the current session as if typed.
Modal
export function Modal(props?: ModalProps, children?: WidgetChildren): SmudgyElement;
A modal: a dimmed, input-blocking backdrop under a centered single child.
ModalProps
export interface ModalProps {
onDismiss?: () => void;
background?: string;
children?: WidgetChildren;
}
Props for a modal: a dimmed, input-blocking backdrop under a centered content box. The single child is the content box (style it with a Container).
onDismiss— Called when the backdrop is clicked. If omitted, the backdrop blocks input but does not dismiss.background— A CSS color string for the backdrop. Default translucent black.
TextEditor
export function TextEditor(props?: TextEditorProps, children?: WidgetChildren): SmudgyElement;
A multi-line text editor. Read its text via the onChange callback.
TextEditorProps
export interface TextEditorProps {
id?: string;
value?: string;
onChange?: (text: string) => void;
placeholder?: string;
height?: WidgetLength;
padding?: number;
size?: number;
children?: WidgetChildren;
}
Props for a multi-line text editor (a leaf – children are ignored).
id— A stable identity for the editing buffer: two editors with different ids edit independently. Omitted, sibling editors are still kept distinct.value— The editor's starting text. In-progress edits are preserved; a script reload resets the editor tovalue.onChange— Called with the full text on each edit (not on cursor/selection movements).placeholder— Placeholder shown when empty.height— Viewport height. When set, taller text scrolls. Unset, the editor grows to fit its content.padding— Padding around the text, in pixels.size— Text size in pixels.
MapView
export function MapView(props?: MapViewProps, children?: WidgetChildren): SmudgyElement;
The map view for the current session.
MapViewProps
export interface MapViewProps {
children?: WidgetChildren;
}
Props for the map view (a leaf – props and children are ignored).
Shared types
Element
export type Element = SmudgyElement;
Length
export type Length = WidgetLength;
Children
export type Children = WidgetChildren;
HorizontalAlign
export type HorizontalAlign = "left" | "start" | "center" | "right" | "end";
Horizontal alignment within a container.
VerticalAlign
export type VerticalAlign = "top" | "start" | "center" | "bottom" | "end";
Vertical alignment within a container.
Ambient globals
SmudgyElement
interface SmudgyElement {
readonly __smudgyWidgetElement: true;
}
One piece of on-screen UI, returned by every component below. Build it,
nest it as a child of another component, or mount it with createWidget;
it is not inspectable from JS.
WidgetLength
type WidgetLength = number | "fill" | "shrink";
A size: a number of pixels, "fill" (take all available space), or
"shrink" (hug the contents).
WidgetChild
type WidgetChild = SmudgyElement | string | number | boolean | null | undefined;
Anything a component accepts as a child: another element, text (a string or
number), or null/undefined/false (dropped, so cond && <Text/>
works), plus arrays of the above (flattened).
WidgetChildren
type WidgetChildren = WidgetChild | WidgetChild[];
smudgy:widgets/jsx-runtime
jsx
export function jsx(type: unknown, props: Record<string, unknown>, key?: unknown): SmudgyElement;
The automatic-JSX factory for elements.
jsxs
export function jsxs(type: unknown, props: Record<string, unknown>, key?: unknown): SmudgyElement;
The automatic-JSX factory for elements with multiple children.
Fragment
export function Fragment(props: { children?: WidgetChildren }): SmudgyElement;
Groups children with no wrapper element (<>...</>).
JSX
export namespace JSX {
type Element = SmudgyElement;
// No host string tags -- every JSX tag must be a widget component function.
interface IntrinsicElements {}
interface ElementChildrenAttribute {
children: {};
}
}
The JSX namespace TypeScript resolves for jsxImportSource: "smudgy:widgets".
Default export
WidgetsApi
This describes a type returned from a function on this page. Typically you'll never construct it directly.
interface WidgetsApi {
Column: typeof Column;
Row: typeof Row;
Stack: typeof Stack;
Container: typeof Container;
Text: typeof Text;
ProgressBar: typeof ProgressBar;
Scrollable: typeof Scrollable;
Markdown: typeof Markdown;
Modal: typeof Modal;
TextEditor: typeof TextEditor;
Button: typeof Button;
MapView: typeof MapView;
createWidget: typeof createWidget;
removeWidget: typeof removeWidget;
}
The default export bundles every member above.
Default export
The module's default export (api).
const api: WidgetsApi;
Script API reference · smudgy:core — Sessions & output · smudgy:core — Lines & buffer · smudgy:core — Events · smudgy:core — Automations · smudgy:core — Saved automations · smudgy:core — Panes · Mapper · smudgy:params