diff options
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/tui/app.py')
| -rw-r--r-- | packages/meshbay-cli/src/meshbay_cli/tui/app.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/tui/app.py b/packages/meshbay-cli/src/meshbay_cli/tui/app.py index fe7fa2c..7abb149 100644 --- a/packages/meshbay-cli/src/meshbay_cli/tui/app.py +++ b/packages/meshbay-cli/src/meshbay_cli/tui/app.py @@ -12,7 +12,9 @@ the log goes to a file in the CLI's data directory instead. import logging +from textual import events from textual.app import App +from textual.errors import NoWidget from ..client.account import Account, no_passphrase from ..client.hub import Hub @@ -31,6 +33,7 @@ class MeshBayApp(App): self.hub = ctx.hub # The screen a signed-in account lands on, made from the account. self.home = home + self._right_click_taken = False async def use_hub(self, url: str) -> None: if url != self.hub.url: @@ -39,6 +42,26 @@ class MeshBayApp(App): self.ctx.hub = self.hub self.ctx.hub_url = url + async def on_event(self, event: events.Event) -> None: + """A right-click goes to the widget under it when it has a use for one + (the chat's copy and paste), before Textual takes it for a selection.""" + if (isinstance(event, (events.MouseDown, events.MouseUp)) and event.button == 3 + and not event.is_forwarded): + if isinstance(event, events.MouseDown): + try: + widget, _ = self.get_widget_at(event.x, event.y) + except NoWidget: + widget = None + handler = getattr(widget, "right_click", None) + self._right_click_taken = handler is not None + if handler is not None: + await handler(event) + return + elif self._right_click_taken: + self._right_click_taken = False + return + await super().on_event(event) + def on_mount(self) -> None: account = None if self.ctx.store.peek().get("hub") == self.hub.url: |