Skip to content

TextInputScreen

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
  107846718964608["dialogs.TextInputScreen"]
  107846717906624["screen.ModalScreen"]
  107846717858048["screen.Screen"]
  107846685555472["typing.Generic"]
  137699722799616["builtins.object"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  107846717906624 --> 107846718964608
  107846717858048 --> 107846717906624
  107846685555472 --> 107846717858048
  137699722799616 --> 107846685555472
  107846718477920 --> 107846717858048
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

๐Ÿ›ˆ DocStrings

Bases: ModalScreen[str | None]

Asks for one line of text.

Source code in src/acptui/ui/screens/dialogs.py
class TextInputScreen(ModalScreen[str | None]):
    """Asks for one line of text."""

    DEFAULT_CSS = "TextInputScreen {" + DIALOG_CSS + "}"
    BINDINGS: ClassVar = [Binding("escape", "dismiss_none", "Cancel")]

    def __init__(self, title: str, value: str = "") -> None:
        super().__init__()
        self.title_text = title
        self.value = value

    def compose(self) -> ComposeResult:
        with Vertical(id="dialog"):
            yield Static(Content(self.title_text), id="dialog-title")
            yield Input(self.value, id="text")
            yield Static("enter: save ยท escape: cancel", id="dialog-hint")

    def on_input_submitted(self, event: Input.Submitted) -> None:
        self.dismiss(event.value.strip() or None)

    def action_dismiss_none(self) -> None:
        """Cancel."""
        self.dismiss(None)

action_dismiss_none

action_dismiss_none() -> None

Cancel.

Source code in src/acptui/ui/screens/dialogs.py
def action_dismiss_none(self) -> None:
    """Cancel."""
    self.dismiss(None)

:fa-brands-github: Show source on GitHub