Exceptions¶
All exceptions live in interactive_buttons.exceptions and are re-exported
from the top-level interactive_buttons package.
EmulatedTerminalDetected
¶
Bases: Exception
Raised when the terminal cannot support raw keyboard input.
interactive-buttons relies on readchar to capture individual
keystrokes. Emulated terminals (e.g. the integrated terminal inside some
IDEs) may not expose a real TTY and will trigger this exception. Run your
programme in a proper terminal emulator (bash, zsh, PowerShell, etc.).
MoreButtonsThanIndexes
¶
Bases: Exception
Raised when the number of buttons exceeds the available digit indexes.
This happens when [display_index][interactive_buttons.Component.display_index] is
True and the number of buttons is greater than 10 - index_begin.
KeyBindError
¶
Bases: Exception
Raised for invalid or conflicting key-binding configuration.
Possible causes:
- A key in
b_keysis not a single ASCII alphanumeric character. - Both
key_bindanddisplay_indexare active at the same time. - Two different buttons share the same bound key.
When each exception is raised¶
| Exception | Raised by | Condition |
|---|---|---|
EmulatedTerminalDetected |
Any layout method | Terminal cannot provide raw keystroke input (e.g. IDE integrated terminal) |
MoreButtonsThanIndexes |
Component.__init__ |
display_index=True and len(buttons) > 10 - index_begin |
KeyBindError |
ButtonKeyBind.__init__, Component.__init__ |
Invalid key character, key_bind + display_index conflict, or duplicate keys |
Handling exceptions¶
from interactive_buttons import (
Button, Component,
EmulatedTerminalDetected,
KeyBindError,
)
try:
comp = Component([Button(label="OK", value=True)])
result = comp.column_buttons()
except EmulatedTerminalDetected:
print("Please run this script in a real terminal, not inside an IDE.")
except KeyBindError as exc:
print(f"Key binding configuration error: {exc}")