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

confirmation.mddocs/

0

# Confirmation Prompts

1

2

Yes/no confirmation prompts with single keypress operation and customizable confirmation letters for quick user decisions.

3

4

## Capabilities

5

6

### Confirm Prompt

7

8

Boolean confirmation prompt that accepts single keypress input for quick yes/no decisions.

9

10

```python { .api }

11

def confirm(

12

message: InquirerPyMessage,

13

default: InquirerPyDefault = False,

14

qmark: str = "?",

15

amark: str = "?",

16

instruction: str = "",

17

long_instruction: str = "",

18

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

19

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

20

keybindings: Optional[InquirerPyKeybindings] = None,

21

wrap_lines: bool = True,

22

confirm_letter: str = "y",

23

reject_letter: str = "n",

24

mandatory: bool = True,

25

mandatory_message: str = "Mandatory prompt",

26

style: Optional[InquirerPyStyle] = None,

27

vi_mode: bool = False,

28

raise_keyboard_interrupt: bool = True,

29

session_result: Optional[InquirerPySessionResult] = None,

30

**kwargs

31

) -> bool

32

```

33

34

**Parameters:**

35

- **message**: The confirmation question text

36

- **default**: Default boolean value (True/False)

37

- **confirm_letter**: Single character for "yes" (default: "y")

38

- **reject_letter**: Single character for "no" (default: "n")

39

- **transformer**: Function to transform the boolean result for display

40

- **filter**: Function to transform the actual returned value

41

- **mandatory**: Whether the prompt requires an answer

42

- **vi_mode**: Note - VI mode is disabled for confirm prompts

43

44

**Returns:** Boolean value based on user input

45

46

**Usage Examples:**

47

48

Basic confirmation:

49

```python

50

from InquirerPy import inquirer

51

52

# Simple yes/no confirmation

53

proceed = inquirer.confirm(message="Do you want to continue?").execute()

54

if proceed:

55

print("Continuing...")

56

else:

57

print("Cancelled.")

58

```

59

60

With custom default and letters:

61

```python

62

# Default to True with custom letters

63

save_changes = inquirer.confirm(

64

message="Save changes before exit?",

65

default=True,

66

confirm_letter="s",

67

reject_letter="d",

68

instruction="(s)ave or (d)iscard"

69

).execute()

70

```

71

72

With transformation:

73

```python

74

# Transform boolean to custom strings

75

result = inquirer.confirm(

76

message="Enable debug mode?",

77

default=False,

78

transformer=lambda result: "Enabled" if result else "Disabled"

79

).execute()

80

print(f"Debug mode: {result}")

81

```

82

83

## Class-based Usage

84

85

Direct class instantiation for advanced customization:

86

87

```python

88

from InquirerPy.prompts import ConfirmPrompt

89

90

# ConfirmPrompt class

91

confirm_prompt = ConfirmPrompt(

92

message="Delete all files?",

93

default=False,

94

confirm_letter="d",

95

reject_letter="k",

96

instruction="(d)elete or (k)eep",

97

transformer=lambda result: "DELETED" if result else "KEPT"

98

)

99

100

confirmed = confirm_prompt.execute()

101

print(f"Action: {confirmed}")

102

```

103

104

## Keyboard Behavior

105

106

- **Single Keypress**: No need to press Enter, responds immediately to key

107

- **Default Handling**: Press Enter to use default value

108

- **Case Insensitive**: Both uppercase and lowercase letters work

109

- **VI Mode**: Disabled by default for confirmation prompts

110

- **Escape/Ctrl+C**: Triggers keyboard interrupt or returns None based on settings

111

112

## Integration with Question Flow

113

114

Confirmation prompts are commonly used in conditional question flows:

115

116

```python

117

from InquirerPy import prompt

118

119

questions = [

120

{

121

"type": "confirm",

122

"message": "Do you want to configure advanced settings?",

123

"name": "advanced",

124

"default": False

125

},

126

{

127

"type": "input",

128

"message": "Enter API endpoint:",

129

"name": "endpoint",

130

"when": lambda answers: answers["advanced"]

131

},

132

{

133

"type": "confirm",

134

"message": "Confirm settings?",

135

"name": "confirm_save",

136

"default": True

137

}

138

]

139

140

answers = prompt(questions)

141

```