-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
STDMux.pm6
26 lines (24 loc) · 1006 Bytes
/
STDMux.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
unit module Zef::CLI::STDMux;
# redirect all sub-processes stdout/stderr to current stdout with the format:
# `file-name.t \s* # <output>` such that we can just print everything as it comes
# and still make a little sense of it (and allow it to be sorted)
# todo: handle line wrapping with seperator
sub procs2stdout(*@processes) is export {
return unless @processes;
my @basenames = @processes>>.id>>.IO>>.basename;
my $longest-basename = @basenames.reduce({ $^a.chars > $^b.chars ?? $^a !! $^b });
for @processes -> $proc {
for $proc.stdout, $proc.stderr -> $stdio {
$stdio.tap: -> $out {
for $out.lines.grep(*.so) -> $line {
state $to-print ~= sprintf(
"%-{$longest-basename.chars + 1}s# %s\n",
$proc.id.IO.basename,
$line
);
LAST { print $to-print if $to-print }
}
}
}
}
}