Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure only printable keys added to footer #1361

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed

- Ensure only printable characters are used as key_display https://github.com/Textualize/textual/pull/1361

## [0.6.0] - 2022-12-11

Expand Down
1 change: 1 addition & 0 deletions docs/examples/widgets/footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FooterApp(App):
description="Show help screen",
key_display="?",
),
Binding(key="delete", action="delete", description="Delete the thing"),
Binding(key="j", action="down", description="Scroll down", show=False),
]

Expand Down
11 changes: 8 additions & 3 deletions src/textual/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,14 @@ def _get_key_display(key: str) -> str:
return display_alias

original_key = REPLACED_KEYS.get(key, key)
upper_original = original_key.upper().replace("_", " ")
try:
unicode_character = unicodedata.lookup(original_key.upper().replace("_", " "))
unicode_character = unicodedata.lookup(upper_original)
except KeyError:
return original_key.upper()
return upper_original

return unicode_character
# Check if printable. `delete` for example maps to a control sequence
# which we don't want to write to the terminal.
if unicode_character.isprintable():
return unicode_character
return upper_original
Loading