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

Conversation

a-luna
Copy link

@a-luna a-luna commented Feb 6, 2021

Currently, if a user provides a non-ASCII, UTF-8 printable character (e.g., any of the following: äüöëñ0¡¢漢字♀♂) to an Input prompt, the prompt immediately exits and returns None in place of the non-ASCII character.

This PR adds a new function to utils.py, based on a stackoverflow response (Test if a python string is printable):

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)

A call to the is_printable function replaces the line in getchar that checks if each character exists in string.printable :

if is_printable(c):
    return c
else:
    return UNDEFINED_KEY

Here's an example of the new behavior:

Example

from bullet import Input

prompt = Input("Enter a string with UTF-8 printable characters: ")
user_input = prompt.launch()
print(user_input)

Output

Enter a string with UTF-8 printable characters: abcdef äüöëñ 0¡¢ 漢字 ♀♂
abcdef äüöëñ 0¡¢ 漢字 ♀♂

Closes #76

@Behoston
Copy link

Behoston commented Jul 5, 2023

Can you review @bchao1 ?

Chars that still not works for me:

  • ł - AltGr + l, do nothing or works as select all?
  • ń - AltGr + n, moves cursor to the left

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only Ascii characters accepted
2 participants