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

Allow UTF-8 printable chars , not just ASCII #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion bullet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def getchar():
return getchar()

else:
if c in string.printable:
if is_printable(c):
return c
else:
return UNDEFINED_KEY
Expand Down Expand Up @@ -117,3 +117,14 @@ def cprint(
None
'''
forceWrite(on + color + s + colors.RESET, end = end)

def is_printable(s: str) -> bool:
"""Determine if a string contains only printable characters.
Args:
s: The string to verify.
Returns:
bool: `True` if all characters in `s` are printable. `False` if any
characters in `s` can not be printed.
"""
# Ref: https://stackoverflow.com/a/50731077
return not any(repr(ch).startswith(("'\\x", "'\\u")) for ch in s)