wincmd.rst
This file
Path
docs/wincmd.rst
80 lines · 3.9 KiB
Last changed by
Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835
History of this fileTake it
The walk stopped after 200 commits: lines older than 430c50a point at it.
Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a
lines 1–61why, one step back1Windows Console Notes2=====================34.. versionadded:: 6.056Until Click 6.0 there are various bugs and limitations with using Click on7a Windows console. Most notably the decoding of command line arguments8was performed with the wrong encoding on Python 2 and on all versions of9Python output of unicode characters was impossible. Starting with Click106.0 we now emulate output streams on Windows to support unicode to the11Windows console through separate APIs and we perform different decoding of12parameters.1314Here is a brief overview of how this works and what it means to you.1516Unicode Arguments17-----------------1819Click internally is generally based on the concept that any argument can20come in as either byte string or unicode string and conversion is21performed to the type expected value as late as possible. This has some22advantages as it allows us to accept the data in the most appropriate form23for the operating system and Python version.2425For instance paths are left as bytes on Python 2 unless you explicitly26tell it otherwise.2728This caused some problems on Windows where initially the wrong encoding29was used and garbage ended up in your input data. We not only fixed the30encoding part, but we also now extract unicode parameters from `sys.argv`.3132This means that on Python 2 under Windows, the arguments processed will33*most likely* be of unicode nature and not bytes. This was something that34previously did not really happen unless you explicitly passed in unicode35parameters so your custom types need to be aware of this.3637There is also another limitation with this: if `sys.argv` was modified38prior to invoking a click handler, we have to fall back to the regular39byte input in which case not all unicode values are available but only a40subset of the codepage used for parameters.4142Unicode Output and Input43------------------------4445Unicode output and input on Windows is implemented through the concept of46a dispatching text stream. What this means is that when click first needs47a text output (or input) stream on windows it goes through a few checks to48figure out of a windows console is connected or not. If no Windows49console is present then the text output stream is returned as such and the50encoding for that stream is set to ``utf-8`` like on all platforms.5152However if a console is connected the stream will instead be emulated and53use the cmd.exe unicode APIs to output text information. In this case the54stream will also use ``utf-16-le`` as internal encoding. However there is55some hackery going on that the underlying raw IO buffer is still bypassing56the unicode APIs and byte output through an indirection is still possible.5758This hackery is used on both Python 2 and Python 3 as neither version of59Python has native support for cmd.exe with unicode characters. There are60some limitations you need to be aware of:61Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835
line 62why, one step back62* This unicode support is limited to ``click.echo``, ``click.prompt`` asMerge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a
line 63why, one step back63 well as ``click.get_text_stream``.Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835
line 64why, one step back64* Depending on if unicode values or byte strings are passed the controlMerge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a
lines 65–69why, one step back65 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.Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835
lines 70–76why, one step back70* The raw output stream is set to binary mode, which is a global71 operation on Windows, so ``print`` calls will be affected. Prefer72 ``click.echo`` over ``print``.73* On Windows 7 and below, there is a limitation where at most 64k74 characters can be written in one call in binary mode. In this75 situation, ``sys.stdout`` and ``sys.stderr`` are replaced with76 wrappers that work around the limitation.Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a
lines 77–80why, one step back7778Another important thing to note is that the Windows console's default79fonts do not support a lot of characters which means that you are mostly80limited to international letters but no emojis or special characters.