Bug 38299: Make filehandler optional for colored outputs

Allow say_success, say_failure, etc, to omit the filehandler parameter
so that they can be used without explicitly opening a filehandler if you
are just printing to STDOUT and don't already have one.

If a filehandler is passed, the existing behavior is unchanged.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Emily Lamancusa 2024-11-07 10:21:19 -05:00 committed by Katrin Fischer
parent 0be29ed976
commit bae04ca3fd
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 24 additions and 4 deletions

View File

@ -71,22 +71,42 @@ Output an informational message in blue.
sub say_warning {
my ( $fh, $msg ) = @_;
say $fh YELLOW, "$msg", RESET;
if ($fh) {
say $fh YELLOW, "$msg", RESET;
} else {
say YELLOW, "$msg", RESET;
}
}
sub say_failure {
my ( $fh, $msg ) = @_;
say $fh RED, "$msg", RESET;
if ($fh) {
say $fh RED, "$msg", RESET;
} else {
say RED, "$msg", RESET;
}
}
sub say_success {
my ( $fh, $msg ) = @_;
say $fh GREEN, "$msg", RESET;
if ($fh) {
say $fh GREEN, "$msg", RESET;
} else {
say GREEN, "$msg", RESET;
}
}
sub say_info {
my ( $fh, $msg ) = @_;
say $fh BLUE, "$msg", RESET;
if ($fh) {
say $fh BLUE, "$msg", RESET;
} else {
say BLUE, "$msg", RESET;
}
}
=head1 AUTHORS