summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2017-07-15 15:21:33 +0200
committerGuillem Jover <guillem@debian.org>2017-09-24 21:03:09 +0200
commit5ea09cee634e4fe0cfac726937ccd2be81c272e8 (patch)
treedad072d56a64932f53733d79aaf5a22f153c3e0c
parent8829502bfc75a74b1539634bb3ca1f801589c0ff (diff)
downloaddpkg-5ea09cee634e4fe0cfac726937ccd2be81c272e8.tar.gz
Dpkg::ErrorHandling: Move color setup into report_pretty
Call setup_color() only if we are going to print something, so that we remove code executed at import time.
-rw-r--r--debian/changelog1
-rw-r--r--scripts/Dpkg/ErrorHandling.pm7
2 files changed, 5 insertions, 3 deletions
diff --git a/debian/changelog b/debian/changelog
index d9f7b86cd..dfc86ff29 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -32,6 +32,7 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
other modules.
- Only load Term::ANSIColor from Dpkg::ErrorHandling if we are going to
use colors, reducing the load time of many other modules.
+ - Move color setup into report_pretty in Dpkg::ErrorHandling.
* Documentation:
- Document currently accepted syntax for changelogs in deb-changelog(5).
Closes: #858579
diff --git a/scripts/Dpkg/ErrorHandling.pm b/scripts/Dpkg/ErrorHandling.pm
index b1f5ed0a2..a5b549f62 100644
--- a/scripts/Dpkg/ErrorHandling.pm
+++ b/scripts/Dpkg/ErrorHandling.pm
@@ -15,6 +15,7 @@ package Dpkg::ErrorHandling;
use strict;
use warnings;
+use feature qw(state);
our $VERSION = '0.02';
our @EXPORT_OK = qw(
@@ -52,11 +53,11 @@ use Dpkg::Gettext;
my $quiet_warnings = 0;
my $debug_level = 0;
my $info_fh = \*STDOUT;
-my $use_color = 0;
sub setup_color
{
my $mode = $ENV{'DPKG_COLORS'} // 'auto';
+ my $use_color;
if ($mode eq 'auto') {
## no critic (InputOutput::ProhibitInteractiveTest)
@@ -70,8 +71,6 @@ sub setup_color
require Term::ANSIColor if $use_color;
}
-setup_color();
-
use constant {
REPORT_PROGNAME => 1,
REPORT_COMMAND => 2,
@@ -153,6 +152,8 @@ sub report_pretty
{
my ($msg, $color) = @_;
+ state $use_color = setup_color();
+
if ($use_color) {
return Term::ANSIColor::colored($msg, $color);
} else {