Skip to content
Myr

wincmd.rst

This file

Path

docs/wincmd.rst

64 lines · 3.1 KiB

Last changed by

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

History of this file

Take it

The walk stopped after 200 commits: lines older than 5210849 point at it.

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 1–5why, one step back
1Windows Console Notes
2=====================34.. versionadded:: 6.05

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 6why, one step back
6Click emulates output streams on Windows to support unicode to the

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 7–45why, one step back
7Windows console through separate APIs and we perform different decoding of
8parameters.910Here is a brief overview of how this works and what it means to you.1112Unicode Arguments13-----------------1415Click internally is generally based on the concept that any argument can16come in as either byte string or unicode string and conversion is17performed to the type expected value as late as possible. This has some18advantages as it allows us to accept the data in the most appropriate form19for the operating system and Python version.2021This caused some problems on Windows where initially the wrong encoding22was used and garbage ended up in your input data. We not only fixed the23encoding part, but we also now extract unicode parameters from `sys.argv`.2425There is also another limitation with this: if `sys.argv` was modified26prior to invoking a click handler, we have to fall back to the regular27byte input in which case not all unicode values are available but only a28subset of the codepage used for parameters.2930Unicode Output and Input31------------------------3233Unicode output and input on Windows is implemented through the concept of34a dispatching text stream. What this means is that when click first needs35a text output (or input) stream on windows it goes through a few checks to36figure out of a windows console is connected or not. If no Windows37console is present then the text output stream is returned as such and the38encoding for that stream is set to ``utf-8`` like on all platforms.3940However if a console is connected the stream will instead be emulated and41use the cmd.exe unicode APIs to output text information. In this case the42stream will also use ``utf-16-le`` as internal encoding. However there is43some hackery going on that the underlying raw IO buffer is still bypassing44the unicode APIs and byte output through an indirection is still possible.45

Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835

line 46why, one step back
46* This unicode support is limited to ``click.echo``, ``click.prompt`` as

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

line 47why, one step back
47 well as ``click.get_text_stream``.

Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835

line 48why, one step back
48* Depending on if unicode values or byte strings are passed the control

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 49–53why, one step back
49 flow goes completely different places internally which can have some
50 odd artifacts if data partially ends up being buffered. Click51 attempts to protect against that by manually always flushing but if52 you are mixing and matching different string types to ``stdout`` or53 ``stderr`` you will need to manually flush.

Merge pull request #830 from segevfiner/not-enough-space-workaroundDavid Lordbefore adoptiona589835

lines 54–60why, one step back
54* The raw output stream is set to binary mode, which is a global
55 operation on Windows, so ``print`` calls will be affected. Prefer56 ``click.echo`` over ``print``.57* On Windows 7 and below, there is a limitation where at most 64k58 characters can be written in one call in binary mode. In this59 situation, ``sys.stdout`` and ``sys.stderr`` are replaced with60 wrappers that work around the limitation.

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 61–64why, one step back
61
62Another important thing to note is that the Windows console's default63fonts do not support a lot of characters which means that you are mostly64limited to international letters but no emojis or special characters.