Skip to content

rs_rich.interact

Generated from the type stubs by scripts/gen_python_api.py; do not edit.

rs_rich.interact: interactive components (rs-rich-interact; no Rich counterpart).

Components: Select and MultiSelect (fuzzy pickers over Items whose values are any Python objects), Input (one line, masked with password=True), TextArea (several lines), Confirm (with Choices), Form, Pager, FilePicker (a path), ColorPicker (a colour string) and AssetPicker (an emoji, box style or spinner). Subclass Component (render(context), handle(event), keymap()) to write your own; any object with handle(event) and render(width, height) is a component too (Event, Done, Cancel, Ignored).

Composition: Column, Row and Stack lay children along an axis, Split puts two side by side or stacked, Tabs shows one at a time, and Layers opens Layers (modals and popovers) over a base. Built-ins, your own components and containers mix; Map says what a child's answer means, Label shows markup, and Keymap and Binding declare keys, which keymap(component) lists.

Drivers:

  • ask(component, **options) (or component.ask()) runs it on the terminal and returns the answer; Escape raises Cancelled and Ctrl+C KeyboardInterrupt. run returns the Outcome instead.
  • Without a terminal the fallback decides: "prompt" asks line by line, "default" returns the component's default, "error" raises NotInteractive.
  • headless(component, script) runs it with scripted keys and returns a Record of the painted frames; degrade(component, answers) runs the line-prompt fallback with scripted answers. Tests use these.

fuzzy and rank are the pickers' matcher.

Item module-attribute

Item = InteractItem

Action module-attribute

Action = InteractAction

Select module-attribute

Select = InteractSelect

MultiSelect module-attribute

MultiSelect = InteractMultiSelect

Input module-attribute

Input = InteractInput

Choice module-attribute

Choice = InteractChoice

Confirm module-attribute

Confirm = InteractConfirm

Form module-attribute

Form = InteractForm

Pager module-attribute

Pager = InteractPager

TextArea module-attribute

TextArea = InteractTextArea

FilePicker module-attribute

FilePicker = InteractFilePicker

ColorPicker module-attribute

ColorPicker = InteractColorPicker

AssetPicker module-attribute

AssetPicker = InteractAssetPicker

Event module-attribute

Event = InteractEvent

Done module-attribute

Done = InteractDone

Cancel module-attribute

Cancel = InteractCancel

Ignored module-attribute

Ignored = InteractIgnored

Component module-attribute

Component = InteractComponent

Context module-attribute

Context = InteractContext

Keymap module-attribute

Keymap = InteractKeymap

Binding module-attribute

Binding = InteractBinding

Label module-attribute

Label = InteractLabel

Map module-attribute

Map = InteractMap

Container module-attribute

Container = InteractContainer

Stack module-attribute

Stack = InteractStack

Column module-attribute

Column = InteractColumn

Row module-attribute

Row = InteractRow

Split module-attribute

Split = InteractSplit

Tabs module-attribute

Tabs = InteractTabs

Layer module-attribute

Layer = InteractLayer

Layers module-attribute

Layers = InteractLayers

Script module-attribute

Script = InteractScript

Outcome module-attribute

Outcome = InteractOutcome

Record module-attribute

Record = InteractRecord

Match module-attribute

Match = FuzzyMatch

run module-attribute

run = interact_run

ask module-attribute

ask = interact_ask

headless module-attribute

headless = interact_headless

degrade module-attribute

degrade = interact_degrade

keymap module-attribute

keymap = interact_keymap

fuzzy module-attribute

fuzzy = fuzzy_match

rank module-attribute

rank = fuzzy_rank

Cancelled

Bases: InteractError

InteractError

Bases: Exception

NotInteractive

Bases: InteractError

reason instance-attribute

reason: Optional[str]