or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-prompts.mdclassic-api.mdconfirmation.mdindex.mdselection.mdtext-input.mdutilities.md

selection.mddocs/

0

# Selection Prompts

1

2

Single and multi-selection list prompts with navigation, customizable display options, and support for complex choice structures.

3

4

## Capabilities

5

6

### Select (List) Prompt

7

8

Single-selection list prompt with keyboard navigation and customizable display options.

9

10

```python { .api }

11

def select(

12

message: InquirerPyMessage,

13

choices: InquirerPyListChoices,

14

default: InquirerPyDefault = None,

15

qmark: str = "?",

16

amark: str = "?",

17

pointer: str = "❯",

18

instruction: str = "",

19

long_instruction: str = "",

20

transformer: Optional[Callable[[Any], Any]] = None,

21

filter: Optional[Callable[[Any], Any]] = None,

22

height: Optional[Union[int, str]] = None,

23

max_height: Optional[Union[int, str]] = None,

24

border: bool = False,

25

validate: Optional[InquirerPyValidate] = None,

26

invalid_message: str = "Invalid input",

27

keybindings: Optional[InquirerPyKeybindings] = None,

28

show_cursor: bool = True,

29

cycle: bool = True,

30

wrap_lines: bool = True,

31

mandatory: bool = True,

32

mandatory_message: str = "Mandatory prompt",

33

style: Optional[InquirerPyStyle] = None,

34

vi_mode: bool = False,

35

raise_keyboard_interrupt: bool = True,

36

session_result: Optional[InquirerPySessionResult] = None,

37

**kwargs

38

) -> Any

39

```

40

41

**Parameters:**

42

- **choices**: List of choices or callable returning choices

43

- **pointer**: Symbol indicating current selection (default: ❯)

44

- **height/max_height**: Control visible list height

45

- **border**: Add border around choices

46

- **show_cursor**: Show selection cursor

47

- **cycle**: Allow cycling from last to first choice

48

49

**Usage Examples:**

50

51

Basic selection:

52

```python

53

from InquirerPy import inquirer

54

55

# Simple choice selection

56

framework = inquirer.select(

57

message="Choose web framework:",

58

choices=["Flask", "Django", "FastAPI", "Tornado"],

59

default="FastAPI"

60

).execute()

61

```

62

63

Complex choices with values:

64

```python

65

# Choices with display names and actual values

66

database = inquirer.select(

67

message="Select database:",

68

choices=[

69

{"name": "PostgreSQL (Recommended)", "value": "postgresql"},

70

{"name": "MySQL", "value": "mysql"},

71

{"name": "SQLite", "value": "sqlite"},

72

{"name": "MongoDB", "value": "mongodb"}

73

]

74

).execute()

75

```

76

77

With separators and height control:

78

```python

79

from InquirerPy import inquirer

80

from InquirerPy.separator import Separator

81

82

environment = inquirer.select(

83

message="Choose deployment environment:",

84

choices=[

85

"development",

86

"testing",

87

Separator("--- Production ---"),

88

"staging",

89

"production",

90

Separator("--- Cloud ---"),

91

"aws",

92

"gcp",

93

"azure"

94

],

95

height="50%",

96

border=True

97

).execute()

98

```

99

100

### Checkbox (Multi-select) Prompt

101

102

Multi-selection prompt allowing users to select multiple options with checkboxes.

103

104

```python { .api }

105

def checkbox(

106

message: InquirerPyMessage,

107

choices: InquirerPyListChoices,

108

default: Any = None,

109

qmark: str = "?",

110

amark: str = "?",

111

pointer: str = "❯",

112

enabled_symbol: str = "●",

113

disabled_symbol: str = "○",

114

border: bool = False,

115

instruction: str = "",

116

long_instruction: str = "",

117

transformer: Optional[Callable[[Any], Any]] = None,

118

filter: Optional[Callable[[Any], Any]] = None,

119

height: Optional[Union[int, str]] = None,

120

max_height: Optional[Union[int, str]] = None,

121

validate: Optional[InquirerPyValidate] = None,

122

invalid_message: str = "Invalid input",

123

keybindings: Optional[InquirerPyKeybindings] = None,

124

show_cursor: bool = True,

125

cycle: bool = True,

126

wrap_lines: bool = True,

127

mandatory: bool = True,

128

mandatory_message: str = "Mandatory prompt",

129

style: Optional[InquirerPyStyle] = None,

130

vi_mode: bool = False,

131

raise_keyboard_interrupt: bool = True,

132

session_result: Optional[InquirerPySessionResult] = None,

133

**kwargs

134

) -> List[Any]

135

```

136

137

**Parameters:**

138

- **enabled_symbol**: Symbol for selected items (default: ●)

139

- **disabled_symbol**: Symbol for unselected items (default: ○)

140

- **default**: List of default selected values or callable

141

142

**Returns:** List of selected values (empty list if none selected)

143

144

**Usage Examples:**

145

146

Basic multi-selection:

147

```python

148

# Multiple technology selection

149

technologies = inquirer.checkbox(

150

message="Select technologies:",

151

choices=["Python", "JavaScript", "Java", "Go", "Rust", "C++"],

152

default=["Python", "JavaScript"]

153

).execute()

154

```

