Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SGR attributes leak from escaped key #166

Open
trapd00r opened this issue Dec 30, 2021 · 1 comment
Open

SGR attributes leak from escaped key #166

trapd00r opened this issue Dec 30, 2021 · 1 comment

Comments

@trapd00r
Copy link

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

@garu
Copy link
Owner

garu commented Nov 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants