haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
668 stars 96 forks source link

console work #258

Closed AnthonyLloyd closed 6 years ago

AnthonyLloyd commented 6 years ago

This PR aims to resolve #256 #249 #248 #230 #190 #161 #152 #147

adamchester commented 6 years ago

Hey @AnthonyLloyd this is looking really good!

I'm curious why you are choosing to create a new logger instead of modifying the LiterateConsoleTarget(https://github.com/haf/expecto/pull/258/files#diff-1d108374b84010eb70bf3a856bb172cfL849)?

Is it possible (and easier?) to provide a new outputWriter that handles ANSI colour codes (only when the OS/terminal supports it)?

adamchester commented 6 years ago

Here's a couple of good resources for ANSI codes and SetConsoleMode + ENABLE_VIRTUAL_TERMINAL_INPUT on windows:

AnthonyLloyd commented 6 years ago

I didn't really think of just creating a new outputWriter. I think because I needed to add Flush. I'll have a look at doing this as I integrate the progress indicator and flush on error. Thanks for the idea.

I tested the SetConsoleMode and it didn't have any effect. I think this is switched on by default now in Windows 10? Should possible consider for legacy versions.

adamchester commented 6 years ago

Hey @AnthonyLloyd, as far as I can tell, it's not going to be just a "legacy" issue. Applications need to "opt in" to VT mode, and if you want to output ANSI sequences, you'll need to "opt in".

When I pulled down this PR to try it out, I actually got the ANSI escape sequences shown on screen instead of the (expected) colours.

See here for information directly from an MS person with knowledge of the situation: https://github.com/Microsoft/WSL/issues/1173#issuecomment-254250445

There's a lot going on in here, so let me try to clarify: The windows console only supports VT sequences of ANY kind with the ConsoleMode set to enable Virtual Terminal support. See This documentation on SetConsoleMode. Specifically, you need to turn on the output mode flag ENABLE_VIRTUAL_TERMINAL_PROCESSING.

By default, cmd.exe enables VT mode for itself. Now here's the confusion:

In 10.0.10586 (or 1511 or TH2), it left this mode on when calling child applications. This meant that anything you launched from cmd would get the new behavior for free. Of course, we found that unsurprisingly broke compatibility, so we had to change that. So... In 10.0.14393 (Anniversary update, or greater), cmd uses VT mode, but then reverts it for launching child processes. So if you wrote a console app that uses VT sequences after October 2015, then tried running it on an AU system, you'll find that the sequences don't work anymore. You'll have to manually turn on VT support with SetConsoleMode yourself. IMPORTANT cmd also wipes out the changes a child makes to the mode. So you can't call enable_vt.exe & myapp.exe and have the VT mode from enable_vt.exe pollute the mode of myapp.exe To further confuse, bash.exe turns on VT mode itself, because obviously, it needs that.

AnthonyLloyd commented 6 years ago

@adamchester Thanks, I'll add this in, best to be safe.