or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-api.mdcustom-prompts.mdform-survey-prompts.mdindex.mdselection-prompts.mdspecialized-prompts.mdtext-prompts.md
tile.json

text-prompts.mddocs/

Text Input Prompts

Text input prompts collect textual data from users with various display and input options including basic input, password masking, invisible input, and multiline text.

Capabilities

Input Prompt

Basic text input prompt for collecting user text with optional formatting and validation.

/**
 * Basic text input prompt
 * @param options - Input prompt options
 * @returns Promise resolving to user input string
 */
function input(options);

interface InputOptions extends BasePromptOptions {
  type: 'input';
  initial?: string;
  multiline?: boolean;
}

Usage Examples:

const { prompt } = require('enquirer');

// Simple input
const response = await prompt({
  type: 'input',
  name: 'name',
  message: 'What is your name?'
});

// Input with initial value
const response = await prompt({
  type: 'input',
  name: 'email',
  message: 'Email address?',
  initial: 'user@example.com'
});

// Input with validation
const response = await prompt({
  type: 'input',
  name: 'username',
  message: 'Username (min 3 chars)?',
  validate: value => value.length >= 3 || 'Username must be at least 3 characters'
});

Text Prompt

Multiline text input prompt ideal for longer text content like descriptions or comments.

/**
 * Multiline text input prompt
 * @param options - Text prompt options
 * @returns Promise resolving to user text input
 */
function text(options);

interface TextOptions extends BasePromptOptions {
  type: 'text';
  initial?: string;
  multiline?: boolean;
}

Usage Examples:

// Multiline text input
const response = await prompt({
  type: 'text',
  name: 'description',
  message: 'Enter a description:',
  multiline: true
});

// Single line text (same as input)
const response = await prompt({
  type: 'text', 
  name: 'title',
  message: 'Project title?'
});

Password Prompt

Secure text input prompt that masks user input for sensitive data like passwords.

/**
 * Password input prompt with masked characters
 * @param options - Password prompt options
 * @returns Promise resolving to password string
 */
function password(options);

interface PasswordOptions extends BasePromptOptions {
  type: 'password';
  initial?: string;
}

Usage Examples:

// Basic password prompt
const response = await prompt({
  type: 'password',
  name: 'password',
  message: 'Enter password:'
});

// Password with confirmation
const responses = await prompt([
  {
    type: 'password',
    name: 'password',
    message: 'New password:'
  },
  {
    type: 'password',
    name: 'confirm',
    message: 'Confirm password:',
    validate: (value, state) => {
      return value === state.answers.password || 'Passwords do not match';
    }
  }
]);

Invisible Prompt

Completely hidden input prompt where no characters are displayed, useful for ultra-secure input scenarios.

/**
 * Invisible input prompt with no visual feedback
 * @param options - Invisible prompt options  
 * @returns Promise resolving to user input string
 */
function invisible(options);

interface InvisibleOptions extends BasePromptOptions {
  type: 'invisible';
  initial?: string;
}

Usage Examples:

// Completely hidden input
const response = await prompt({
  type: 'invisible',
  name: 'secret',
  message: 'Enter secret key (no echo):'
});

// Invisible with validation
const response = await prompt({
  type: 'invisible',
  name: 'token',
  message: 'API token:',
  validate: value => value.length === 32 || 'Token must be 32 characters'
});

List Prompt

Text input that accepts comma-separated values and returns an array.

/**
 * Comma-separated list input prompt
 * @param options - List prompt options
 * @returns Promise resolving to array of strings
 */
function list(options);

interface ListOptions extends BasePromptOptions {
  type: 'list';
  initial?: string | string[];
  separator?: string;
}

Usage Examples:

// Comma-separated list
const response = await prompt({
  type: 'list',
  name: 'tags',
  message: 'Enter tags (comma-separated):'
});
// User enters: "javascript, node, cli"
// Result: { tags: ['javascript', 'node', 'cli'] }

// Custom separator
const response = await prompt({
  type: 'list',
  name: 'items',
  message: 'Enter items (pipe-separated):',
  separator: '|'
});

// With initial values
const response = await prompt({
  type: 'list',
  name: 'keywords',
  message: 'Keywords:',
  initial: ['react', 'typescript']
});

Common Options

All text prompts support these common configuration options:

interface CommonTextOptions {
  name: string;
  message: string;
  initial?: string;
  required?: boolean;
  format?(value: string): string | Promise<string>;
  result?(value: string): string | Promise<string>;
  validate?(value: string): boolean | string | Promise<boolean | string>;
  onSubmit?(name: string, value: any, prompt: object): boolean | Promise<boolean>;
  onCancel?(name: string, value: any, prompt: object): boolean | Promise<boolean>;
}

Formatting and Results

Transform input values before they are stored in the answers object:

const response = await prompt({
  type: 'input',
  name: 'name',
  message: 'Name?',
  format: value => value.trim().toLowerCase(),
  result: value => value.charAt(0).toUpperCase() + value.slice(1)
});

Validation

Add validation to ensure input meets requirements:

const response = await prompt({
  type: 'input',
  name: 'email',
  message: 'Email?',
  validate: value => {
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return emailRegex.test(value) || 'Please enter a valid email address';
  }
});