API Reference

class richer_prompt.Select(message: str | Text, choices: Iterable[Choice[T] | T], *, cursor_pointer: str = '❯', numbered: bool = True, show_hint: bool = True, console: Console | None = None)

Select a single choice from a vertical list.

select Choose a color: 1. Red 2. Green 3. Blue ↑↓ to navigate · Enter to select
Parameters:
  • message (str or rich.text.Text) – The message to display above the choices.

  • choices (iterable of T or Choice[T]) – The values to choose from. Each choice can be a raw value or an instance of Choice, which allows customization of labels and descriptions.

  • show_hint (bool, default True) – Whether to show a hint about how to select choices.

  • console (rich.console.Console, optional) – A Console instance. If None, use the global console.

Examples

>>> prompt = Select("Choose a color:", ["Red", "Green", "Blue"])
>>> color = prompt()
__call__(index: int = 0) T

Run the prompt loop.

Parameters:

index (int, default 0) – The index of the choice to select by default.

Return type:

The value of the selected choice.

classmethod ask(message: str | Text, choices: Iterable[T], *, index: int = 0, cursor_pointer: str = '❯', numbered: bool = True, show_hint: bool = True, console: Console | None = None) T

Shortcut to construct and run a prompt loop and return the result.

Parameters:
  • message (str or rich.text.Text) – The message to display above the choices.

  • choices (iterable of T or Choice[T]) – The values to choose from. Each choice can be a raw value or an instance of Choice, which allows customization of labels and descriptions.

  • index (int, default 0) – The index of the choice to have the cursor start on.

  • cursor_pointer (str, default "❯") – The string to use as the cursor pointer.

  • numbered (bool, default True) – Whether to display numbers next to the choices.

  • show_hint (bool, default True) – Whether to show a hint about how to select choices.

  • console (rich.console.Console, optional) – A Console instance. If None, use the global console.

Return type:

The value of the selected choice.

Examples

>>> color = Select.ask("Choose a color:", ["Red", "Green", "Blue"])
pre_prompt() None

Hook to display something before the prompt.

class richer_prompt.MultiSelect(message: str | Text, choices: Iterable[Choice[T] | T], *, cursor_pointer: str = '❯', numbered: bool = True, show_hint: bool = True, console: Console | None = None)

Select multiple choices from a vertical list.

multiselect Choose colors: 1. [ ]Red 2. [ ]Green 3. [ ]Blue Submit ↑↓ to navigate · Enter to select · Submit to finish
Parameters:
  • message (str or rich.text.Text) – The message to display above the choices.

  • choices (iterable of T or Choice[T]) – The values to choose from. Each choice can be a raw value or an instance of Choice, which allows customization of labels and descriptions.

  • cursor_pointer (str, default "❯") – The string to use as the cursor pointer.

  • numbered (bool, default True) – Whether to display numbers next to the choices.

  • show_hint (bool, default True) – Whether to show a hint about how to select choices.

  • console (rich.console.Console, optional) – A Console instance. If None, use the global console.

Examples

>>> prompt = MultiSelect("Choose colors:", ["Red", "Green", "Blue"])
>>> colors = prompt()
__call__(index: int = 0, default: set[int] | None = None) list[T]

Run the prompt loop.

Parameters:
  • index (int, default 0) – The index of the choice to have the cursor start on.

  • default (set of int, optional) – A set of indices of choices that should be selected by default.

Return type:

List of values of the selected choices.

classmethod ask(message: str | Text, choices: Iterable[Choice[T] | T], *, index: int = 0, default: set[int] | None = None, cursor_pointer: str = '❯', numbered: bool = True, show_hint: bool = True, console: Console | None = None) list[T]

Shortcut to construct and run a prompt loop and return the result.

Parameters:
  • message (str or rich.text.Text) – The message to display above the choices.

  • choices (iterable of T or Choice[T]) – The values to choose from. Each choice can be a raw value or an instance of Choice, which allows customization of labels and descriptions.

  • index (int, default 0) – The index of the choice to have the cursor start on.

  • default (set of int, optional) – A set of indices of choices that should be selected by default.

  • cursor_pointer (str, default "❯") – The string to use as the cursor pointer.

  • numbered (bool, default True) – Whether to display numbers next to the choices.

  • show_hint (bool, default True) – Whether to show a hint about how to select choices.

  • console (rich.console.Console, optional) – A Console instance. If None, use the global console.

Return type:

List of values of the selected choices.

Examples

>>> colors = MultiSelect.ask("Choose colors:", ["Red", "Green", "Blue"])
pre_prompt() None

Hook to display something before the prompt.

class richer_prompt.Tabs(message: str | Text, choices: Iterable[Choice[T] | T], *, console: Console | None = None)

Select a single choice from a horizontal list.

tabs Choose a color:  Red  Green  Blue  →
Parameters:
  • message (str or rich.text.Text) – The message to display above the choices.

  • choices (iterable of T or Choice[T]) – The values to choose from. Each choice can be a raw value or an instance of Choice, which allows customization of labels and descriptions.

  • console (rich.console.Console, optional) – A Console instance. If None, use the global console.

Examples

>>> prompt = Tabs("Choose a color:", ["Red", "Green", "Blue"])
>>> color = prompt()
__call__(index: int = 0) T

Run the prompt loop.

Parameters:

index (int, default 0) – The index of the choice to select by default.

Return type:

The value of the selected choice.

classmethod ask(message: str | Text, choices: Iterable[T], *, index: int = 0, console: Console | None = None) T

Shortcut to construct and run a prompt loop and return the result.

Parameters:
  • message (str or rich.text.Text) – The message to display above the choices.

  • choices (iterable of T or Choice[T]) – The values to choose from. Each choice can be a raw value or an instance of Choice, which allows customization of labels and descriptions.

  • index (int, default 0) – The index of the choice to have the cursor start on.

  • console (rich.console.Console, optional) – A Console instance. If None, use the global console.

Return type:

The value of the selected choice.

Examples

>>> color = Tabs.ask("Choose a color:", ["Red", "Green", "Blue"])
pre_prompt() None

Hook to display something before the prompt.

class richer_prompt.Choice(value: T, label: str = '', description: str = '')

A selectable choice used by prompt classes.

Parameters:
  • value (T) – The choice value returned when selected.

  • label (str, optional) – The label to display for the choice. If not provided, the value is used as the label.

  • description (str, optional) – Additional text to describe the choice.

description: str
property display: str

Get the display string for the choice.

label: str
value: T