Fixes #5 by adding a global static property to avoid exceptions when executed in enviornments where console is not present (such as LINQPad).
Turns out, detecting if your code has a console attached is a non-trivial process. :rofl: at Microsoft.
The only reliable way I could find is to actually call the underlying Console.WindowHeight/Width API and wait for it to throw an exception to test if a console is present or not.
Environment.UserInteractive is true in LINQPad and in a standard Console Application.
Structured error handling (SHE) is the only reliably way to check if the console is attached or not; but using SHE is a performance killer.
So, I mostly opted for a global flag. The reason it's global was mostly because TableConfiguration.Unicode() is static and set defaults where Console.OutputEncoding is getting set too; which throws again and so the flag can't be an instance flag during TableConfiguration construction.
I guess it's okay since it's kind of an obscure scenario with how I'm using this; but it does work pretty well now in LINQPad. :+1:
Turns out, detecting if your code has a console attached is a non-trivial process. :rofl: at Microsoft.
The only reliable way I could find is to actually call the underlying
Console.WindowHeight/Width
API and wait for it to throw an exception to test if a console is present or not.https://stackoverflow.com/questions/6408588/how-to-tell-if-there-is-a-console
https://stackoverflow.com/questions/1188658/how-can-a-c-sharp-windows-console-application-tell-if-it-is-run-interactively
Environment.UserInteractive
istrue
in LINQPad and in a standard Console Application.Structured error handling (SHE) is the only reliably way to check if the console is attached or not; but using SHE is a performance killer.
So, I mostly opted for a global flag. The reason it's global was mostly because
TableConfiguration.Unicode()
is static and set defaults whereConsole.OutputEncoding
is getting set too; which throws again and so the flag can't be an instance flag duringTableConfiguration
construction.I guess it's okay since it's kind of an obscure scenario with how I'm using this; but it does work pretty well now in LINQPad. :+1: