from textual import on from textual.app import ComposeResult from textual.screen import ModalScreen from textual.widgets import Input, Label, Button from textual.containers import Horizontal, Vertical class CreateTaskScreen(ModalScreen[str]): def compose(self) -> ComposeResult: yield Vertical( Horizontal( Label("$>", id="task_prompt"), Label("task add ", id="task_prompt_label"), Input(placeholder="arguments", id="task_input"), ), Horizontal( Button("Cancel", id="cancel"), Button("Submit", id="submit", variant="primary"), ), id="create_task_container", classes="modal_screen" ) @on(Input.Submitted) def handle_task_args(self) -> None: input_widget = self.query_one("#task_input", Input) self.visible = False self.disabled = True self.loading = True task_args = input_widget.value self.dismiss(task_args) def on_key(self, event) -> None: if (event.key == "escape" or event.key == "ctrl+c"): self.dismiss() def button_on_click(self, event): if event.button.id == "cancel": self.dismiss() elif event.button.id == "submit": input_widget = self.query_one("#task_input", Input) task_args = input_widget.value self.dismiss(task_args)