CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-inquirer-textual

Inquirer based on Textual for creating interactive command-line user input prompts

Overview
Eval results
Files

quick-reference.mddocs/

Quick Reference

Fast API lookup for inquirer-textual. All signatures, parameters, and return types.

Prompt Functions

prompts.text()

def text(
    message: str,
    shortcuts: list[Shortcut] | None = None,
    validators: Validator | Iterable[Validator] | None = None
) -> Result[str]
  • Purpose: Text input with optional validation
  • Returns: Result containing input text string
  • Validation: If validation fails on Enter, prompt remains active

prompts.secret()

def secret(
    message: str,
    shortcuts: list[Shortcut] | None = None
) -> Result[str]
  • Purpose: Password/secret input with masked display
  • Returns: Result containing secret string (actual value, not masked)

prompts.number()

def number(
    message: str,
    shortcuts: list[Shortcut] | None = None
) -> Result[str]
  • Purpose: Integer number input
  • Returns: Result containing numeric STRING (validated as integer)
  • Note: Value is string, use int(result.value) to convert

prompts.confirm()

def confirm(
    message: str,
    shortcuts: list[Shortcut] | None = None,
    default: bool = False,
    mandatory: bool = True
) -> Result[bool]
  • Purpose: Yes/No confirmation
  • Returns: Result containing boolean value
  • Parameters:
    • default: True shows (Y/n), False shows (y/N)
    • mandatory: If False, allows Ctrl+C exit (returns command='ctrl+c', value=None)

prompts.select()

def select(
    message: str,
    choices: list[str | Choice],
    shortcuts: list[Shortcut] | None = None,
    default: str | Choice | None = None,
    mandatory: bool = True
) -> Result[str | Choice]
  • Purpose: Single selection from list
  • Returns: Result containing selected string or Choice object
  • Parameters:
    • default: Initial highlighted item
    • mandatory: If False, allows Ctrl+C exit
  • Keyboard: Up/Down to navigate, Enter to select

prompts.checkbox()

def checkbox(
    message: str,
    choices: list[str | Choice],
    shortcuts: list[Shortcut] | None = None,
    enabled: list[str | Choice] | None = None
) -> Result[list[str | Choice]]
  • Purpose: Multiple selection from list with checkboxes
  • Returns: Result containing list of selected strings or Choice objects
  • Parameters:
    • enabled: Pre-checked items (NOT FUNCTIONAL in v0.2.0 - bug)
  • Keyboard: Up/Down to navigate, Space to toggle, Enter to confirm
  • Known Issue: All items start unchecked regardless of enabled parameter

prompts.multi()

def multi(
    widgets: list[InquirerWidget],
    shortcuts: list[Shortcut] | None = None
) -> Result[list[Any]]
  • Purpose: Sequential multi-prompt form
  • Returns: Result containing list of values from all widgets in order
  • Behavior: Displays widgets one by one; if user quits early, returns completed values

Data Structures

Result[T]

class Result(Generic[T]):
    command: str | None  # 'select', 'quit', or custom command
    value: T             # Typed value from prompt
  • Commands:
    • 'select': User pressed Enter to confirm
    • 'quit': User pressed Ctrl+D
    • 'ctrl+c': User pressed Ctrl+C (when allowed)
    • Custom: Any shortcut command or Choice.command

Choice

class Choice:
    name: str            # Display name
    data: Any = None     # Attached data (any Python object)
    command: str = 'select'  # Command when selected
  • Usage: Attach data to selection items or trigger custom commands

Shortcut

class Shortcut:
    key: str             # Key or key combination
    command: str         # Command name to execute
    description: str | None = None  # Description (auto-defaults to command if None)
    show: bool = True    # Show in footer
  • Key Examples: 'escape', 'ctrl+s', 'ctrl+shift+d', 'f1'
  • Auto-description: If description is None, post_init() sets it to command value

Widget Classes

InquirerText

class InquirerText(InquirerWidget):
    def __init__(
        self,
        message: str,
        default: str = '',
        validators: Validator | Iterable[Validator] | None = None
    )
    def focus(scroll_visible: bool = True) -> Self
    def current_value() -> str
  • Use with: InquirerApp.prompt() or prompts.multi()

InquirerSecret

class InquirerSecret(InquirerWidget):
    def __init__(self, message: str)
    def focus(scroll_visible: bool = True) -> Self
    def current_value() -> str
  • Use with: InquirerApp.prompt() or prompts.multi()

InquirerNumber

class InquirerNumber(InquirerWidget):
    def __init__(self, message: str)
    def focus(scroll_visible: bool = True) -> Self
    def current_value() -> str  # String validated as integer
  • Use with: InquirerApp.prompt() or prompts.multi()
  • Note: Returns string, use int(value) to convert

InquirerConfirm

class InquirerConfirm(InquirerWidget):
    def __init__(
        self,
        message: str,
        confirm_character: str = 'y',
        reject_character: str = 'n',
        default: bool = False,
        mandatory: bool = True
    )
    def current_value() -> bool
  • Use with: InquirerApp.prompt() or prompts.multi()

InquirerSelect

class InquirerSelect(InquirerWidget):
    def __init__(
        self,
        message: str,
        choices: list[str | Choice],
        default: str | Choice | None = None,
        mandatory: bool = True
    )
    def focus(scroll_visible: bool = True) -> Self
    def current_value() -> str | Choice | None
  • Use with: InquirerApp.prompt() or prompts.multi()

InquirerCheckbox

