Skip to content

CompletionList

Base classes

Name Children Inherits
OptionList
textual.widgets._option_list
A navigable list of options.

⋔ Inheritance diagram

graph TD
  107846719849136["prompt.CompletionList"]
  107846720462688["_option_list.OptionList"]
  107846717872128["scroll_view.ScrollView"]
  107846718749664["containers.ScrollableContainer"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  137699722799616["builtins.object"]
  107846720462688 --> 107846719849136
  107846717872128 --> 107846720462688
  107846718749664 --> 107846717872128
  107846718477920 --> 107846718749664
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

🛈 DocStrings

Bases: OptionList

Completion candidates, shown above the prompt.

Source code in src/acptui/ui/widgets/prompt.py
class CompletionList(OptionList):
    """Completion candidates, shown above the prompt."""

    DEFAULT_CSS = """
    CompletionList {
        height: auto;
        max-height: 8;
        border: none;
        padding: 0;
        background: $panel;
        display: none;
        &.-visible { display: block; }
    }
    """

    def __init__(self) -> None:
        super().__init__(id="completions")
        self.completions: list[Completion] = []
        self.can_focus = False

    def show(self, completions: list[Completion]) -> None:
        """Show candidates (or hide when there are none)."""
        self.completions = completions
        self.clear_options()
        self.add_options(
            Option(
                Content.assemble(
                    (c.label, "bold"), ("  " + c.detail if c.detail else "", "$text-muted")
                )
            )
            for c in completions
        )
        self.set_class(bool(completions), "-visible")
        if completions:
            self.highlighted = 0

    def hide(self) -> None:
        """Hide the list."""
        self.completions = []
        self.set_class(False, "-visible")

    @property
    def is_shown(self) -> bool:
        """Whether candidates are shown."""
        return self.has_class("-visible")

    @property
    def selected(self) -> Completion | None:
        """The highlighted candidate."""
        index = self.highlighted
        if index is None or not (0 <= index < len(self.completions)):
            return None
        return self.completions[index]

is_shown property

is_shown: bool

Whether candidates are shown.

selected property

selected: Completion | None

The highlighted candidate.

hide

hide() -> None

Hide the list.

Source code in src/acptui/ui/widgets/prompt.py
def hide(self) -> None:
    """Hide the list."""
    self.completions = []
    self.set_class(False, "-visible")

show

show(completions: list[Completion]) -> None

Show candidates (or hide when there are none).

Source code in src/acptui/ui/widgets/prompt.py
def show(self, completions: list[Completion]) -> None:
    """Show candidates (or hide when there are none)."""
    self.completions = completions
    self.clear_options()
    self.add_options(
        Option(
            Content.assemble(
                (c.label, "bold"), ("  " + c.detail if c.detail else "", "$text-muted")
            )
        )
        for c in completions
    )
    self.set_class(bool(completions), "-visible")
    if completions:
        self.highlighted = 0

:fa-brands-github: Show source on GitHub