From 7afea478b77b209172347e35f861cff215e03575 Mon Sep 17 00:00:00 2001 From: Emily Lamancusa Date: Thu, 7 Nov 2024 10:21:19 -0500 Subject: [PATCH] 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 Signed-off-by: Jonathan Druart --- Koha/Installer/Output.pm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Koha/Installer/Output.pm b/Koha/Installer/Output.pm index 6cb3d6a78d8..41cd5b52412 100644 --- a/Koha/Installer/Output.pm +++ b/Koha/Installer/Output.pm @@ -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 -- 2.34.1