From 37ff77f4e8fda9b3c5f384fa7f9122e6c6bd3edb Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 5 Mar 2021 03:17:45 -0700 Subject: [PATCH] Girocco/CLIUtil.pm: provide Progress warn method While the "emit" method outputs to STDOUT, the new "warn" method outputs to STDERR and the new "emitfh" method accepts a file handle as the first argument. Signed-off-by: Kyle J. McKay --- Girocco/CLIUtil.pm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Girocco/CLIUtil.pm b/Girocco/CLIUtil.pm index da68c93..5462fdc 100644 --- a/Girocco/CLIUtil.pm +++ b/Girocco/CLIUtil.pm @@ -188,16 +188,27 @@ BEGIN {eval{ $self->{wasvis} and $self->show; } - sub emit { + sub emitfh { my $self = shift; - my $msg = shift; - defined($msg) && $msg ne "" or return; - $msg =~ /\n$/ or $msg .= "\n"; + my ($fh, $msg) = @_; + defined($msg) or return; + chomp $msg; + $msg ne "" or return; $self->clear; - printf "%s", $msg; + printf $fh "%s\n", $msg; $self->restore; } + sub emit { + my $self = shift; + $self->emitfh(\*STDOUT, @_); + } + + sub warn { + my $self = shift; + $self->emitfh(\*STDERR, @_); + } + sub DESTROY { my $self = shift; $self->clear; -- 2.11.4.GIT