You can control how KeyboardInterrupt (typically triggered by ctrl-c) is handled in InquirerPy using two primary methods: keybindings or raise_keyboard_interrupt.
Method 1: Using raise_keyboard_interrupt
If you want behavior similar to a Python REPL (where ctrl-c skips the prompt and ctrl-d terminates the program), set raise_keyboard_interrupt=False.
Note: When using this method, it is recommended to inform the user how to terminate the program via mandatory_message or long_instruction.
Method 2: Using keybindings
You can explicitly map specific keys to skip or interrupt actions.
Warning: Do not use raise_keyboard_interrupt and keybindings together, as both attempt to modify the same underlying key mappings and may cause conflicts.
# Example using raise_keyboard_interrupt for REPL-like behavior
from InquirerPy import inquirer
result = inquirer.select(
message="Select one:",
choices=["Fruit", "Meat", "Drinks", "Vegetable"],
raise_keyboard_interrupt=False,
mandatory_message="Prompt is mandatory, terminate the program using ctrl-d",
).execute()
# Example using explicit keybindings
from InquirerPy import inquirer
result = inquirer.select(
message="Select one:",
choices=["Fruit", "Meat", "Drinks", "Vegetable"],
keybindings={"skip": [{"key": "c-c"}], "interrupt": [{"key": "c-d"}]},
).execute()