serilog-sinks-console icon indicating copy to clipboard operation
serilog-sinks-console copied to clipboard

Provide an adaptive theme

Open nblumhardt opened this issue 7 years ago • 1 comments

The ANSI themes provided with this sink look the best, but aren't supported on many Windows versions, and shouldn't be used unless the output is going to a terminal. Some users don't want theming at all.

This creates a bit of a challenge for portable apps that want to look good.

Could we create an AdaptiveConsoleTheme.Default (plus some other portable variants like Grayscale) that dispatches to either SystemConsoleTheme, AnsiConsoleTheme or ConsoleTheme.None depending on the run-time environment?

This would choose ANSI output when supported, Windows console theming when appropriate, or no theming when output is piped or the user has indicated they do not want color output (see below).

Terminal capability detection is a bit of a minefield; http://bixense.com/clicolors/ and http://no-color.org/ propose some environment-variable-based tactics that we might also include support for.

nblumhardt avatar Feb 07 '18 06:02 nblumhardt

@nblumhardt I was debugging into the Console sink this morning chasing that $type thing it outputs, and started thinking about the fact that I've got a cross-platform (Win / Linux / OSX) ncurses wrapper in the works. At the time I was considering a spinoff of this sink dependent on ncurses, then I saw this issue. It might make this problem a lot easier to solve.

The main implementation is done and tested and working on all three platforms, I just need to document it and package it. (I'd also planned more samples etc but those wouldn't block usage.)

Even if you don't like an ncurses dependency, you should check out the cross-platform support. It is 100% transparent to the dependent application, except when you get an oddball Linux platform that uses a different library name, but I have provisions for easily supporting that, too.

https://github.com/MV10/dotnet-curses

Since I don't have docs, you can read about it on my blog here.

MV10 avatar Aug 26 '18 16:08 MV10