Overview

Collect single-line user input.

Import

import { Prompt } from 'nikcli-tui';

Usage

new Prompt({ parent: screen, message: 'Enter value', onSubmit: (v) => {} });

Live Preview

Run Locally

npm run tsx:core-gallery

Props

  • message: string — Prompt message.
  • onSubmit: (value: string) => void — Required submit handler.
  • placeholder?: string — Placeholder text.
  • defaultValue?: string — Initial input value.
  • width?: string | number — Default 70%.
  • height?: number — Default 7.
  • onCancel?: () => void — Esc handler.

Methods

  • setMessage(text), setValue(value), getValue(), setPlaceholder(text), setDefaultValue(value).
  • focus(), blur(), clear(), submit(), cancel().
  • setDimensions(w, h), show(), hide().

Keyboard

  • Enter: submit value.
  • Esc: cancel (if onCancel provided) and close.

Installation

npm i nikcli-tui

Import

import { Prompt } from 'nikcli-tui';

Quick Start

new Prompt({ parent: screen, message: 'Your name?', onSubmit: v => console.log(v) });

Production Examples

const confirm = Prompt.confirm('Proceed?', () => console.log('yes'), () => console.log('no'));

Best Practices

  • Mantieni i prompt brevi; per form multi-campo usa Modal + TextInput.