Files
textual/tests/snapshot_tests/snapshot_apps/key_display.py
darrenburns 36664ef7ae Sensible default key displays + allow users to override key displays at the App level (#1213)
* Get rid of string split key display

* Include screen level bindings when no widget is focused

* Add default key display mappings

* Allow user to customise key display at app level

* Better docstring

* Update CHANGELOG.md
2022-11-18 14:05:45 +00:00

37 lines
1.1 KiB
Python

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer
class KeyDisplayApp(App):
"""Tests how keys are displayed in the Footer, and ensures
that overriding the key_displays works as expected.
Exercises both the built-in Textual key display replacements,
and user supplied replacements.
Will break when we update the Footer - but we should add a similar
test (or updated snapshot) for the updated Footer."""
BINDINGS = [
Binding("question_mark", "question", "Question"),
Binding("ctrl+q", "quit", "Quit app"),
Binding("escape", "escape", "Escape"),
Binding("a", "a", "Letter A"),
]
def compose(self) -> ComposeResult:
yield Footer()
def get_key_display(self, key: str) -> str:
key_display_replacements = {
"escape": "Escape!",
"ctrl+q": "^q",
}
display = key_display_replacements.get(key)
if display:
return display
return super().get_key_display(key)
app = KeyDisplayApp()
if __name__ == '__main__':
app.run()