or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-inquirer--confirm

Interactive command line prompt to gather boolean input from users

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@inquirer/confirm@4.0.x

To install, run

npx @tessl/cli install tessl/npm-inquirer--confirm@4.0.0

index.mddocs/

Inquirer Confirm

Inquirer Confirm provides a simple interactive command line prompt to gather boolean input from users. It's part of the Inquirer.js ecosystem and offers a clean, themeable confirmation prompt that accepts yes/no responses with customizable default values, message transformers, and styling options.

Package Information

  • Package Name: @inquirer/confirm
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @inquirer/prompts (recommended) or npm install @inquirer/confirm

Core Imports

import confirm from "@inquirer/confirm";

Alternative import from prompts bundle:

import { confirm } from "@inquirer/prompts";

For CommonJS:

const confirm = require("@inquirer/confirm");

Basic Usage

import confirm from "@inquirer/confirm";

// Simple confirmation
const shouldContinue = await confirm({ message: "Continue?" });

// With default value
const deleteFile = await confirm({
  message: "Delete this file?",
  default: false
});

// With custom transformer
const proceed = await confirm({
  message: "Proceed with deployment?",
  transformer: (answer) => answer ? "✅ Yes" : "❌ No"
});

Capabilities

Confirm Prompt

Creates an interactive confirmation prompt that captures boolean user input with customizable styling and behavior.

/**
 * Creates a confirmation prompt that captures boolean user input
 * @param config - Configuration object for the confirm prompt
 * @param context - Optional context configuration for runtime behavior
 * @returns Promise resolving to boolean user response
 */
function confirm(config: ConfirmConfig, context?: ContextOptions): Promise<boolean>;

interface ConfirmConfig {
  /** The question to ask the user */
  message: string;
  /** Default answer (true or false). Any value other than false is treated as true */
  default?: boolean;
  /** Function to transform the boolean result into a custom display string */
  transformer?: (value: boolean) => string;
  /** Theme customization object for styling the prompt */
  theme?: PartialDeep<Theme>;
}

Usage Examples:

import confirm from "@inquirer/confirm";

// Basic confirmation with default true
const answer1 = await confirm({ message: "Do you want to proceed?" });
// Displays: ? Do you want to proceed? (Y/n)

// Confirmation with default false
const answer2 = await confirm({
  message: "Delete all files?",
  default: false
});
// Displays: ? Delete all files? (y/N)

// With custom response transformation
const answer3 = await confirm({
  message: "Save changes?",
  transformer: (value) => value ? "Saved!" : "Discarded"
});
// On completion shows: ✔ Save changes? Saved! (or Discarded)

Context Options

All inquirer prompts, including confirm, accept an optional second parameter for context configuration:

function confirm(config: ConfirmConfig, context?: ContextOptions): Promise<boolean>;

interface ContextOptions {
  /** The stdin stream (defaults to process.stdin) */
  input?: NodeJS.ReadableStream;
  /** The stdout stream (defaults to process.stdout) */
  output?: NodeJS.WritableStream;
  /** If true, clear the screen after the prompt is answered */
  clearPromptOnDone?: boolean;
  /** An AbortSignal to cancel prompts asynchronously */
  signal?: AbortSignal;
}

Context Usage Example:

import confirm from "@inquirer/confirm";

const answer = await confirm(
  { message: "Deploy to production?" },
  {
    clearPromptOnDone: true,
    signal: AbortSignal.timeout(10000) // Timeout after 10 seconds
  }
);

Input Handling

The prompt accepts various input formats:

  • Yes responses: Any input starting with y or yes (case insensitive, matches /^(y|yes)/i)
  • No responses: Any input starting with n or no (case insensitive, matches /^(n|no)/i)
  • Empty input: Uses the default value (true if not specified)
  • Invalid input: Falls back to the default value

Theme System

The prompt supports comprehensive theming through the theme configuration option.

interface Theme {
  /** Prefix shown before the message, can be string or status-specific object */
  prefix: string | Prettify<Omit<Record<Status, string>, 'loading'>>;
  /** Spinner configuration for loading states */
  spinner: {
    /** The time interval between frames, in milliseconds */
    interval: number;
    /** A list of frames to show for the spinner */
    frames: string[];
  };
  /** Styling functions for different text elements */
  style: {
    /** Style function for the final answer display */
    answer: (text: string) => string;
    /** Style function for the message text */
    message: (text: string, status: Status) => string;
    /** Style function for error messages */
    error: (text: string) => string;
    /** Style function for the default value indicator */
    defaultAnswer: (text: string) => string;
    /** Style function for help text */
    help: (text: string) => string;
    /** Style function for highlighted text */
    highlight: (text: string) => string;
    /** Style function for keyboard keys referred to in help texts */
    key: (text: string) => string;
  };
}

type Status = "idle" | "done" | "loading";

type PartialDeep<T> = T extends object
  ? {
      [P in keyof T]?: PartialDeep<T[P]>;
    }
  : T;

type Prettify<T> = {
  [K in keyof T]: T[K];
} & {};

Theme Usage Example:

const answer = await confirm({
  message: "Deploy to production?",
  theme: {
    prefix: "🚀",
    style: {
      answer: (text) => `>>> ${text} <<<`,
      message: (text, status) => 
        status === "done" ? `✅ ${text}` : `❓ ${text}`,
      defaultAnswer: (text) => `[${text}]`
    }
  }
});

Default Behavior

  • Default value: true when not specified (config.default !== false means undefined defaults to true)
  • Display format: Shows (Y/n) when default is not false, (y/N) when default is false
  • Transformer: Uses built-in transformer that returns "yes" for true, "no" for false
  • Theme: Uses Inquirer's default theme with standard prefixes and styling

Return Value

The function returns a Promise<boolean>:

  • true for affirmative responses or when default is true and no specific input is provided
  • false for negative responses or when default is false and no specific input is provided