Skip to content

Commit

Permalink
Fixing buttons and escape character in confirmation dialog
Browse files Browse the repository at this point in the history
darrenburns committed Aug 21, 2024
1 parent 8171be2 commit 98ceca8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/posting/widgets/confirmation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""A modal screen for confirming a destructive action."""

from typing import Literal
from textual import on
from textual.app import ComposeResult
from textual.containers import Horizontal, Vertical
from textual.screen import ModalScreen
@@ -28,9 +29,9 @@ class ConfirmationModal(ModalScreen[bool]):
def __init__(
self,
message: str,
confirm_text: str = "Yes \[y]",
confirm_text: str = "Yes \\[y]",
confirm_binding: str = "y",
cancel_text: str = "No \[n]",
cancel_text: str = "No \\[n]",
cancel_binding: str = "n",
auto_focus: Literal["confirm", "cancel"] | None = "confirm",
name: str | None = None,
@@ -59,3 +60,11 @@ def compose(self) -> ComposeResult:
with Horizontal(id="confirmation-buttons"):
yield Button(self.confirm_text, id="confirm-button")
yield Button(self.cancel_text, id="cancel-button")

@on(Button.Pressed, "#confirm-button")
def confirm(self) -> None:
self.dismiss(True)

@on(Button.Pressed, "#cancel-button")
def cancel(self) -> None:
self.dismiss(False)

0 comments on commit 98ceca8

Please sign in to comment.