Table of Contents

smudgy:core — Sessions & output

Generated from smudgy v0.3.5 (smudgy-core.d.ts @ cfcea3b156f6). Index: scriptref.

The basic output functions (echo/send/sendRaw), the current session and other connected sessions, and the profile and app settings. Import from smudgy:core.

echo

export function echo(line: string): void;

Print a line in your session's output window; nothing is sent to the MUD.

send

export function send(command: string): void;

Send a command to the MUD as if you typed it: aliases run, and the command separator (e.g. ;) splits it into multiple commands.

sendRaw

export function sendRaw(text: string): void;

Send text to the MUD exactly as given: no alias processing, no splitting on the command separator.

reload

export function reload(): void;

Reload the current session's scripts and automations.

session

export const session: Session;

The session your script is running in.

id

export const id: number;

Your session's numeric id.

Session

export interface Session {
  readonly id: number;
  readonly profile: Profile;
  echo(line: string): void;
  send(line: string): void;
  sendRaw(line: string): void;
  reload(): void;
  readonly mainPane: Pane;
  readonly panes: PaneRegistry;
  toString(): string;
}

A MUD session. Every method acts on the session the handle names, which need not be the one your script is running in: session is your own, and getSessions / byName reach any connected one, so byName("scout")?.send("look") drives another character.

On a session other than your own, panes can be split, closed, and written to, but not listed or looked up.

getSessions

export function getSessions(): Session[];

All connected sessions.

import { getSessions, createAlias } from "smudgy:core";
// Typing "*<anything>" sends that command to every connected session.
createAlias("broadcast", /^\*(?<command>.*)$/, ({ command }) => {
  for (const s of getSessions()) s.send(command);
});

byName

export function byName(name: string): Session | undefined;

The first connected session whose profile name is name. Returns undefined if no match is found.

getProfile

export function getProfile(): Profile;

Your session's profile.

Profile

export interface Profile {
  name?: string;
  subtext?: string;
}

The name and subtext (caption) associated with a session.

getSettings

export function getSettings(): Settings;

The current app settings as set in the preferences window. Read-only.

Settings

export interface Settings {
  commandSeparator: string;
  rawLinePrefix: string;
  scrollbackLength: number;
  terminalFontFamily: string;
  terminalFontSize: number;
  terminalLineLength?: number;
  theme: string;
  commandInputBehavior: "selectAllClearOnBlur" | "selectAll" | "clear";
  palette?: Palette;
}

The read-only app settings returned by getSettings. Only display and behavior settings are exposed. palette can be briefly absent right after a session starts.

Palette

export interface Palette {
  ansi: string[];
  foreground: string;
  background: string;
  echo: string;
  warn: string;
  output: string;
  selection: string;
  inputBackground: string;
  accent?: string;
}

The terminal's color scheme, as #rrggbb hex strings.

getDataDir

export function getDataDir(): string;

Your script's (or package's) data directory ($DATA), as an absolute path.

vars

export const vars: Record<string, any>;

Variables shared by every script on this server, persisted across reloads and characters. Read and write plain properties:

import { vars, send } from "smudgy:core";
vars.target = "goblin";        // set it in one script...
send(`kill ${vars.target}`);   // ...use it in another

These are internally stored as JSON, so only valid JSON types will persist.

mapper

export const mapper: Mapper;

The current session's map API (see Mapper).

SmudgyApi

export interface SmudgyApi {
  echo(line: string): void;
  send(command: string): void;
  sendRaw(text: string): void;
  reload(): void;
  capture(value: boolean): void;
  byName(name: string): Session | undefined;
  getSessions(): Session[];
  getProfile(): Profile;
  getSettings(): Settings;
  getDataDir(): string;
  readonly userAutomations: UserAutomations;
  on: typeof on;
  once: typeof once;
  emit: typeof emit;
  createAlias: typeof createAlias;
  createTrigger: typeof createTrigger;
  createTriggers: typeof createTriggers;
  createTimer: typeof createTimer;
  createHotkey: typeof createHotkey;
  readonly aliases: AutomationRegistry<Alias>;
  readonly triggers: AutomationRegistry<Trigger>;
  readonly timers: AutomationRegistry<Timer>;
  readonly hotkeys: AutomationRegistry<Hotkey>;
  readonly vars: Record<string, any>;
  readonly line: Line;
  readonly buffer: Buffer;
  readonly mapper: Mapper;
  readonly session: Session;
  readonly id: number;
}

The whole current-session API on one object. Every member mirrors the named export of the same name.

Default export

The module's default export (api).

const api: SmudgyApi;

Script API reference · smudgy:core — Lines & buffer · smudgy:core — Events · smudgy:core — Automations · smudgy:core — Saved automations · smudgy:core — Panes · smudgy:widgets · Mapper · smudgy:params