or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdprompt-system.mdquestion-types.mdrender-system.mdshortcuts.mdthemes.md

question-types.mddocs/

0

# Question Types

1

2

Core question classes for different input scenarios. Each question type provides specific validation and interaction patterns optimized for its use case, supporting features like autocompletion, validation, default values, and conditional display.

3

4

## Capabilities

5

6

### Text Input

7

8

Text question for single-line string input with optional autocompletion and validation. Supports dynamic defaults, message formatting, and input validation functions.

9

10

```python { .api }

11

class Text:

12

"""Text input question with optional autocompletion."""

13

14

def __init__(

15

self,

16

name: str,

17

message: str = "",

18

default: str | callable | None = None,

19

autocomplete: list | None = None,

20

validate: callable | bool = True,

21

ignore: bool | callable = False,

22

show_default: bool = False,

23

hints: str | None = None,

24

other: bool = False

25

):

26

"""

27

Create a text input question.

28

29

Args:

30

name: Question identifier for answers dict

31

message: Prompt message to display (can include format strings)

32

default: Default value (string, callable function, or None)

33

autocomplete: List of completion options for tab completion

34

validate: Validation function or boolean (True means always valid)

35

ignore: Skip question if True or callable returns True

36

show_default: Display default value in prompt

37

hints: Help text to display

38

other: Allow "Other" option for custom input

39

"""

40

41

kind = "text"

42

```

43

44

**Usage Example:**

45

46

```python

47

import inquirer

48

49

question = inquirer.Text(

50

'username',

51

message="Enter your username",

52

default="admin",

53

validate=lambda answers, current: len(current) >= 3

54

)

55

```

56

57

### Password Input

58

59

Password question with masked input display. Inherits from Text but hides user input with customizable echo character.

60

61

```python { .api }

62

class Password(Text):

63

"""Password input with masked display."""

64

65

def __init__(

66

self,

67

name: str,

68

echo: str = "*",

69

message: str = "",

70

default: str | callable | None = None,

71

validate: callable | bool = True,

72

ignore: bool | callable = False,

73

show_default: bool = False,

74

hints: str | None = None,

75

other: bool = False

76

):

77

"""

78

Create a password input question.

79

80

Args:

81

name: Question identifier

82

echo: Character to display instead of actual input

83

message: Prompt message to display

84

default: Default value (string, callable function, or None)

85

validate: Validation function or boolean

86

ignore: Skip question if True or callable returns True

87

show_default: Display default value in prompt

88

hints: Help text to display

89

other: Allow "Other" option for custom input

90

"""

91

92

kind = "password"

93

```

94

95

**Usage Example:**

96

97

```python

98

password_q = inquirer.Password(

99

'password',

100

message="Enter your password",

101

echo="•" # Custom echo character

102

)

103

```

104

105

### List Selection

106

107

Single-choice selection from a list of options with keyboard navigation, optional carousel mode, and support for tagged values.

108

109

```python { .api }

110

class List:

111

"""Single-choice selection from list of options."""

112

113

def __init__(

114

self,

115

name: str,

116

message: str = "",

117

choices: list | callable | None = None,

118

hints: str | None = None,

119

default: any = None,

120

ignore: bool | callable = False,

121

validate: callable | bool = True,

122

show_default: bool = False,

123

carousel: bool = False,

124

other: bool = False,

125

autocomplete: list | None = None

126

):

127

"""

128

Create a list selection question.

129

130

Args:

131

name: Question identifier

132

message: Prompt message (can include format strings)

133

choices: List of options (strings, (tag, value) tuples, or callable)

134

hints: Help text to display

135

default: Default selection (can be callable)

136

ignore: Skip question if True or callable returns True

137

validate: Validation function or boolean

138

show_default: Display default value in prompt

139

carousel: Enable wraparound navigation at list ends

140

other: Allow "Other" option for custom input

141

autocomplete: Autocompletion options for filtering

142

"""

143

144

kind = "list"

145

```

146

147

**Usage Example:**

148

149

```python

150

list_q = inquirer.List(

151

'size',

152

message="Select size",

153

choices=[

154

('Small (S)', 'small'),

155

('Medium (M)', 'medium'),

156

('Large (L)', 'large')

157

],

158

carousel=True,

159

default='medium'

160

)

161

```

162

163

### Multiple Choice Selection

164

165

Multiple-choice selection with checkboxes, supporting locked options, carousel navigation, and tagged values.

166

