Skip to content

@jsvision/ui / messageBox

Function: messageBox()

messageBox(host, o): Promise<"ok" | "cancel">

Defined in: ui/src/dialog/message-box.ts:211

Show a modal message box and wait for the user to dismiss it.

With the default single OK button the box can still resolve 'cancel'Dialog is closable and Esc-dismissible, and both resolve the modal to Commands.cancel. Callers that only inform the user typically ignore the return value.

Parameters

host

ModalDialogHost

The modal host (an Application, or { loop, desktop, i18n }).

o

MessageBoxOptions

Title, message text, and the button set.

Returns

Promise<"ok" | "cancel">

'ok' when OK is chosen, 'cancel' on Cancel, Esc, or the frame close-box.

Example

ts
import { createApplication, messageBox } from '@jsvision/ui';
import { resolveCapabilities } from '@jsvision/core';

const caps = resolveCapabilities().profile;
const app = createApplication({ caps });

function remove(): void {
  // Delete the selected item.
}

await messageBox(app, { title: 'About', text: 'jsvision — classic terminal UI, reimagined' });
const answer = await messageBox(app, { title: 'Delete?', text: 'This cannot be undone.', buttons: 'okCancel' });
if (answer === 'ok') remove();