Skip to content
Myr

wincmd.md

This file

Path

docs/wincmd.md

49 lines · 3.0 KiB · Markdown

Last changed by

Merge branch 'stable'David Lordbefore adoptiona9a218c

History of this file

Take it

Move Wincmd and Virtualenv docs from reST to MyST (#2954)Rowlando13before adoption499bbee

lines 1–25why, one step back
1# Windows Console Notes
23```{versionadded} 6.04```56Click emulates output streams on Windows to support unicode to the Windows console through separate APIs and we perform7different decoding of parameters.89Here is a brief overview of how this works and what it means to you.1011## Unicode Arguments1213Click internally is generally based on the concept that any argument can come in as either byte string or unicode string14and conversion is performed to the type expected value as late as possible. This has some advantages as it allows us to15accept the data in the most appropriate form for the operating system and Python version.1617This caused some problems on Windows where initially the wrong encoding was used and garbage ended up in your input18data. We not only fixed the encoding part, but we also now extract unicode parameters from `sys.argv`.1920There is also another limitation with this: if `sys.argv` was modified prior to invoking a click handler, we have to21fall back to the regular byte input in which case not all unicode values are available but only a subset of the codepage22used for parameters.2324## Unicode Output and Input25

Merge branch 'stable'David Lordbefore adoptiona9a218c

lines 26–31why, one step back
26Unicode output and input on Windows is implemented through the concept of a
27dispatching text stream. This means that when click first needs a text output28(or input) stream on windows it goes through a few checks to figure out if a29windows console is connected or not. If no Windows console is present then the30text output stream is returned as such and the encoding for that stream is set31to `utf-8` like on all platforms.

Move Wincmd and Virtualenv docs from reST to MyST (#2954)Rowlando13before adoption499bbee

lines 32–49why, one step back
32
33However if a console is connected the stream will instead be emulated and use the cmd.exe unicode APIs to output text34information. In this case the stream will also use `utf-16-le` as internal encoding. However there is some hackery going35on that the underlying raw IO buffer is still bypassing the unicode APIs and byte output through an indirection is still36possible.3738- This unicode support is limited to `click.echo`, `click.prompt` as well as `click.get_text_stream`.39- Depending on if unicode values or byte strings are passed the control flow goes completely different places internally40 which can have some odd artifacts if data partially ends up being buffered. Click attempts to protect against that by41 manually always flushing but if you are mixing and matching different string types to `stdout` or `stderr` you will42 need to manually flush.43- The raw output stream is set to binary mode, which is a global operation on Windows, so `print` calls will be44 affected. Prefer `click.echo` over `print`.45- On Windows 7 and below, there is a limitation where at most 64k characters can be written in one call in binary mode.46 In this situation, `sys.stdout` and `sys.stderr` are replaced with wrappers that work around the limitation.4748Another important thing to note is that the Windows console's default fonts do not support a lot of characters which49means that you are mostly limited to international letters but no emojis or special characters.