155

156

With validation:

157

```python

158

# Require at least one selection

159

features = inquirer.checkbox(

160

message="Select features to enable:",

161

choices=["Authentication", "Database", "Caching", "Logging", "Monitoring"],

162

validate=lambda result: len(result) >= 1,

163

invalid_message="Please select at least one feature"

164

).execute()

165

```

166

167

### Rawlist (Numbered) Prompt

168

169

Numbered list selection limited to 9 choices with keyboard shortcuts.

170

171

```python { .api }

172

def rawlist(

173

message: InquirerPyMessage,

174

choices: InquirerPyListChoices,

175

default: InquirerPyDefault = None,

176

separator: str = ") ",

177

qmark: str = "?",

178

amark: str = "?",

179

pointer: str = " ",

180

instruction: str = "",

181

long_instruction: str = "",

182

transformer: Optional[Callable[[Any], Any]] = None,

183

filter: Optional[Callable[[Any], Any]] = None,

184

height: Optional[Union[int, str]] = None,

185

max_height: Optional[Union[int, str]] = None,

186

border: bool = False,

187

validate: Optional[InquirerPyValidate] = None,

188

invalid_message: str = "Invalid input",

189

keybindings: Optional[InquirerPyKeybindings] = None,

190

show_cursor: bool = True,

191

cycle: bool = True,

192

wrap_lines: bool = True,

193

mandatory: bool = True,

194

mandatory_message: str = "Mandatory prompt",

195

style: Optional[InquirerPyStyle] = None,

196

vi_mode: bool = False,

197

raise_keyboard_interrupt: bool = True,

198

session_result: Optional[InquirerPySessionResult] = None,

199

**kwargs

200

) -> Any

201

```

202

203

**Parameters:**

204

- **separator**: Text between number and choice (default: ") ")

205

- **Maximum 9 choices**: Limited by keyboard number keys 1-9

206

207

**Usage Example:**

208

```python

209

# Quick numbered selection

210

priority = inquirer.rawlist(

211

message="Select priority level:",

212

choices=["Low", "Medium", "High", "Critical"],

213

default="Medium"

214

).execute()

215

# Displays as: 1) Low 2) Medium 3) High 4) Critical

216

```

217

218

## Advanced Choice Structures

219

220

### Choice Objects

221

222

Choices can be strings, dictionaries, or Choice objects:

223

224

```python

225

# String choices (simple)

226

choices = ["Option 1", "Option 2", "Option 3"]

227

228

# Dictionary choices (name/value pairs)

229

choices = [

230

{"name": "Development Server", "value": "dev"},

231

{"name": "Production Server", "value": "prod"}

232

]

233

234

# Choice objects with additional properties

235

from InquirerPy.base.control import Choice

236

237

choices = [

238

Choice("item1", name="First Item", enabled=True),

239

Choice("item2", name="Second Item", enabled=False),

240

Choice("item3", name="Third Item")

241

]

242

```

243

244

### Dynamic Choices

245

246

Choices can be generated dynamically based on previous answers:

247

248

```python

249

from InquirerPy import prompt

250

251

questions = [

252

{

253

"type": "select",

254

"message": "Choose category:",

255

"choices": ["Frontend", "Backend", "DevOps"],

256

"name": "category"

257

},

258

{

259

"type": "checkbox",

260

"message": "Select tools:",

261

"choices": lambda answers: {

262

"Frontend": ["React", "Vue", "Angular"],

263

"Backend": ["Django", "Flask", "FastAPI"],

264

"DevOps": ["Docker", "Kubernetes", "Terraform"]

265

}.get(answers["category"], []),

266

"name": "tools"

267

}

268

]

269

270

result = prompt(questions)

271

```

272

273

## Class-based Usage

274

275

```python

276

from InquirerPy.prompts import ListPrompt, CheckboxPrompt, RawlistPrompt

277

278

# ListPrompt class

279

list_prompt = ListPrompt(

280

message="Choose option:",

281

choices=["A", "B", "C"],

282

height=10,

283

border=True

284

)

285

selection = list_prompt.execute()

286

287

# CheckboxPrompt class

288

checkbox_prompt = CheckboxPrompt(

289

message="Select multiple:",

290

choices=["X", "Y", "Z"],

291

default=["X"]

292

)

293

selections = checkbox_prompt.execute()

294

295

# RawlistPrompt class

296

rawlist_prompt = RawlistPrompt(

297

message="Pick one:",

298

choices=["First", "Second", "Third"],

299

separator=" -> "

300

)

301

pick = rawlist_prompt.execute()

302

```

303

304

## Keyboard Navigation

305

306

- **Up/Down Arrows**: Navigate choices

307

- **Space**: Toggle selection (checkbox) or select (list)

308

- **Enter**: Confirm selection

309

- **Tab**: Move to next choice (in some modes)

310

- **Numbers 1-9**: Quick selection (rawlist)

311

- **Ctrl+A**: Select all (checkbox)

312

- **Ctrl+I**: Invert selection (checkbox)