Documented wincmd
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent ae5412d · Browse files · 4 files·+96 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+96 added−1 removed
- other:+96 added−1 removed
Provenance
- Commit
7e8da4b- Tree
1b6cc09- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
ae5412d
4 files changed+96 added−1 removed
modified:docs/index.rst+1 added
73 unmodified lines74 utils75 bashcomplete76 exceptions77 python378+ wincmd79 80 API Reference81 -------------82 18 unmodified linesmodified:docs/python3.rst+3 added-1 removed
137 unmodified lines138 139 export LC_ALL=C.UTF-8140 export LANG=C.UTF-8141 142-To see which locales are supported you can invoke ``locale -a``::142+On some systems it was reported that `UTF-8` has to be written as `UTF8`143+and vice versa. To see which locales are supported you can invoke144+``locale -a``::145 146 locale -a147 148 You need to do this before you invoke your Python script. If you are35 unmodified linesmodified:docs/utils.rst+19 added
28 unmodified lines29 suppressed by passing ``nl=False``::30 31 click.echo(b'\xe2\x98\x83', nl=False)32 33+Last but not least :func:`echo` uses click's intelligent internal output34+streams to stdout and stderr which support unicode output on the Windows35+console. This means for as long as you are using `click.echo` you can36+output unicode character (there are some limitations on the default font37+with regards to which characters can be displayed). This functionality is38+new in Click 6.0.39+40+.. versionadded:: 6.041+42+Click now emulates output streams on Windows to support unicode to the43+Windows console through separate APIs. For more information see44+`wincmd`_.45+46 .. versionadded:: 3.047 48 Starting with Click 3.0 you can also easily print to standard error by49 passing ``err=True``::228 unmodified lines278 279 stdin_text = click.get_text_stream('stdin')280 stdout_binary = click.get_binary_stream('stdout')281 282+.. versionadded:: 6.0283 284+Click now emulates output streams on Windows to support unicode to the285+Windows console through separate APIs. For more information see286+`wincmd`_.287+288+289 Intelligent File Opening290 ------------------------291 292 .. versionadded:: 3.0106 unmodified linesadded:docs/wincmd.rst+73 added
1+Windows Console Notes2+=====================3+4+.. versionadded:: 6.05+6+Until Click 6.0 there are various bugs and limitations with using Click on7+a Windows console. Most notably the decoding of command line arguments8+was performed with the wrong encoding on Python 2 and on all versions of9+Python output of unicode characters was impossible. Starting with Click10+6.0 we now emulate output streams on Windows to support unicode to the11+Windows console through separate APIs and we perform different decoding of12+parameters.13+14+Here is a brief overview of how this works and what it means to you.15+16+Unicode Arguments17+-----------------18+19+Click internally is generally based on the concept that any argument can20+come in as either byte string or unicode string and conversion is21+performed to the type expected value as late as possible. This has some22+advantages as it allows us to accept the data in the most appropriate form23+for the operating system and Python version.24+25+For instance paths are left as bytes on Python 2 unless you explicitly26+tell it otherwise.27+28+This caused some problems on Windows where initially the wrong encoding29+was used and garbage ended up in your input data. We not only fixed the30+encoding part, but we also now extract unicode parameters from `sys.argv`.31+32+This means that on Python 2 under Windows, the arguments processed will33+*most likely* be of unicode nature and not bytes. This was something that34+previously did not really happen unless you explicitly passed in unicode35+parameters so your custom types need to be aware of this.36+37+There is also another limitation with this: if `sys.argv` was modified38+prior to invoking a click handler, we have to fall back to the regular39+byte input in which case not all unicode values are available but only a40+subset of the codepage used for parameters.41+42+Unicode Output and Input43+------------------------44+45+Unicode output and input on Windows is implemented through the concept of46+a dispatching text stream. What this means is that when click first needs47+a text output (or input) stream on windows it goes through a few checks to48+figure out of a windows console is connected or not. If no Windows49+console is present then the text output stream is returned as such and the50+encoding for that stream is set to ``utf-8`` like on all platforms.51+52+However if a console is connected the stream will instead be emulated and53+use the cmd.exe unicode APIs to output text information. In this case the54+stream will also use ``utf-16-le`` as internal encoding. However there is55+some hackery going on that the underlying raw IO buffer is still bypassing56+the unicode APIs and byte output through an indirection is still possible.57+58+This hackery is used on both Python 2 and Python 3 as neither version of59+Python has native support for cmd.exe with unicode characters. There are60+some limitations you need to be aware of:61+62+* this unicode support is limited to ``click.echo``, ``click.prompt`` as63+ well as ``click.get_text_stream``.64+* depending on if unicode values or byte strings are passed the control65+ flow goes completely different places internally which can have some66+ odd artifacts if data partially ends up being buffered. Click67+ attempts to protect against that by manually always flushing but if68+ you are mixing and matching different string types to ``stdout`` or69+ ``stderr`` you will need to manually flush.70+71+Another important thing to note is that the Windows console's default72+fonts do not support a lot of characters which means that you are mostly73+limited to international letters but no emojis or special characters.