or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.md
tile.json

index.mddocs/

0

# Inquirer Confirm

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: @inquirer/confirm

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `npm install @inquirer/prompts` (recommended) or `npm install @inquirer/confirm`

10

11

## Core Imports

12

13

```typescript

14

import confirm from "@inquirer/confirm";

15

```

16

17

Alternative import from prompts bundle:

18

19

```typescript

20

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

21

```

22

23

For CommonJS:

24

25

```javascript

26

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

27

```

28

29

## Basic Usage

30

31

```typescript

32

import confirm from "@inquirer/confirm";

33

34

// Simple confirmation

35

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

36

37

// With default value

38

const deleteFile = await confirm({

39

message: "Delete this file?",

40

default: false

41

});

42

43

// With custom transformer

44

const proceed = await confirm({

45

message: "Proceed with deployment?",

46

transformer: (answer) => answer ? "βœ… Yes" : "❌ No"

47

});

48

```

49

50

## Capabilities

51

52

### Confirm Prompt

53

54

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

55

56

```typescript { .api }

57

/**

58

* Creates a confirmation prompt that captures boolean user input

59

* @param config - Configuration object for the confirm prompt

60

* @param context - Optional context configuration for runtime behavior

61

* @returns Promise resolving to boolean user response

62

*/

63

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

64

65

interface ConfirmConfig {

66

/** The question to ask the user */

67

message: string;

68

/** Default answer (true or false). Any value other than false is treated as true */

69

default?: boolean;

70

/** Function to transform the boolean result into a custom display string */

71

transformer?: (value: boolean) => string;

72

/** Theme customization object for styling the prompt */

73

theme?: PartialDeep<Theme>;

74

}

75

```

76

77

**Usage Examples:**

78

79

```typescript

80

import confirm from "@inquirer/confirm";

81

82

// Basic confirmation with default true

83

const answer1 = await confirm({ message: "Do you want to proceed?" });

84

// Displays: ? Do you want to proceed? (Y/n)

85

86

// Confirmation with default false

87

const answer2 = await confirm({

88

message: "Delete all files?",

89

default: false

90

});

91

// Displays: ? Delete all files? (y/N)

92

93

// With custom response transformation

94

const answer3 = await confirm({

95

message: "Save changes?",

96

transformer: (value) => value ? "Saved!" : "Discarded"

97

});

98

// On completion shows: βœ” Save changes? Saved! (or Discarded)

99

```

100

101

## Context Options

102

103

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

104

105

```typescript { .api }

106

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

107

108

interface ContextOptions {

109

/** The stdin stream (defaults to process.stdin) */

110

input?: NodeJS.ReadableStream;

111

/** The stdout stream (defaults to process.stdout) */

112

output?: NodeJS.WritableStream;

113

/** If true, clear the screen after the prompt is answered */

114

clearPromptOnDone?: boolean;

115

/** An AbortSignal to cancel prompts asynchronously */

116

signal?: AbortSignal;

117

}

118

```

119

120

**Context Usage Example:**

121

122

```typescript

123

import confirm from "@inquirer/confirm";

124

125

const answer = await confirm(

126

{ message: "Deploy to production?" },

127

{

128

clearPromptOnDone: true,

129

signal: AbortSignal.timeout(10000) // Timeout after 10 seconds

130

}

131

);

132

```

133

134

## Input Handling

135

136

The prompt accepts various input formats:

137

138

- **Yes responses**: Any input starting with `y` or `yes` (case insensitive, matches `/^(y|yes)/i`)

139

- **No responses**: Any input starting with `n` or `no` (case insensitive, matches `/^(n|no)/i`)

140

- **Empty input**: Uses the `default` value (true if not specified)

141

- **Invalid input**: Falls back to the `default` value

142

143

## Theme System

144

145

The prompt supports comprehensive theming through the `theme` configuration option.

146

147

```typescript { .api }

148

interface Theme {

149

/** Prefix shown before the message, can be string or status-specific object */

150

prefix: string | Prettify<Omit<Record<Status, string>, 'loading'>>;

151

/** Spinner configuration for loading states */

152

spinner: {

153

/** The time interval between frames, in milliseconds */

154

interval: number;

155

/** A list of frames to show for the spinner */

156

frames: string[];

157

};

158

/** Styling functions for different text elements */

159

style: {

160

/** Style function for the final answer display */

161

answer: (text: string) => string;

162

/** Style function for the message text */

163

message: (text: string, status: Status) => string;

164

/** Style function for error messages */

165

error: (text: string) => string;

166

/** Style function for the default value indicator */

167

defaultAnswer: (text: string) => string;

168

/** Style function for help text */

169

help: (text: string) => string;

170

/** Style function for highlighted text */

171

highlight: (text: string) => string;

172

/** Style function for keyboard keys referred to in help texts */

173

key: (text: string) => string;

174

};

175

}

176

177

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

178

179

type PartialDeep<T> = T extends object

180

? {

181

[P in keyof T]?: PartialDeep<T[P]>;

182

}

183

: T;

184

185

type Prettify<T> = {

186

[K in keyof T]: T[K];

187

} & {};

188

```

189

190

**Theme Usage Example:**

191

192

```typescript

193

const answer = await confirm({

194

message: "Deploy to production?",

195

theme: {

196

prefix: "πŸš€",

197

style: {

198

answer: (text) => `>>> ${text} <<<`,

199

message: (text, status) =>

200

status === "done" ? `βœ… ${text}` : `❓ ${text}`,

201

defaultAnswer: (text) => `[${text}]`

202

}

203

}

204

});

205

```

206

207

## Default Behavior

208

209

- **Default value**: `true` when not specified (`config.default !== false` means undefined defaults to true)

210

- **Display format**: Shows `(Y/n)` when default is not `false`, `(y/N)` when default is `false`

211

- **Transformer**: Uses built-in transformer that returns `"yes"` for true, `"no"` for false

212

- **Theme**: Uses Inquirer's default theme with standard prefixes and styling

213

214

## Return Value

215

216

The function returns a `Promise<boolean>`:

217

- `true` for affirmative responses or when default is true and no specific input is provided

218

- `false` for negative responses or when default is false and no specific input is provided