class InquirerCheckbox(InquirerWidget):
    def __init__(
        self,
        message: str,
        choices: list[str | Choice],
        enabled: list[str | Choice] | None = None  # NOT FUNCTIONAL in v0.2.0
    )
    def focus(scroll_visible: bool = True) -> Self
    def current_value() -> list[str | Choice]
    def action_toggle_selected()  # Bound to spacebar
  • Use with: InquirerApp.prompt() or prompts.multi()
  • Known Issue: enabled parameter does not work

InquirerMulti

class InquirerMulti(InquirerWidget):
    def __init__(self, widgets: list[InquirerWidget])
  • Use with: InquirerApp.prompt() or prompts.multi()

InquirerWidget (Base)

class InquirerWidget(Widget):
    def __init__(self, mandatory: bool = True)
    def current_value() -> Any  # Abstract, implemented by subclasses

    class Submit(Message):
        value: Any
        command: str | None = "select"
  • Base class for all widget types
  • Submit message: Posted when widget is submitted

InquirerApp

Class

class InquirerApp(App[Result[T]], Generic[T]):
    # Instance attributes
    widget: InquirerWidget | None
    shortcuts: list[Shortcut] | None
    header: str | list[str] | None
    show_footer: bool
    result: Result[T] | None
    inquiry_func: Callable[[InquirerApp[T]], None] | None

Methods

def run(
    *,
    headless: bool = False,
    inline: bool = False,
    inline_no_clear: bool = False,
    mouse: bool = True,
    size: tuple[int, int] | None = None,
    auto_pilot: AutopilotCallbackType | None = None,
    loop: AbstractEventLoop | None = None,
    inquiry_func: Callable[[InquirerApp[T]], None] | None = None
) -> Result[T]
  • inline=True: Embeds in terminal at cursor (preserves history)
  • inline=False: Full-screen TUI mode
  • inquiry_func: Function for building custom multi-prompt flows
def prompt(
    widget: InquirerWidget,
    shortcuts: list[Shortcut] | None = None
) -> Result[T]
  • Use in: inquiry_func to display widgets sequentially
  • Blocks: Until user completes or quits widget
def stop(value: Any = None)
  • Use in: inquiry_func to set final return value and exit
def focus_widget()
  • Purpose: Focus the current widget
def get_theme_variable_defaults() -> dict[str, str]
  • Returns: Theme color variables
    • 'select-question-mark': '#e5c07b'
    • 'select-list-item-highlight-foreground': '#61afef'
    • 'input-color': '#98c379'

Validation (Textual Framework)

from textual.validation import Validator, ValidationResult, Function

class Validator:
    def validate(self, value: str) -> ValidationResult
    def success(self) -> ValidationResult
    def failure(self, message: str = "") -> ValidationResult

Built-in Validators

  • Function: Function(lambda s: bool, "error message")
  • Integer: Validates integer input
  • Number: Validates numeric input
  • Length: Validates string length
  • Regex: Validates against regex pattern

Custom Validator

class CustomValidator(Validator):
    def validate(self, value: str) -> ValidationResult:
        if valid_condition:
            return self.success()
        return self.failure("Error message")

Common Patterns

Check Command Before Using Value

result = prompts.text("Input:")
if result.command == 'select':
    # Safe to use result.value
    process(result.value)

Using Choice Data

from inquirer_textual.common.Choice import Choice

choices = [Choice("A", data={"id": 1}), Choice("B", data={"id": 2})]
result = prompts.select("Pick:", choices)
if result.command == 'select':
    data = result.value.data  # Access attached data

Multi-Prompt with Unpacking

result = prompts.multi([
    InquirerText("Name:"),
    InquirerText("Email:")
])
if result.command == 'select':
    name, email = result.value

inquiry_func Pattern

def flow(app):
    r1 = app.prompt(InquirerText("First:"))
    if r1.command != 'select':
        return
    r2 = app.prompt(InquirerText("Second:"))
    app.stop((r1.value, r2.value))

app = InquirerApp()
result = app.run(inline=True, inquiry_func=flow)

Type Annotations

from inquirer_textual import prompts
from inquirer_textual.common.Choice import Choice

# Text result
text_result: Result[str] = prompts.text("Name:")
name: str = text_result.value

# Number result
num_result: Result[str] = prompts.number("Age:")
age: int = int(num_result.value)  # Convert to int

# Confirm result
bool_result: Result[bool] = prompts.confirm("OK?")
confirmed: bool = bool_result.value

# Select result
select_result: Result[str | Choice] = prompts.select("Pick:", ["A", "B"])
choice: str | Choice = select_result.value

# Checkbox result
checkbox_result: Result[list[str | Choice]] = prompts.checkbox("Select:", ["X", "Y"])
selected: list[str | Choice] = checkbox_result.value

# Multi result
multi_result: Result[list[Any]] = prompts.multi([...])
values: list[Any] = multi_result.value

Keyboard Controls

All Prompts

  • Enter: Confirm/submit
  • Ctrl+D: Quit
  • Ctrl+C: Exit (when mandatory=False)
  • Custom shortcuts: As configured

Text/Secret/Number Input

  • Type to edit: Standard text input
  • Backspace/Delete: Edit text

Confirm

  • y: Yes
  • n: No
  • Custom characters: As configured

Select

  • Up/Down Arrow: Navigate
  • Page Up/Page Down: Fast scroll

Checkbox

  • Up/Down Arrow: Navigate
  • Space: Toggle current item checkbox
  • Page Up/Page Down: Fast scroll

Install with Tessl CLI

npx tessl i tessl/pypi-inquirer-textual

docs

advanced-app.md

data-structures.md

errors-edge-cases.md

index.md

patterns-recipes.md

prompts-api.md

quick-reference.md

widgets-api.md

tile.json