diff --git a/README.md b/README.md index 263d303..7adc13e 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ The following built-in themes are available: * `AnsiConsoleTheme.Literate` - an ANSI 256-color version of the "literate" theme * `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme * `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme - * `AnsiConsoleTheme.Sixteen` - an ANSI 16-color version of the "literate" theme that works with light and dark backgrounds + * `AnsiConsoleTheme.Sixteen` - an ANSI 16-color theme that works well with both light and dark backgrounds Adding a new theme is straightforward; examples can be found in the [`SystemConsoleThemes`](https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs) and [`AnsiConsoleThemes`](https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs) classes. diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs index 87bee56..1728aa0 100644 --- a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs @@ -18,27 +18,6 @@ namespace Serilog.Sinks.SystemConsole.Themes { static class AnsiConsoleThemes { - const string Reset = "\x1b[0m"; - const string Bold = "\x1b[1m"; - - const string Black = "\x1b[30m"; - const string Red = "\x1b[31m"; - const string Green = "\x1b[32m"; - const string Yellow = "\x1b[33m"; - const string Blue = "\x1b[34m"; - const string Magenta = "\x1b[35m"; - const string Cyan = "\x1b[36m"; - const string White = "\x1b[37m"; - - const string BrightBlack = "\x1b[30;1m"; - const string BrightRed = "\x1b[31;1m"; - const string BrightGreen = "\x1b[32;1m"; - const string BrightYellow = "\x1b[33;1m"; - const string BrightBlue = "\x1b[34;1m"; - const string BrightMagenta = "\x1b[35;1m"; - const string BrightCyan = "\x1b[36;1m"; - const string BrightWhite = "\x1b[37;1m"; - public static AnsiConsoleTheme Literate { get; } = new AnsiConsoleTheme( new Dictionary { @@ -105,22 +84,22 @@ static class AnsiConsoleThemes public static AnsiConsoleTheme Sixteen { get; } = new AnsiConsoleTheme( new Dictionary { - [ConsoleThemeStyle.Text] = Reset, - [ConsoleThemeStyle.SecondaryText] = Reset, - [ConsoleThemeStyle.TertiaryText] = Reset, - [ConsoleThemeStyle.Invalid] = Yellow, - [ConsoleThemeStyle.Null] = Blue, - [ConsoleThemeStyle.Name] = Reset, - [ConsoleThemeStyle.String] = Cyan, - [ConsoleThemeStyle.Number] = Magenta, - [ConsoleThemeStyle.Boolean] = Blue, - [ConsoleThemeStyle.Scalar] = Green, - [ConsoleThemeStyle.LevelVerbose] = Reset, - [ConsoleThemeStyle.LevelDebug] = Bold, - [ConsoleThemeStyle.LevelInformation] = BrightCyan, - [ConsoleThemeStyle.LevelWarning] = BrightYellow, - [ConsoleThemeStyle.LevelError] = BrightRed, - [ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m", + [ConsoleThemeStyle.Text] = AnsiEscapeSequence.Unthemed, + [ConsoleThemeStyle.SecondaryText] = AnsiEscapeSequence.Unthemed, + [ConsoleThemeStyle.TertiaryText] = AnsiEscapeSequence.Unthemed, + [ConsoleThemeStyle.Invalid] = AnsiEscapeSequence.Yellow, + [ConsoleThemeStyle.Null] = AnsiEscapeSequence.Blue, + [ConsoleThemeStyle.Name] = AnsiEscapeSequence.Unthemed, + [ConsoleThemeStyle.String] = AnsiEscapeSequence.Cyan, + [ConsoleThemeStyle.Number] = AnsiEscapeSequence.Magenta, + [ConsoleThemeStyle.Boolean] = AnsiEscapeSequence.Blue, + [ConsoleThemeStyle.Scalar] = AnsiEscapeSequence.Green, + [ConsoleThemeStyle.LevelVerbose] = AnsiEscapeSequence.Unthemed, + [ConsoleThemeStyle.LevelDebug] = AnsiEscapeSequence.Bold, + [ConsoleThemeStyle.LevelInformation] = AnsiEscapeSequence.BrightCyan, + [ConsoleThemeStyle.LevelWarning] = AnsiEscapeSequence.BrightYellow, + [ConsoleThemeStyle.LevelError] = AnsiEscapeSequence.BrightRed, + [ConsoleThemeStyle.LevelFatal] = AnsiEscapeSequence.BrightRed, }); } } diff --git a/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs new file mode 100644 index 0000000..2512190 --- /dev/null +++ b/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiEscapeSequence.cs @@ -0,0 +1,41 @@ +// Copyright 2017 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Serilog.Sinks.SystemConsole.Themes +{ + static class AnsiEscapeSequence + { + public const string Unthemed = ""; + public const string Reset = "\x1b[0m"; + public const string Bold = "\x1b[1m"; + + public const string Black = "\x1b[30m"; + public const string Red = "\x1b[31m"; + public const string Green = "\x1b[32m"; + public const string Yellow = "\x1b[33m"; + public const string Blue = "\x1b[34m"; + public const string Magenta = "\x1b[35m"; + public const string Cyan = "\x1b[36m"; + public const string White = "\x1b[37m"; + + public const string BrightBlack = "\x1b[30;1m"; + public const string BrightRed = "\x1b[31;1m"; + public const string BrightGreen = "\x1b[32;1m"; + public const string BrightYellow = "\x1b[33;1m"; + public const string BrightBlue = "\x1b[34;1m"; + public const string BrightMagenta = "\x1b[35;1m"; + public const string BrightCyan = "\x1b[36;1m"; + public const string BrightWhite = "\x1b[37;1m"; + } +} \ No newline at end of file