Data-Printer icon indicating copy to clipboard operation
Data-Printer copied to clipboard

SGR attributes leak from escaped key

Open trapd00r opened this issue 4 years ago • 1 comments

Creating my own theme, I discovered that if using SGR escape sequences for the 'escaped' key in the hash returned from colors, like so:

escaped => "\e[38;5;172;1;3;4;7m",

the additional attributes (bold, italic, underline and reverse) leak over to the string.

img

I'm not sure how the color_reset / $end_color is implemented, but simply adding "\e[m" to the output seems to fix the issue and I haven't noticed any drawbacks. Surely I'm missing something though. :)

@@ -781,7 +781,7 @@ sub maybe_colorize {
         }
         if ($sgr_color) {
             $output = $sgr_color
-                . $output
+                . $output . "\e[m"
                 . (defined $end_color
                     ? $theme->sgr_color_for($end_color)
                     : $theme->color_reset

img

trapd00r avatar Dec 30 '21 12:12 trapd00r

Hi @trapd00r! Thank you for using Data::Printer and for taking the time to submit this issue. color_reset just prints "\e[0m", which should reset everything back to normal. Apparently, your terminal seems to disagree with that 😭

It seems like "\e[m" can be used as a drop-in replacement for "\e[0m" and even saves up one byte, so I'm just going to replace it on color_reset. Hopefully this will fix your issue.

garu avatar Nov 22 '22 03:11 garu