Custom Widgets#

Widgets can be seen as containers such as tags in XML/HTML. They are yielded by prompt engines with several data required to be formatted by a formatter.

The widgets module module contains a collection of widgets used by the built-in prompt engines as well as the base class for widgets. In order to create a widget, we need to subclass that base class:

Attention

attrs is used for the creation of widgets in aprompt. To avoid third-party dependencies, we use dataclasses.dataclass()es. throughout the tutorial.

src/aprompt_year/widgets.py#
from dataclasses import dataclass
from aprompt.widgets import Widget

@dataclass
class Year(Widgets):
    value: int