167

```python { .api }

168

class Checkbox:

169

"""Multiple-choice selection with checkboxes."""

170

171

def __init__(

172

self,

173

name: str,

174

message: str = "",

175

choices: list | callable | None = None,

176

hints: str | None = None,

177

locked: list | None = None,

178

default: list | callable | None = None,

179

ignore: bool | callable = False,

180

validate: callable | bool = True,

181

show_default: bool = False,

182

carousel: bool = False,

183

other: bool = False,

184

autocomplete: list | None = None

185

):

186

"""

187

Create a checkbox question.

188

189

Args:

190

name: Question identifier

191

message: Prompt message (can include format strings)

192

choices: List of options (strings, (tag, value) tuples, or callable)

193

hints: Help text to display

194

locked: Choices that cannot be deselected (always checked)

195

default: Initially selected choices (list or callable)

196

ignore: Skip question if True or callable returns True

197

validate: Validation function or boolean

198

show_default: Display default value in prompt

199

carousel: Enable wraparound navigation at list ends

200

other: Allow "Other" option for custom input

201

autocomplete: Autocompletion options for filtering

202

"""

203

204

kind = "checkbox"

205

```

206

207

**Usage Example:**

208

209

```python

210

checkbox_q = inquirer.Checkbox(

211

'features',

212

message="Select features",

213

choices=['Feature A', 'Feature B', 'Feature C', 'Feature D'],

214

locked=['Feature A'], # Cannot be deselected

215

default=['Feature A', 'Feature B']

216

)

217

```

218

219

### Yes/No Confirmation

220

221

Boolean confirmation question with customizable default value and yes/no response handling.

222

223

```python { .api }

224

class Confirm:

225

"""Yes/no confirmation question."""

226

227

def __init__(

228

self,

229

name: str,

230

message: str = "",

231

default: bool | callable = False,

232

ignore: bool | callable = False,

233

validate: callable | bool = True,

234

show_default: bool = False,

235

hints: str | None = None,

236

other: bool = False

237

):

238

"""

239

Create a confirmation question.

240

241

Args:

242

name: Question identifier

243

message: Prompt message (can include format strings)

244

default: Default boolean value (bool or callable)

245

ignore: Skip question if True or callable returns True

246

validate: Validation function or boolean

247

show_default: Display default value in prompt

248

hints: Help text to display

249

other: Allow "Other" option for custom input

250

"""

251

252

kind = "confirm"

253

```

254

255

**Usage Example:**

256

257

```python

258

confirm_q = inquirer.Confirm(

259

'proceed',

260

message="Do you want to continue?",

261

default=True

262

)

263

```

264

265

### External Editor Input

266

267

Multi-line text input using external editor (vim, emacs, nano, or $EDITOR/$VISUAL). Inherits from Text with editor-specific behavior.

268

269

```python { .api }

270

class Editor(Text):

271

"""Multi-line text input using external editor."""

272

273

def __init__(

274

self,

275

name: str,

276

message: str = "",

277

default: str | callable | None = None,

278

validate: callable | bool = True,

279

ignore: bool | callable = False,

280

show_default: bool = False,

281

hints: str | None = None,

282

other: bool = False

283

):

284

"""

285

Create an editor input question.

286

287

Args:

288

name: Question identifier

289

message: Prompt message (can include format strings)

290

default: Default text content (string, callable, or None)

291

validate: Validation function or boolean

292

ignore: Skip question if True or callable returns True

293

show_default: Display default value in prompt

294

hints: Help text to display

295

other: Allow "Other" option for custom input

296

"""

297

298

kind = "editor"

299

```

300

301

**Usage Example:**

302

303

```python

304

editor_q = inquirer.Editor(

305

'description',

306

message="Enter detailed description"

307

)

308

```

309

310

### File System Path Input

311

312

File or directory path input with validation for path type, existence, and format. Includes built-in path validation and cross-platform support.

313

314

