| 1 | package My::Role::ColoredHelp; | ||
| 2 | |||
| 3 | use Mojo::Base -role; | ||
| 4 | use Term::ANSIColor qw( colored ); | ||
| 5 | |||
| 6 | =head2 color_msg | ||
| 7 | |||
| 8 | Apply some colors to a help message. | ||
| 9 | |||
| 10 | =cut | ||
| 11 | |||
| 12 | sub color_msg { | ||
| 13 | my ( $s, $msg, $script ) = @_; | ||
| 14 | |||
| 15 | # Script. | ||
| 16 | $msg =~ s/ <SCRIPT> / colored($script,"YELLOW") /xge; | ||
| 17 | |||
| 18 | # Quotes. | ||
| 19 | $msg =~ s/ ( ' [^']*+ ' ) / colored($1,"GREEN") /xge; | ||
| 20 | |||
| 21 | # Variables. | ||
| 22 | $msg =~ s/ (\$\w+) / colored($1,"GREEN") /xge; | ||
| 23 | |||
| 24 | # Functions. | ||
| 25 | $msg =~ s/ ( \w+\(\) ) / colored($1,"GREEN") /xge; | ||
| 26 | |||
| 27 | # Options. | ||
| 28 | $msg =~ s/ (-+\w[^#]+) / colored($1,"GREEN") /xge; | ||
| 29 | |||
| 30 | # Comments. | ||
| 31 | $msg =~ s/ (\#.+) / colored($1,"ON_BRIGHT_BLACK") /xge; | ||
| 32 | |||
| 33 | # Errors. | ||
| 34 | $msg =~ s/ ^ (ERROR:.+) / colored($1,"RED") /xge; | ||
| 35 | |||
| 36 | $msg; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; |