summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2018-09-18 10:58:55 -0700
committerDavid Lord <davidism@gmail.com>2018-09-18 11:09:21 -0700
commit7b53e1541eeff3c1823b0059cdf0c71e3dd839da (patch)
tree0cb3ddb1cf7a30d6aea67ce5cce7a410a4814520
parent7b22cdac4777adc50b922e5fbb0926efeb5245c8 (diff)
downloadclick-getchar-exc.tar.gz
fix encoding issues with getchargetchar-exc
correctly raises on ^C and ^D echo no longer raises encoding error
-rw-r--r--CHANGES.rst11
-rw-r--r--click/_termui_impl.py9
2 files changed, 15 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 37255f2..a2fe9df 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -7,7 +7,6 @@ Version 7.0
Unreleased
-- ``click.getchar()`` now returns unicode in Python 3 on Windows, same as other platforms. (`#1108`_, `#1088`_, `#822`_, `#821`_, `#537`_)
- Drop support for Python 2.6 and 3.3. (`#976`_)
- Wrap ``click.Choice``'s missing message. (`#202`_, `#1000`_)
- Add native ZSH autocompletion support. (`#323`_, `#865`_)
@@ -23,10 +22,13 @@ Unreleased
- Added the ability to hide commands and options from help. (`#500`_)
- Document that options can be ``required=True``. (`#514`_, `#1022`_)
- Non-standalone calls to ``Context.exit`` return the exit code, rather than calling ``sys.exit``. (`#533`_, `#667`_)
+- ``click.getchar()`` now returns unicode in Python 3 on Windows, same as other platforms. (`#537`_, `#821`_, `#822`_, `#1088`_, `#1108`_)
- Added ``FloatRange`` type. (`#538`_, `#553`_)
- Added support for bash completion of ``type=click.Choice`` for ``Options`` and ``Arguments``. (`#535`_)
- Only allow one positional arg for ``Argument`` parameter delcaration. (`#568`_, `#574`_, `#1014`_)
- Add ``case_sensitive=False`` as an option to Choice. (`#569`_)
+- ``click.getchar()`` correctly raises ``KeyboardInterrupt`` on "^C" and ``EOFError`` on "^D" on Linux. (`#583`_, `#1115`_)
+- Fix encoding issue with ``click.getchar(echo=True)`` on Linux. (`#1115`_)
- ``param_hint`` in errors now derived from param itself. (`#598`_, `#704`_, `#709`_)
- Add a test that ensures that when an argument is formatted into a usage error, its metavar is used, not its name. (`#612`_)
- Allow setting ``prog_name`` as extra in ``CliRunner.invoke``. (`#616`_, `#999`_)
@@ -105,12 +107,14 @@ Unreleased
.. _#514: https://github.com/pallets/click/issues/514
.. _#533: https://github.com/pallets/click/pull/533
.. _#535: https://github.com/pallets/click/issues/535
+.. _#537: https://github.com/pallets/click/issues/537
.. _#538: https://github.com/pallets/click/pull/538
.. _#553: https://github.com/pallets/click/pull/553
.. _#557: https://github.com/pallets/click/pull/557
.. _#568: https://github.com/pallets/click/issues/568
.. _#569: https://github.com/pallets/click/issues/569
.. _#574: https://github.com/pallets/click/issues/574
+.. _#583: https://github.com/pallets/click/issues/583
.. _#598: https://github.com/pallets/click/issues/598
.. _#612: https://github.com/pallets/click/pull/612
.. _#616: https://github.com/pallets/click/issues/616
@@ -146,6 +150,8 @@ Unreleased
.. _#809: https://github.com/pallets/click/pull/809
.. _#816: https://github.com/pallets/click/pull/816
.. _#819: https://github.com/pallets/click/pull/819
+.. _#821: https://github.com/pallets/click/issues/821
+.. _#822: https://github.com/pallets/click/issues/822
.. _#842: https://github.com/pallets/click/pull/842
.. _#860: https://github.com/pallets/click/issues/860
.. _#862: https://github.com/pallets/click/issues/862
@@ -206,7 +212,10 @@ Unreleased
.. _#1058: https://github.com/pallets/click/pull/1058
.. _#1059: https://github.com/pallets/click/pull/1059
.. _#1061: https://github.com/pallets/click/pull/1061
+.. _#1088: https://github.com/pallets/click/issues/1088
.. _#1105: https://github.com/pallets/click/pull/1105
+.. _#1108: https://github.com/pallets/click/pull/1108
+.. _#1115: https://github.com/pallets/click/pull/1115
Version 6.7
diff --git a/click/_termui_impl.py b/click/_termui_impl.py
index bca27ed..b7fcbb5 100644
--- a/click/_termui_impl.py
+++ b/click/_termui_impl.py
@@ -527,11 +527,11 @@ def open_url(url, wait=False, locate=False):
def _translate_ch_to_exc(ch):
- if ch == '\x03':
+ if ch == u'\x03':
raise KeyboardInterrupt()
- if ch == '\x04' and not WIN: # Unix-like, Ctrl+D
+ if ch == u'\x04' and not WIN: # Unix-like, Ctrl+D
raise EOFError()
- if ch == '\x1a' and WIN: # Windows, Ctrl+Z
+ if ch == u'\x1a' and WIN: # Windows, Ctrl+Z
raise EOFError()
@@ -612,7 +612,8 @@ else:
def getchar(echo):
with raw_terminal() as fd:
ch = os.read(fd, 32)
+ ch = ch.decode(get_best_encoding(sys.stdin), 'replace')
if echo and isatty(sys.stdout):
sys.stdout.write(ch)
_translate_ch_to_exc(ch)
- return ch.decode(get_best_encoding(sys.stdin), 'replace')
+ return ch