Skip to content
Myr

fix encoding issues with getchar

Before adoption: this commit came in with the history the project adopted, so no landing records it.

correctly raises on ^C and ^D echo no longer raises encoding error

authored by David Lord · committed by David Lord · parent 7b22cda · Browse files · 2 files+15 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−5 removed

  • other:+15 added−5 removed

2 files+15 added−5 removed

modified:click/_termui_impl.py+5 added-4 removed
525 unmodified lines
526 return 1527528529def _translate_ch_to_exc(ch):530 if ch == '\x03':530 if ch == u'\x03':531 raise KeyboardInterrupt()532 if ch == '\x04' and not WIN: # Unix-like, Ctrl+D532 if ch == u'\x04' and not WIN: # Unix-like, Ctrl+D533 raise EOFError()534 if ch == '\x1a' and WIN: # Windows, Ctrl+Z534 if ch == u'\x1a' and WIN: # Windows, Ctrl+Z535 raise EOFError()536537538if WIN:
72 unmodified lines
611612 def getchar(echo):613 with raw_terminal() as fd:614 ch = os.read(fd, 32)615 ch = ch.decode(get_best_encoding(sys.stdin), 'replace')616 if echo and isatty(sys.stdout):617 sys.stdout.write(ch)618 _translate_ch_to_exc(ch)618 return ch.decode(get_best_encoding(sys.stdin), 'replace')619 return ch
modified:CHANGES.rst+10 added-1 removed
5 unmodified lines
6-----------78Unreleased910- ``click.getchar()`` now returns unicode in Python 3 on Windows, same as other platforms. (`#1108`_, `#1088`_, `#822`_, `#821`_, `#537`_)10- Drop support for Python 2.6 and 3.3. (`#976`_)11- Wrap ``click.Choice``'s missing message. (`#202`_, `#1000`_)12- Add native ZSH autocompletion support. (`#323`_, `#865`_)13- Document that ANSI color info isn't parsed from bytearrays in Python 2. (`#334`_)
7 unmodified lines
21- Show progressbar only if total execution time is visible. (`#487`_)22- Added the ability to hide commands and options from help. (`#500`_)23- Document that options can be ``required=True``. (`#514`_, `#1022`_)24- Non-standalone calls to ``Context.exit`` return the exit code, rather than calling ``sys.exit``. (`#533`_, `#667`_)25- ``click.getchar()`` now returns unicode in Python 3 on Windows, same as other platforms. (`#537`_, `#821`_, `#822`_, `#1088`_, `#1108`_)26- Added ``FloatRange`` type. (`#538`_, `#553`_)27- Added support for bash completion of ``type=click.Choice`` for ``Options`` and ``Arguments``. (`#535`_)28- Only allow one positional arg for ``Argument`` parameter delcaration. (`#568`_, `#574`_, `#1014`_)29- Add ``case_sensitive=False`` as an option to Choice. (`#569`_)30- ``click.getchar()`` correctly raises ``KeyboardInterrupt`` on "^C" and ``EOFError`` on "^D" on Linux. (`#583`_, `#1115`_)31- Fix encoding issue with ``click.getchar(echo=True)`` on Linux. (`#1115`_)32- ``param_hint`` in errors now derived from param itself. (`#598`_, `#704`_, `#709`_)33- Add a test that ensures that when an argument is formatted into a usage error, its metavar is used, not its name. (`#612`_)34- Allow setting ``prog_name`` as extra in ``CliRunner.invoke``. (`#616`_, `#999`_)35- ``launch`` now works properly under Cygwin. (`#650`_)
70 unmodified lines
106.. _#500: https://github.com/pallets/click/pull/500107.. _#514: https://github.com/pallets/click/issues/514108.. _#533: https://github.com/pallets/click/pull/533109.. _#535: https://github.com/pallets/click/issues/535110.. _#537: https://github.com/pallets/click/issues/537111.. _#538: https://github.com/pallets/click/pull/538112.. _#553: https://github.com/pallets/click/pull/553113.. _#557: https://github.com/pallets/click/pull/557114.. _#568: https://github.com/pallets/click/issues/568115.. _#569: https://github.com/pallets/click/issues/569116.. _#574: https://github.com/pallets/click/issues/574117.. _#583: https://github.com/pallets/click/issues/583118.. _#598: https://github.com/pallets/click/issues/598119.. _#612: https://github.com/pallets/click/pull/612120.. _#616: https://github.com/pallets/click/issues/616121.. _#650: https://github.com/pallets/click/pull/650
27 unmodified lines
149.. _#807: https://github.com/pallets/click/pull/807150.. _#809: https://github.com/pallets/click/pull/809151.. _#816: https://github.com/pallets/click/pull/816152.. _#819: https://github.com/pallets/click/pull/819153.. _#821: https://github.com/pallets/click/issues/821154.. _#822: https://github.com/pallets/click/issues/822155.. _#842: https://github.com/pallets/click/pull/842156.. _#860: https://github.com/pallets/click/issues/860157.. _#862: https://github.com/pallets/click/issues/862158.. _#863: https://github.com/pallets/click/pull/863
52 unmodified lines
211.. _#1055: https://github.com/pallets/click/pull/1055212.. _#1058: https://github.com/pallets/click/pull/1058213.. _#1059: https://github.com/pallets/click/pull/1059214.. _#1061: https://github.com/pallets/click/pull/1061215.. _#1088: https://github.com/pallets/click/issues/1088216.. _#1105: https://github.com/pallets/click/pull/1105217.. _#1108: https://github.com/pallets/click/pull/1108218.. _#1115: https://github.com/pallets/click/pull/1115219220221Version 6.7222-----------
343 unmodified lines