@@ -64,7 +64,7 @@ public static string StripControlSequences(string text)
6464 return outputBuilder ? . ToString ( ) ?? text ;
6565 }
6666
67- public static ConversionResult ConvertToHtml ( string ? text , ParserState ? priorResidualState = null )
67+ public static ConversionResult ConvertToHtml ( string ? text , ParserState ? priorResidualState = null , ConsoleColor ? defaultBackgroundColor = null )
6868 {
6969 var textStartIndex = - 1 ;
7070 var textLength = 0 ;
@@ -147,7 +147,7 @@ public static ConversionResult ConvertToHtml(string? text, ParserState? priorRes
147147 // Ignore everything else and don't write sequence to the output.
148148 if ( finalByte == DisplayAttributesFinalByte )
149149 {
150- ProcessParameters ( ref newState , parameters ) ;
150+ ProcessParameters ( defaultBackgroundColor , ref newState , parameters ) ;
151151 }
152152
153153 continue ;
@@ -197,7 +197,7 @@ public static ConversionResult ConvertToHtml(string? text, ParserState? priorRes
197197 return new ( outputBuilder . ToString ( ) , currentState ) ;
198198 }
199199
200- private static void ProcessParameters ( ref ParserState newState , int [ ] parameters )
200+ private static void ProcessParameters ( ConsoleColor ? defaultBackgroundColor , ref ParserState newState , int [ ] parameters )
201201 {
202202 for ( var i = 0 ; i < parameters . Length ; i ++ )
203203 {
@@ -228,7 +228,9 @@ private static void ProcessParameters(ref ParserState newState, int[] parameters
228228 }
229229 else if ( TryGetBackgroundColor ( parameter , out color ) )
230230 {
231- newState . BackgroundColor = color ;
231+ // Don't set the background color if it matches the default background color.
232+ // Skipping setting it improves appearance when row mouseover slightly changes color.
233+ newState . BackgroundColor = ( color != defaultBackgroundColor ) ? color : null ;
232234 }
233235 else if ( parameter == DefaultBackgroundCode )
234236 {
@@ -516,14 +518,14 @@ private static string ProcessStateChange(ParserState currentState, ParserState n
516518 {
517519 return state . ForegroundColor switch
518520 {
519- ConsoleColor . Black => state . Bright ? "ansi-fg-brightblack" : "ansi-fg-black" ,
520- ConsoleColor . Blue => state . Bright ? "ansi-fg-brightblue" : "ansi-fg-blue" ,
521- ConsoleColor . Cyan => state . Bright ? "ansi-fg-brightcyan" : "ansi-fg-cyan" ,
522- ConsoleColor . Green => state . Bright ? "ansi-fg-brightgreen" : "ansi-fg-green" ,
521+ ConsoleColor . Black => state . Bright ? "ansi-fg-brightblack" : "ansi-fg-black" ,
522+ ConsoleColor . Blue => state . Bright ? "ansi-fg-brightblue" : "ansi-fg-blue" ,
523+ ConsoleColor . Cyan => state . Bright ? "ansi-fg-brightcyan" : "ansi-fg-cyan" ,
524+ ConsoleColor . Green => state . Bright ? "ansi-fg-brightgreen" : "ansi-fg-green" ,
523525 ConsoleColor . Magenta => state . Bright ? "ansi-fg-brightmagenta" : "ansi-fg-magenta" ,
524- ConsoleColor . Red => state . Bright ? "ansi-fg-brightred" : "ansi-fg-red" ,
525- ConsoleColor . White => state . Bright ? "ansi-fg-brightwhite" : "ansi-fg-white" ,
526- ConsoleColor . Yellow => state . Bright ? "ansi-fg-brightyellow" : "ansi-fg-yellow" ,
526+ ConsoleColor . Red => state . Bright ? "ansi-fg-brightred" : "ansi-fg-red" ,
527+ ConsoleColor . White => state . Bright ? "ansi-fg-brightwhite" : "ansi-fg-white" ,
528+ ConsoleColor . Yellow => state . Bright ? "ansi-fg-brightyellow" : "ansi-fg-yellow" ,
527529 _ => ""
528530 } ;
529531 }
@@ -532,14 +534,14 @@ private static string ProcessStateChange(ParserState currentState, ParserState n
532534 {
533535 return state . BackgroundColor switch
534536 {
535- ConsoleColor . Black => "ansi-bg-black" ,
536- ConsoleColor . Blue => "ansi-bg-blue" ,
537- ConsoleColor . Cyan => "ansi-bg-cyan" ,
538- ConsoleColor . Green => "ansi-bg-green" ,
537+ ConsoleColor . Black => "ansi-bg-black" ,
538+ ConsoleColor . Blue => "ansi-bg-blue" ,
539+ ConsoleColor . Cyan => "ansi-bg-cyan" ,
540+ ConsoleColor . Green => "ansi-bg-green" ,
539541 ConsoleColor . Magenta => "ansi-bg-magenta" ,
540- ConsoleColor . Red => "ansi-bg-red" ,
541- ConsoleColor . White => "ansi-bg-white" ,
542- ConsoleColor . Yellow => "ansi-bg-yellow" ,
542+ ConsoleColor . Red => "ansi-bg-red" ,
543+ ConsoleColor . White => "ansi-bg-white" ,
544+ ConsoleColor . Yellow => "ansi-bg-yellow" ,
543545 _ => ""
544546 } ;
545547 }
0 commit comments