Data::P...::Theme(3)

πŸ’… NAME πŸ’…

okay so bestie, you're on the page for Data::P...::Theme(3) from the User Contributed Perl Documentation, and it's literally all about Data::Printer::Theme: create your own color themes for DDP! πŸ’–βœ¨


✨ SYNOPSIS ✨

here's the whole lil module skeleton β€” copy-paste it, customize it, make it yours 🫢

package Data::Printer::Theme::MyCustomTheme;

sub colors {
    return {
        array       => '#aabbcc', # array index numbers
        number      => '#aabbcc', # numbers
        string      => '#aabbcc', # strings
        class       => '#aabbcc', # class names
        method      => '#aabbcc', # method names
        undef       => '#aabbcc', # the 'undef' value
        hash        => '#aabbcc', # hash keys
        regex       => '#aabbcc', # regular expressions
        code        => '#aabbcc', # code references
        glob        => '#aabbcc', # globs (usually file handles)
        vstring     => '#aabbcc', # version strings (v5.30.1, etc)
        lvalue      => '#aabbcc', # lvalue label
        format      => '#aabbcc', # format type
        true        => '#aabbcc', # boolean type (true)
        false       => '#aabbcc', # boolean type (false)
        repeated    => '#aabbcc', # references to seen values
        caller_info => '#aabbcc', # details on what's being printed
        weak        => '#aabbcc', # weak references flag
        tainted     => '#aabbcc', # tainted flag
        unicode     => '#aabbcc', # utf8 flag
        escaped     => '#aabbcc', # escaped characters (\t, \n, etc)
        brackets    => '#aabbcc', # (), {}, []
        separator   => '#aabbcc', # the "," between hash pairs, array elements, etc
        quotes      => '#aabbcc', # q(")
        unknown     => '#aabbcc', # any (potential) data type unknown to Data::Printer
    };
}
1;

Then in your .dataprinter file:

theme = MyCustomTheme

That's it! Alternatively, you can load it at runtime:

use DDP theme => 'MyCustomTheme';

🌈 DESCRIPTION 🌈

okay so Data::Printer colorizes your output by default. Originally, the only way to customize colors was to override the default ones 😭. Then Data::Printer 1.0 introduced themes, and now you can pick a theme or create your own. main character energy, fr fr πŸ’…

Data::Printer comes with several themes for you to choose from:

  • Material (the default) β€” iconic, obviously πŸ‘‘
  • Monokai β€” a whole vibe 🌸
  • Solarized β€” yes bestie, that one β˜€οΈ
  • Classic (original pre-1.0 colors) β€” vintage era πŸŽ€

Run examples/try_me.pl to see them in action on your own terminal! πŸ’»βœ¨


🎨 CREATING YOUR THEMES 🎨

A theme is a module in the Data::Printer::Theme namespace. It doesn't have to inherit or load any module. All you have to do is implement a single function, colors, that returns a hash reference where keys are the expected color labels, and values are the colors you want to use.

Feel free to copy & paste the code from the SYNOPSIS and customize at will :) 🫢

🌈 Customizing Colors 🌈

Setting any color to undef means "Don't colorize this". Otherwise, the color is a string which can be one of the following:

πŸ’€ Named colors, Term::ANSIColor style (discouraged)

Only 8 named colors are supported:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

and their bright_XXX, on_XXX and on_bright_XXX variants.

Those are provided only as backwards compatibility with older versions of Data::Printer and, because of their limitation, we encourage you to try and use one of the other representations.

🌈 SGR Escape code (Terminal style)

You may provide any SGR escape sequence, and they will be honored as long as you use double quotes (e.g. "\e[38;5;196m"). You may use this to achieve extra control like blinking, etc. Note, however, that some terminals may not support them.

'rgb(0,255,30)'
'#00FF3B'
NOTE: There may not be a real 1:1 conversion between RGB and terminal colors. In those cases we use approximation to achieve the closest option.

πŸ‘€ SEE ALSO πŸ‘€

Data::Printer


mwah πŸ’‹ this page comes from perl v5.42.0, dated 2024-01-23, and it's literally Data::P...::Theme(3). byeee bestie, go make something iconic 🫢✨

πŸ“¦ where this page comes from