Skip to content

Handling of special characters in getchar #821

Closed

Description

@pkch

When the user presses arrow up, the click.getchar() returns b'\xe0'. This behavior is probably good, but I guess it should be documented (along with other special characters), since it's not a valid utf-8 value even though the terminal encoding is utf-8. (The naive click.getchar().decode('utf-8') would crash on this example with UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 0: unexpected end of data.)

Activity

  1. fdavis commented on May 17, 2018

    @fdavis
    Contributor

    hey @pkch is this still an issue for you? I don't seem to get this running on master (different python3 invocation because I seem to get a str type back in py3)

    (.clickve) [~/git/click]$ python2 -c 'import click;print(click.getchar().decode("utf-8").__repr__())'
    u'\x1b[A'
    (.clickve) [~/git/click]$ python -c 'import click;print(bytes(click.getchar(),"utf-8").__repr__())'
    b'\x1b[A'
    
  2. added 2 commits that reference this issue on Oct 8, 2018
  3. added a commit that references this issue on Oct 29, 2018
  4. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  5. added
    docs
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions