From 62cc519f083a6fa49a6f2771b25485b3661bfd12 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. --- Koha/Installer/Output.pm | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Koha/Installer/Output.pm b/Koha/Installer/Output.pm index 6cb3d6a78d..2c1a6b31d3 100644 --- a/Koha/Installer/Output.pm +++ b/Koha/Installer/Output.pm @@ -71,22 +71,46 @@ 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