Skip to content

ConfigScreen

Base classes

Name Children Inherits
ModalScreen
textual.screen
A screen with bindings that take precedence over the App's key bindings.

โ‹” Inheritance diagram

graph TD
  107846720043344["dialogs.ConfigScreen"]
  107846717906624["screen.ModalScreen"]
  107846717858048["screen.Screen"]
  107846685555472["typing.Generic"]
  137699722799616["builtins.object"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  107846717906624 --> 107846720043344
  107846717858048 --> 107846717906624
  107846685555472 --> 107846717858048
  137699722799616 --> 107846685555472
  107846718477920 --> 107846717858048
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

๐Ÿ›ˆ DocStrings

Bases: ModalScreen[ConfigChoice | None]

Session options (mode, model, ...) as the agent exposes them; returns a new value.

Source code in src/acptui/ui/screens/dialogs.py
class ConfigScreen(ModalScreen[ConfigChoice | None]):
    """Session options (mode, model, ...) as the agent exposes them; returns a new value."""

    DEFAULT_CSS = "ConfigScreen {" + DIALOG_CSS + "}"
    BINDINGS: ClassVar = [Binding("escape", "back", "Back")]

    def __init__(self, options: list[SessionConfigOption]) -> None:
        super().__init__()
        self.options = options
        self.current: SelectSessionConfigOption | None = None

    def compose(self) -> ComposeResult:
        with Vertical(id="dialog"):
            yield Static("Session options", id="dialog-title")
            yield OptionList(id="config")
            yield Static("enter: change ยท escape: close", id="dialog-hint")

    def on_mount(self) -> None:
        self._show_options()

    def _show_options(self) -> None:
        self.current = None
        self.query_one("#dialog-title", Static).update("Session options")
        options = self.query_one("#config", OptionList)
        options.clear_options()
        if not self.options:
            self.query_one("#dialog-hint", Static).update(
                "The agent offers no options for this session."
            )
        for index, option in enumerate(self.options):
            category = option.category if is_set(option.category) and option.category else ""
            label = Content.assemble(
                (option.name, "bold"),
                ": ",
                (option_value_label(option), "$text-accent"),
                (f"  ({category})" if category else "", "$text-muted"),
            )
            options.add_option(Option(label, id=f"o:{index}"))
        if self.options:
            options.highlighted = 0
        options.focus()

    def _show_values(self, option: SelectSessionConfigOption) -> None:
        self.current = option
        self.query_one("#dialog-title", Static).update(Content(option.name))
        options = self.query_one("#config", OptionList)
        options.clear_options()
        group = None
        highlight = 0
        for index, (value, name, group_name) in enumerate(_select_values(option)):
            if group_name and group_name != group:
                group = group_name
                options.add_option(
                    Option(Content(group_name).stylize("bold $text-muted"), disabled=True)
                )
            marker = "โ— " if value == option.current_value else "  "
            options.add_option(Option(Content(marker + name), id=f"v:{index}"))
            if value == option.current_value:
                highlight = options.option_count - 1
        options.highlighted = highlight
        options.focus()

    def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
        option_id = event.option_id or ""
        if option_id.startswith("o:"):
            option = self.options[int(option_id[2:])]
            if isinstance(option, SelectSessionConfigOption):
                self._show_values(option)
            elif isinstance(option, BooleanSessionConfigOption):
                self.dismiss((option.config_id, not option.current_value))
        elif option_id.startswith("v:") and self.current is not None:
            value = _select_values(self.current)[int(option_id[2:])][0]
            self.dismiss((self.current.config_id, value))

    def action_back(self) -> None:
        """Back to the option list, or close."""
        if self.current is not None:
            self._show_options()
        else:
            self.dismiss(None)

action_back

action_back() -> None

Back to the option list, or close.

Source code in src/acptui/ui/screens/dialogs.py
def action_back(self) -> None:
    """Back to the option list, or close."""
    if self.current is not None:
        self._show_options()
    else:
        self.dismiss(None)

:fa-brands-github: Show source on GitHub