Skip to content

@jsvision/ui / createApplication

Function: createApplication()

Documented in: Application

createApplication<O>(opts?): CreatedApplication<O>

Defined in: ui/src/app/application.ts:410

Create a terminal application: assemble the event loop, desktop, optional menu bar/status line, and popup overlay, register the standard window-management commands, and return an Application.

The whole view tree is built and mounted in one pass; the menu bar and status line are wired to the loop after it exists. Populate the returned desktop with windows and call run() to start.

Type Parameters

O

O extends ApplicationOptions = ApplicationOptions

Parameters

opts?

O = ...

All optional: the shared translation service, content (the body — a Desktop by default), caps (auto-detected), viewport/theme/logger/keymap/menu/status/runtime/streams.

Returns

CreatedApplication<O>

The assembled application. With no content it is a DesktopApplication (so app.desktop is a Desktop, no null check); with a content view it is a RouterApplication (app.desktop is undefined).

Example

ts
import { createApplication, Window, menuBar, subMenu, item, statusLine, statusItem, Commands } from '@jsvision/ui';

// Zero-config: capabilities are auto-detected and everything imports from one package.
const bar = menuBar([
  subMenu('~W~indow', [item('~T~ile', Commands.tile), item('~C~ascade', Commands.cascade), item('E~x~it', Commands.quit)]),
]);
const status = statusLine([statusItem('~T~ile', Commands.tile, 'F4'), statusItem('~Q~uit', Commands.quit, 'Alt+X')]);

const app = createApplication({ menuBar: bar, statusLine: status });

const win = new Window('Editor');
win.setLayout({ rect: { x: 1, y: 2, width: 30, height: 8 } });
app.desktop.addWindow(win); // `desktop` is a Desktop here — no `content` was passed

const code = await app.run(); // runs until the 'quit' command; restores the terminal on exit
process.exit(code);