Merge pull request #12 from jepler/cancel-search-etc

Cancel search on F9 or Esc press
This commit is contained in:
Jeff Epler 2024-05-23 07:40:09 -04:00 committed by GitHub
commit cd0a7912bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -12,6 +12,7 @@ jobs:
release: release:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
environment: release
permissions: permissions:
# IMPORTANT: this permission is mandatory for trusted publishing # IMPORTANT: this permission is mandatory for trusted publishing
id-token: write id-token: write

View file

@ -30,6 +30,10 @@ import pyotp
import platformdirs import platformdirs
import tomllib import tomllib
from textual._ansi_sequences import ANSI_SEQUENCES_KEYS
from textual.keys import Keys
from typing import TypeGuard # use `typing_extensions` for Python 3.9 and below
# workaround for pyperclip being un-typed # workaround for pyperclip being un-typed
if TYPE_CHECKING: if TYPE_CHECKING:
@ -42,8 +46,6 @@ else:
from pyperclip import paste as pyperclip_paste from pyperclip import paste as pyperclip_paste
from pyperclip import copy as pyperclip_copy from pyperclip import copy as pyperclip_copy
from typing import TypeGuard # use `typing_extensions` for Python 3.9 and below
def is_str_list(val: Any) -> TypeGuard[list[str]]: def is_str_list(val: Any) -> TypeGuard[list[str]]:
"""Determines whether all objects in the list are strings""" """Determines whether all objects in the list are strings"""
@ -52,6 +54,12 @@ def is_str_list(val: Any) -> TypeGuard[list[str]]:
return all(isinstance(x, str) for x in val) return all(isinstance(x, str) for x in val)
# Monkeypatch escape key as meaning "F9", WFM
# ignore typing here because ANSI_SEQUENCES_KEYS is a Mapping[] which is read-only as
# far as mypy is concerned.
ANSI_SEQUENCES_KEYS["\x1b\x1b"] = (Keys.F9,) # type: ignore
# Copied from pyotp with the issuer mismatch check removed and HTOP support removed # Copied from pyotp with the issuer mismatch check removed and HTOP support removed
def parse_uri(uri: str) -> pyotp.TOTP: def parse_uri(uri: str) -> pyotp.TOTP:
""" """
@ -176,6 +184,7 @@ class SearchInput(Input, can_focus=False):
Binding("up", "focus_previous", show=False), Binding("up", "focus_previous", show=False),
Binding("down", "focus_next", show=False), Binding("down", "focus_next", show=False),
Binding("ctrl+a", "clear_search", "Show all", show=True), Binding("ctrl+a", "clear_search", "Show all", show=True),
Binding("F9", "clear_search", show=True),
] ]
def on_focus(self) -> None: def on_focus(self) -> None: