@@ -34,18 +34,25 @@ class OutputFormatFeature : CommandFeature
3434 public const string DefaultOutputTemplate =
3535 "[{Timestamp:o} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}" ;
3636
37- public static readonly ConsoleTheme DefaultTheme = SystemConsoleTheme . Literate ;
37+ public static readonly ConsoleTheme DefaultTheme = SystemConsoleTheme . Literate ;
38+ public static readonly ConsoleTheme DefaultAnsiTheme = AnsiConsoleTheme . Code ;
3839
39- bool _json , _noColor ;
40+ bool _json , _noColor , _forceColor ;
4041
4142 public OutputFormatFeature ( SeqCliOutputConfig outputConfig )
4243 {
4344 _noColor = outputConfig . DisableColor ;
45+ _forceColor = outputConfig . ForceColor ;
4446 }
4547
4648 public bool Json => _json ;
4749
48- ConsoleTheme Theme => _noColor ? ConsoleTheme . None : DefaultTheme ;
50+ bool ApplyThemeToRedirectedOutput => _noColor == false && _forceColor == true ;
51+
52+ ConsoleTheme Theme
53+ => _noColor ? ConsoleTheme . None
54+ : ApplyThemeToRedirectedOutput ? DefaultAnsiTheme
55+ : DefaultTheme ;
4956
5057 public override void Enable ( OptionSet options )
5158 {
@@ -55,6 +62,10 @@ public override void Enable(OptionSet options)
5562 v => _json = true ) ;
5663
5764 options . Add ( "no-color" , "Don't colorize text output" , v => _noColor = true ) ;
65+
66+ options . Add ( "force-color" ,
67+ "Force redirected output to have ANSI color (unless `--no-color` is also specified)" ,
68+ v => _forceColor = true ) ;
5869 }
5970
6071 public Logger CreateOutputLogger ( )
@@ -72,7 +83,8 @@ public Logger CreateOutputLogger()
7283 outputConfiguration . Enrich . With < SurrogateLevelRemovalEnricher > ( ) ;
7384 outputConfiguration . WriteTo . Console (
7485 outputTemplate : DefaultOutputTemplate ,
75- theme : Theme ) ;
86+ theme : Theme ,
87+ applyThemeToRedirectedOutput : ApplyThemeToRedirectedOutput ) ;
7688 }
7789
7890 return outputConfiguration . CreateLogger ( ) ;
@@ -115,7 +127,8 @@ public void WriteEntity(Entity entity)
115127 . Enrich . With < StripStructureTypeEnricher > ( )
116128 . WriteTo . Console (
117129 outputTemplate : "{@Message:j}{NewLine}" ,
118- theme : Theme )
130+ theme : Theme ,
131+ applyThemeToRedirectedOutput : ApplyThemeToRedirectedOutput )
119132 . CreateLogger ( ) ;
120133 writer . Information ( "{@Entity}" , jo ) ;
121134 }
0 commit comments