mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* 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
37 lines
1.1 KiB
Python
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()
|