Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console work #258

Merged
merged 10 commits into from
Jul 4, 2018
Merged

console work #258

merged 10 commits into from
Jul 4, 2018

Conversation

AnthonyLloyd
Copy link
Contributor

@AnthonyLloyd AnthonyLloyd commented Jun 19, 2018

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

  • Flushable logger
  • log using ANSI colour codes
  • log to StringBuilder
  • progress indicator e.g. n/m tests or stress 50% complete
  • flush once complete or from first error
  • pretty print of ligatures etc

@AnthonyLloyd AnthonyLloyd changed the title console work [WIP] console work Jun 19, 2018
@adamchester
Copy link
Contributor

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)?

@AnthonyLloyd
Copy link
Contributor Author

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
Copy link
Contributor

adamchester commented Jun 29, 2018

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: microsoft/WSL#1173 (comment)

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
Copy link
Contributor Author

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


let finishTime =
lazy
totalTicks |> (+) (Stopwatch.GetTimestamp())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that Stopwatch's ticks differs between operating systems and is not the same as DateTime/BCL ticks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you need to use Stopwatch.Frequency to convert between seconds and Stopwatch ticks. It does this in the lines just above here.

@@ -12,10 +12,12 @@
///
/// Changes:
/// Changed namespace to Expecto.Logging and file name to Logging.fs - Anthony Lloyd - 11 Jun 2018
/// Add IFlushable - Anthony Lloyd - 19 Jun 2018
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep a changelog at the top? Feels a bit year 2000.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that it was a good thing to do when making changes to Apache code. To help when back porting the code. Could be got from git but it contains a bit more specific info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging licence
3 participants