-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
fa5ac0d
commit 36664ef
Showing
7 changed files
with
255 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters