Skip to content

Commit 59423bd

Browse files
committed
feat: add sixteen colors theme
supports light terminal background
1 parent 55bf3d5 commit 59423bd

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleTheme.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public class AnsiConsoleTheme : ConsoleTheme
3030
/// </summary>
3131
public static AnsiConsoleTheme Code { get; } = AnsiConsoleThemes.Code;
3232

33-
/// <summary>
34-
/// A 16-color theme along the lines of Visual Studio Code that should work on light backgrounds.
35-
/// </summary>
36-
public static AnsiConsoleTheme Code16Color { get; } = AnsiConsoleThemes.Code16Color;
37-
3833
/// <summary>
3934
/// A theme using only gray, black and white.
4035
/// </summary>
@@ -48,7 +43,7 @@ public class AnsiConsoleTheme : ConsoleTheme
4843
/// <summary>
4944
/// A theme in the style of the original <i>Serilog.Sinks.Literate</i> using only standard 16 terminal colors that will work on light backgrounds.
5045
/// </summary>
51-
public static AnsiConsoleTheme Literate16Color { get; } = AnsiConsoleThemes.Literate16Color;
46+
public static AnsiConsoleTheme Sixteen { get; } = AnsiConsoleThemes.Sixteen;
5247

5348
readonly IReadOnlyDictionary<ConsoleThemeStyle, string> _styles;
5449
const string AnsiStyleReset = "\x1b[0m";

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,6 @@ static class AnsiConsoleThemes
6060
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m",
6161
});
6262

63-
public static AnsiConsoleTheme Literate16Color { get; } = new AnsiConsoleTheme(
64-
new Dictionary<ConsoleThemeStyle, string>
65-
{
66-
[ConsoleThemeStyle.Text] = Reset,
67-
[ConsoleThemeStyle.SecondaryText] = Reset,
68-
[ConsoleThemeStyle.TertiaryText] = Reset,
69-
[ConsoleThemeStyle.Invalid] = Yellow,
70-
[ConsoleThemeStyle.Null] = Blue,
71-
[ConsoleThemeStyle.Name] = Reset,
72-
[ConsoleThemeStyle.String] = Cyan,
73-
[ConsoleThemeStyle.Number] = Magenta,
74-
[ConsoleThemeStyle.Boolean] = Blue,
75-
[ConsoleThemeStyle.Scalar] = Green,
76-
[ConsoleThemeStyle.LevelVerbose] = Reset,
77-
[ConsoleThemeStyle.LevelDebug] = Bold,
78-
[ConsoleThemeStyle.LevelInformation] = BrightCyan,
79-
[ConsoleThemeStyle.LevelWarning] = BrightYellow,
80-
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0015m\x1b[48;5;0196m",
81-
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m",
82-
});
83-
8463
public static AnsiConsoleTheme Grayscale { get; } = new AnsiConsoleTheme(
8564
new Dictionary<ConsoleThemeStyle, string>
8665
{
@@ -123,25 +102,25 @@ static class AnsiConsoleThemes
123102
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m",
124103
});
125104

126-
public static AnsiConsoleTheme Code16Color { get; } = new AnsiConsoleTheme(
105+
public static AnsiConsoleTheme Sixteen { get; } = new AnsiConsoleTheme(
127106
new Dictionary<ConsoleThemeStyle, string>
128107
{
129108
[ConsoleThemeStyle.Text] = Reset,
130109
[ConsoleThemeStyle.SecondaryText] = Reset,
131110
[ConsoleThemeStyle.TertiaryText] = Reset,
132-
[ConsoleThemeStyle.Invalid] = BrightYellow,
133-
[ConsoleThemeStyle.Null] = Cyan,
134-
[ConsoleThemeStyle.Name] = Cyan,
135-
[ConsoleThemeStyle.String] = Yellow,
136-
[ConsoleThemeStyle.Number] = BrightYellow,
137-
[ConsoleThemeStyle.Boolean] = Cyan,
111+
[ConsoleThemeStyle.Invalid] = Yellow,
112+
[ConsoleThemeStyle.Null] = Blue,
113+
[ConsoleThemeStyle.Name] = Reset,
114+
[ConsoleThemeStyle.String] = Cyan,
115+
[ConsoleThemeStyle.Number] = Magenta,
116+
[ConsoleThemeStyle.Boolean] = Blue,
138117
[ConsoleThemeStyle.Scalar] = Green,
139118
[ConsoleThemeStyle.LevelVerbose] = Reset,
140-
[ConsoleThemeStyle.LevelDebug] = Reset,
141-
[ConsoleThemeStyle.LevelInformation] = Bold,
119+
[ConsoleThemeStyle.LevelDebug] = Bold,
120+
[ConsoleThemeStyle.LevelInformation] = BrightCyan,
142121
[ConsoleThemeStyle.LevelWarning] = BrightYellow,
143-
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m",
144-
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m",
122+
[ConsoleThemeStyle.LevelError] = BrightRed,
123+
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m",
145124
});
146125
}
147-
}
126+
}

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleTheme.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class SystemConsoleTheme : ConsoleTheme
3939
/// A theme based on the original Serilog "colored console" sink.
4040
/// </summary>
4141
public static SystemConsoleTheme Colored { get; } = SystemConsoleThemes.Colored;
42+
43+
/// <summary>
44+
/// A theme in the style of the original <i>Serilog.Sinks.Literate</i> using only standard 16 terminal colors that will work on light backgrounds.
45+
/// </summary>
46+
public static SystemConsoleTheme Sixteen { get; } = SystemConsoleThemes.Sixteen;
4247

4348
/// <summary>
4449
/// Construct a theme given a set of styles.

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,26 @@ static class SystemConsoleThemes
8181
[ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red },
8282
[ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red },
8383
});
84+
85+
public static SystemConsoleTheme Sixteen { get; } = new SystemConsoleTheme(
86+
new Dictionary<ConsoleThemeStyle, SystemConsoleThemeStyle>
87+
{
88+
[ConsoleThemeStyle.Text] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black },
89+
[ConsoleThemeStyle.SecondaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black },
90+
[ConsoleThemeStyle.TertiaryText] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black },
91+
[ConsoleThemeStyle.Invalid] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkYellow },
92+
[ConsoleThemeStyle.Null] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue },
93+
[ConsoleThemeStyle.Name] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black },
94+
[ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkCyan },
95+
[ConsoleThemeStyle.Number] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Magenta },
96+
[ConsoleThemeStyle.Boolean] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue },
97+
[ConsoleThemeStyle.Scalar] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Green },
98+
[ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black },
99+
[ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Black },
100+
[ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Cyan },
101+
[ConsoleThemeStyle.LevelWarning] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Yellow },
102+
[ConsoleThemeStyle.LevelError] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Red, },
103+
[ConsoleThemeStyle.LevelFatal] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White, Background = ConsoleColor.Red },
104+
});
84105
}
85106
}

0 commit comments

Comments
 (0)