CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-clack--core

Low-level primitives for building command-line interface applications with customizable prompt components.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

confirmation.mddocs/

Confirmation Prompts

Simple yes/no confirmation functionality for binary choices.

Capabilities

Confirm Prompt

Binary yes/no confirmation prompt with customizable active/inactive labels.

/**
 * Prompt for yes/no confirmation with customizable labels
 */
class ConfirmPrompt extends Prompt<boolean> {
  constructor(opts: ConfirmOptions);
  
  /** Current cursor position (0 for true, 1 for false) */
  cursor: 0 | 1;
}

/**
 * Configuration options for ConfirmPrompt
 */
interface ConfirmOptions extends PromptOptions<ConfirmPrompt> {
  /** Label for the true/yes option */
  active: string;
  /** Label for the false/no option */
  inactive: string;
  /** Initial boolean value to select */
  initialValue?: boolean;
}

Usage Examples:

import { ConfirmPrompt, isCancel } from '@clack/core';

// Basic yes/no confirmation
const confirmPrompt = new ConfirmPrompt({
  render() {
    const yesSelected = this.cursor === 0;
    const noSelected = this.cursor === 1;
    return `Do you want to continue?\n${yesSelected ? '→' : ' '} ${this.active}\n${noSelected ? '→' : ' '} ${this.inactive}`;
  },
  active: 'Yes',
  inactive: 'No'
});

const shouldContinue = await confirmPrompt.prompt();
if (isCancel(shouldContinue)) {
  process.exit(0);
}

// Confirmation with custom labels and initial value
const deleteConfirmPrompt = new ConfirmPrompt({
  render() {
    const deleteSelected = this.cursor === 0;
    const cancelSelected = this.cursor === 1;
    const deleteStyle = deleteSelected ? '\x1b[31m→ Delete\x1b[39m' : '  Delete';
    const cancelStyle = cancelSelected ? '\x1b[32m→ Cancel\x1b[39m' : '  Cancel';
    return `⚠️  This will permanently delete all files!\n${deleteStyle}\n${cancelStyle}`;
  },
  active: 'Delete',
  inactive: 'Cancel',
  initialValue: false // Default to 'Cancel' for safety
});

const confirmDelete = await deleteConfirmPrompt.prompt();

// Installation confirmation
const installPrompt = new ConfirmPrompt({
  render() {
    const installSelected = this.cursor === 0;
    const skipSelected = this.cursor === 1;
    return `Install dependencies now?\n${installSelected ? '●' : '○'} ${this.active}\n${skipSelected ? '●' : '○'} ${this.inactive}`;
  },
  active: 'Install now',
  inactive: 'Skip for now',
  initialValue: true
});

const shouldInstall = await installPrompt.prompt();

// Simple boolean confirmation
const overwritePrompt = new ConfirmPrompt({
  render() {
    const value = this.cursor === 0 ? this.active : this.inactive;
    return `File already exists. Overwrite? ${value}`;
  },
  active: 'Yes',
  inactive: 'No'
});

const overwrite = await overwritePrompt.prompt();

docs

advanced-selection.md

base-prompt.md

confirmation.md

index.md

selection.md

text-input.md

utilities.md

tile.json