pub fn is_windows_10() -> bool
Detects Windows ≥10.
As mentioned in the
WindowsVt documentation, Windows 10 from the
Threshold 2 Update in November 2015 supports the
mode bit, which enables VT100/ECMA-48 escape sequence processing in the console. This in turn
makes clearing the console vastly easier and is the recommended mode of operation by Microsoft.
However, detecting Windows ≥10 is not trivial. To mitigate broken programs that incorrectly perform version shimming, Microsoft has deprecated most ways to obtain the version of Windows by making the relevant APIs lie unless the calling executable embeds a manifest that explicitely opts-in to support Windows 10.
To be clear, this is the proper way to go. If you are writing an application which uses this library, or indeed any application targeting Windows at all, you should embed such a manifest (and take that opportunity to opt-in to long path support, see e.g. watchexec#163). If you are writing a library on top of this one, it is your responsibility to communicate this requirement to your users.
It is important to remark that it is not possible to manifest twice. In plainer words, libraries must not embed a manifest as that will make it impossible for applications which depend on them to embed their own manifest.
This function tries its best to detect Windows ≥10, and specifically, whether the mentioned mode bit can be used. Critically, it leaves trying to set the bit as feature detection as a last resort, such that an error setting the bit is not confunded with the bit not being supported.
Note that this is only provided to write your own clearscreen logic and should not be relied on for other purposes, as it makes no guarantees of reliable detection, and its internal behaviour may change without notice. Additionally, this will always return false if the library was compiled for a non-Windows target, even if e.g. it’s running under WSL in a Windows 10 host.