summaryrefslogtreecommitdiff
path: root/make/console.pm
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2020-12-25 05:12:11 +0000
committerSadie Powell <sadie@witchery.services>2020-12-31 22:54:50 +0000
commit2b7c3967087eb231ce074b67157b6d67cc0c79eb (patch)
tree8cb246bfc5010539e46fa164e63f539593aceadc /make/console.pm
parente8f3587b80c26ee4fbd160db9a83ed8914a63e22 (diff)
Export console_format from make::console and make it more robust.
Previously a module could do warning("<|INVALID wibble|>") in its $CompilerFlags or $LinkerFLags and this would break the build.
Diffstat (limited to 'make/console.pm')
-rw-r--r--make/console.pm22
1 files changed, 13 insertions, 9 deletions
diff --git a/make/console.pm b/make/console.pm
index 98442ff77..33ce8f289 100644
--- a/make/console.pm
+++ b/make/console.pm
@@ -34,6 +34,7 @@ use File::Spec::Functions qw(rel2abs);
our @EXPORT = qw(command
execute_command
+ console_format
print_format
print_error
print_warning
@@ -59,20 +60,23 @@ struct 'command' => {
'description' => '$',
};
-sub __console_format($$) {
- my ($name, $data) = @_;
- return $data unless -t STDOUT;
- return $FORMAT_CODES{uc $name} . $data . $FORMAT_CODES{DEFAULT};
+sub console_format($) {
+ my $message = shift;
+ while ($message =~ /(<\|(\S+)\s(.*?)\|>)/) {
+ my ($match, $type, $text) = ($1, uc $2, $3);
+ if (-t STDOUT && exists $FORMAT_CODES{$type}) {
+ $message =~ s/\Q$match\E/$FORMAT_CODES{$type}$text$FORMAT_CODES{DEFAULT}/;
+ } else {
+ $message =~ s/\Q$match\E/$text/;
+ }
+ }
+ return $message;
}
sub print_format($;$) {
my $message = shift;
my $stream = shift // *STDOUT;
- while ($message =~ /(<\|(\S+)\s(.*?)\|>)/) {
- my $formatted = __console_format $2, $3;
- $message =~ s/\Q$1\E/$formatted/;
- }
- print { $stream } $message;
+ print { $stream } console_format $message;
}
sub print_error {