Skip to content
Open
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
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)