@@ -13,12 +13,15 @@ sealed class ColorState
1313 public ConsoleColor Background ;
1414 public bool BoldEnabled ;
1515 public bool ItalicEnabled ;
16+ public bool MonospaceEnabled ;
1617 }
1718
18- const ConsoleColor Bold = ConsoleColor . White ;
19- const ConsoleColor Italic = ConsoleColor . Cyan ;
20- const ConsoleColor BoldItalicFg = ConsoleColor . Gray ;
21- const ConsoleColor BoldItalicBg = ConsoleColor . DarkRed ;
19+ const ConsoleColor Normal = ConsoleColor . Gray ;
20+ const ConsoleColor NormalBold = ConsoleColor . White ;
21+ const ConsoleColor Italic = ConsoleColor . DarkCyan ;
22+ const ConsoleColor ItalicBold = ConsoleColor . Cyan ;
23+ const ConsoleColor Monospace = ConsoleColor . DarkGreen ;
24+ const ConsoleColor MonospaceBold = ConsoleColor . Green ;
2225
2326 readonly bool useColor ;
2427
@@ -27,6 +30,9 @@ sealed class ColorState
2730 public ConsolePresenter ( bool useColor )
2831 {
2932 this . useColor = useColor ;
33+ if ( useColor ) {
34+ Console . ForegroundColor = Normal ;
35+ }
3036 }
3137
3238 public override void Append ( string ? text ) => Console . Write ( text ) ;
@@ -64,34 +70,25 @@ public override void StartBold (object? state)
6470
6571 var colors = state as ColorState ;
6672 if ( colors == null ) {
67- Console . ForegroundColor = Bold ;
73+ Console . ForegroundColor = NormalBold ;
6874 return ;
6975 }
7076
7177 colors . BoldEnabled = true ;
72- if ( colors . ItalicEnabled ) {
73- Console . ForegroundColor = BoldItalicFg ;
74- Console . BackgroundColor = BoldItalicBg ;
75- } else {
76- Console . ForegroundColor = Bold ;
77- }
78+ UpdateColors ( colors ) ;
7879 }
7980
8081 public override void EndBold ( object ? state )
8182 {
8283 var colors = state as ColorState ;
8384 if ( colors == null ) {
85+ Console . ForegroundColor = Normal ;
8486 base . EndBold ( state ) ;
8587 return ;
8688 }
8789
88- if ( colors . ItalicEnabled ) {
89- Console . ForegroundColor = Italic ;
90- Console . BackgroundColor = colors . Background ;
91- } else {
92- Console . ForegroundColor = colors . Foreground ;
93- }
9490 colors . BoldEnabled = false ;
91+ UpdateColors ( colors ) ;
9592 }
9693
9794 public override void StartItalic ( object ? state )
@@ -108,29 +105,59 @@ public override void StartItalic (object? state)
108105 }
109106
110107 colors . ItalicEnabled = true ;
111- if ( colors . BoldEnabled ) {
112- Console . ForegroundColor = BoldItalicFg ;
113- Console . BackgroundColor = BoldItalicBg ;
114- } else {
115- Console . ForegroundColor = Italic ;
116- }
108+ UpdateColors ( colors ) ;
117109 }
118110
119111 public override void EndItalic ( object ? state )
120112 {
121113 var colors = state as ColorState ;
122114 if ( colors == null ) {
123- base . EndBold ( state ) ;
115+ base . EndItalic ( state ) ;
116+ return ;
117+ }
118+
119+ colors . ItalicEnabled = false ;
120+ UpdateColors ( colors ) ;
121+ }
122+
123+ public override void StartMonospace ( object ? state )
124+ {
125+ if ( ! useColor ) {
126+ base . StartMonospace ( state ) ;
124127 return ;
125128 }
126129
127- if ( colors . BoldEnabled ) {
128- Console . ForegroundColor = Bold ;
129- Console . BackgroundColor = colors . Background ;
130+ var colors = state as ColorState ;
131+ if ( colors == null ) {
132+ Console . ForegroundColor = Monospace ;
133+ return ;
134+ }
135+
136+ colors . MonospaceEnabled = true ;
137+ UpdateColors ( colors ) ;
138+ }
139+
140+ public override void EndMonospace ( object ? state )
141+ {
142+ var colors = state as ColorState ;
143+ if ( colors == null ) {
144+ base . EndMonospace ( state ) ;
145+ return ;
146+ }
147+
148+ colors . MonospaceEnabled = false ;
149+ UpdateColors ( colors ) ;
150+ }
151+
152+ void UpdateColors ( ColorState colors )
153+ {
154+ if ( colors . MonospaceEnabled ) {
155+ Console . ForegroundColor = colors . BoldEnabled ? MonospaceBold : Monospace ;
156+ } else if ( colors . ItalicEnabled ) {
157+ Console . ForegroundColor = colors . BoldEnabled ? ItalicBold : Italic ;
130158 } else {
131- Console . ForegroundColor = colors . Foreground ;
159+ Console . ForegroundColor = colors . BoldEnabled ? NormalBold : Normal ;
132160 }
133- colors . ItalicEnabled = false ;
134161 }
135162 }
136163}
0 commit comments