Home > Raku > But what about eigenstates?

But what about eigenstates?

Shell::Piping can now redirect STDERR to multiple targets. Thanks a lot to lizmat for eigenstates.

use Shell::Piping;
sub coloured-stderr(Int $index is raw, Str $s is raw) {
    my @shade = '38:5:160', '38:5:196';
    $*ERR.put: "\e[@shade[$index]m$s\e[0m";
}

px«find $*HOME» |» px |» '/dev/null'.IO :stderr(&coloured-stderr & '/tmp/pipe.log'.IO & Capture);

This will display the STDERR streams of find and sort in different shades of red, write the same to a logfile and capture STDERR to be used in X::Shell::NonZeroExitcode. I’m quite sure this can also be done in Bash with tee, using lots of parentheses and little -Ofun.

I’m using an all-Junction because it feels right. A use for an any-Junction might be a Routine that takes multiple IO::Path and takes the first found to create a config file. So my Christmas wish list now contains a single entry with a module that can tell Junction types apart.

I wanted Shell::Piping to be able to deal better with STDERR because ffmpeg is outputting both status reports and errors to STDERR. In this case Capture will contain tons of stuff that is not an error message. So I need to be able to collect only a last few lines. Adding another adverb didn’t have much appeal because Shell/Piping.raku contains 21 multi candidates for infix:<|»>. I want to Capture, but only 2 lines. Using :stderr(Capture but 2)looks cool and is easy to implement. Since Capture is not a descendant of Cool it doesn’t come with .Int, unless we mix 2 in. Then we can if-branch on my $limit = $stderr.?Int. That’s good because $stderr ~~ Int:D does not work and Metamodel::Mixins is not helpful either.

I still believe that handling junctions should be in CORE. More thought needs be spend on what junctions are and what can be done with them though. This sounds like a new year resolution. Do we have Raku new year resolutions? It would be nice to hear from the steering council where Raku is heading in 2021.

Categories: Raku
  1. No comments yet.
  1. December 14, 2020 at 20:06

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: