Coloured Error Messages with Rakudo (and without Windows)
Rakudo can display coloured error messages (controlled by %*ENV<RAKUDO_ERROR_COLOR>
). If you want to be as cool as Rakudo, here is how it’s done.
class X::Parameter::ExtraNamed is Exception { has $.extra-parameters; has $.classname; has $.method-name; method message () { state ($r, $c, $g); once { ($r, $c, $g) = '','',''; try { ($r, $c, $g ) = Rakudo::Internals.error-rcgye; } # red, clear, green, yelow, eject } "The method $g$.method-name$c of $g$.classname$c received " ~ "an invalid named parameter(s): $r$.extra-parameters$c"; } }
The default is not to show any control chars. Since you may not be on Rakudo or those internals change in the future, sticking the real control chars into state variables is done in a try block.
Categories: Perl6
Comments (0)
Trackbacks (1)
Leave a comment
Trackback
-
January 25, 2016 at 16:082016.1,2,3 What Are We Waiting 4? | Weekly changes in and around Perl 6