Bunli
Packages

@bunli/runtime

Runtime renderer and prompt primitives for Bunli TUI applications

Overview

@bunli/runtime provides terminal UI rendering capabilities and interactive prompt primitives for Bunli CLI applications. It is primarily used internally by @bunli/tui but also exports types and utilities used by command handlers.

Installation

bun add @bunli/runtime

Most users won't directly use @bunli/runtime. The prompt API is available through the handler context's prompt property, and TUI components are provided by @bunli/tui.

Subpath Exports

The package has 8 subpath exports:

ExportPurpose
@bunli/runtimeRoot - type re-exports only
@bunli/runtime/appReact context providers (RuntimeProvider, RouteStore, CommandRegistry)
@bunli/runtime/rendererTUI renderer (runTuiRender for full-screen TUI apps)
@bunli/runtime/promptPrompt primitives (text, select, confirm, etc.)
@bunli/runtime/optionsTuiRenderOptions and OpenTuiRendererOptions
@bunli/runtime/eventsRuntime event schemas
@bunli/runtime/transportRuntimeTransport interface
@bunli/runtime/imageImage capability detection and rendering

Root Exports (Types Only)

The root package only exports TypeScript types:

import type {
  OpenTuiRendererOptions,
  TuiRenderOptions,
  RuntimeTransport,
  RuntimeTransportObserver,
  RuntimeEvent,
  RuntimeEventType,
} from "@bunli/runtime";

Runtime Events

Runtime events for telemetry and debugging:

type RuntimeEvent =
  | RuntimeRendererStartedEvent
  | RuntimeRendererMissingRenderEvent
  | RuntimeRendererDestroyedEvent
  | RuntimeImageRenderAttemptEvent
  | RuntimeImageRenderResultEvent
  | RuntimePromptStartedEvent
  | RuntimePromptCancelledEvent
  | RuntimeTransportErrorEvent;

TUI Options

interface TuiRenderOptions {
  exitOnCtrlC?: boolean;
  targetFps?: number;
  enableMouseMovement?: boolean;
  useMouse?: boolean;
  bufferMode?: "alternate" | "standard";
}

Image Rendering

Check terminal image capabilities:

import { detectImageCapability, renderImage } from "@bunli/runtime/image";

// Detect what image protocols the terminal supports
const capability = detectImageCapability();
// { supported: true, protocol: 'kitty' }

// Render an image
const result = await renderImage(imageData, {
  protocol: "kitty",
  width: 800,
});

Transport

Custom transport for runtime events:

interface RuntimeTransport {
  send(event: RuntimeEvent): void | Promise<void>;
}

interface RuntimeTransportObserver {
  onTransportError?(error: Error): void;
}

See Also

On this page