```python { .api }

315

class Path(Text):

316

"""File/directory path input with validation."""

317

318

# Path type constants

319

ANY = "any"

320

FILE = "file"

321

DIRECTORY = "directory"

322

323

def __init__(

324

self,

325

name: str,

326

message: str = "",

327

default: str | callable | None = None,

328

path_type: str = "any",

329

exists: bool | None = None,

330

validate: callable | bool = True,

331

ignore: bool | callable = False,

332

show_default: bool = False,

333

hints: str | None = None,

334

other: bool = False

335

):

336

"""

337

Create a path input question.

338

339

Args:

340

name: Question identifier

341

message: Prompt message (can include format strings)

342

default: Default path value (string, callable, or None)

343

path_type: Path type ("any", "file", "directory")

344

exists: Require path to exist (True), not exist (False), or ignore (None)

345

validate: Additional validation function or boolean

346

ignore: Skip question if True or callable returns True

347

show_default: Display default value in prompt

348

hints: Help text to display

349

other: Allow "Other" option for custom input

350

"""

351

352

def validate(self, current: str):

353

"""

354

Validate path according to type and existence requirements.

355

356

Args:

357

current: Current path input value

358

359

Raises:

360

ValidationError: If path fails validation criteria

361

"""

362

363

kind = "path"

364

```

365

366

**Usage Example:**

367

368

```python

369

path_q = inquirer.Path(

370

'log_directory',

371

message="Select log directory",

372

path_type=inquirer.Path.DIRECTORY,

373

exists=True

374

)

375

```

376

377

## Base Question Class

378

379

All question types inherit from the base Question class, which provides common functionality for validation, choice management, and dynamic property resolution.

380

381

```python { .api }

382

class Question:

383

"""Base class for all question types."""

384

385

def __init__(

386

self,

387

name: str,

388

message: str = "",

389

choices: list | None = None,

390

default: any = None,

391

ignore: bool | callable = False,

392

validate: callable | bool = True,

393

show_default: bool = False,

394

hints: str | None = None,

395

other: bool = False

396

):

397

"""Base question initialization."""

398

399

def add_choice(self, choice):

400

"""Add a choice to the question's choice list."""

401

402

def validate(self, current):

403

"""Validate the current answer."""

404

405

@property

406

def ignore(self) -> bool:

407

"""Whether this question should be skipped."""

408

409

@property

410

def message(self) -> str:

411

"""Resolved message string."""

412

413

@property

414

def default(self):

415

"""Resolved default value."""

416

417

@property

418

def choices(self) -> list:

419

"""List of resolved choices."""

420

421

kind = "base question"

422

```

423

424

## Question Factory

425

426

```python { .api }

427

def question_factory(kind: str, *args, **kwargs):

428

"""

429

Create a question instance by type name.

430

431

Args:

432

kind: Question type ("text", "list", "checkbox", etc.)

433

*args, **kwargs: Question constructor arguments

434

435

Returns:

436

Question instance

437

438

Raises:

439

UnknownQuestionTypeError: If kind is not recognized

440

"""

441

```

442

443

## Tagged Values for Complex Choices

444

445

```python { .api }

446

class TaggedValue:

447

"""Tagged value for complex choice handling with display/value separation."""

448

449

def __init__(self, tag: str, value: any):

450

"""

451

Create a tagged value with separate display and return values.

452

453

Args:

454

tag: Display text shown to user

455

value: Actual value returned when selected

456

"""

457

458

def __str__(self) -> str:

459

"""Return the display tag."""

460

461

def __repr__(self) -> str:

462

"""Return representation of the value."""

463

464

def __eq__(self, other) -> bool:

465

"""Compare with other TaggedValue, tuple, or value."""

466

467

def __ne__(self, other) -> bool:

468

"""Not equal comparison."""

469

470

def __hash__(self) -> int:

471

"""Hash based on (tag, value) tuple."""

472

473

@property

474

def tag(self) -> str:

475

"""Display tag shown to user."""

476

477

@property

478

def value(self) -> any:

479

"""Actual value returned when selected."""

480

481

@property

482

def tuple(self) -> tuple:

483

"""(tag, value) tuple representation."""

484

```

485

486

**Usage Example:**

487

488

```python

489

import inquirer

490

491

# Create tagged values for complex choices

492

choices = [

493

inquirer.TaggedValue("Small (1-10 users)", "small"),

494

inquirer.TaggedValue("Medium (11-100 users)", "medium"),

495

inquirer.TaggedValue("Large (100+ users)", "large")

496

]

497

498

# Or use tuples (automatically converted to TaggedValue)

499

choices = [

500

("Small (1-10 users)", "small"),

501

("Medium (11-100 users)", "medium"),

502

("Large (100+ users)", "large")

503

]

504

505

question = inquirer.List(

506

'plan',

507

message="Select plan size",

508

choices=choices

509

)

510

511

# User sees: "Small (1-10 users)" but answer contains: "small"

512

```