summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaat <maat-pub@mageia.biz>2021-03-28 22:59:51 +0200
committerMaat <maat-pub@mageia.biz>2021-03-28 22:59:51 +0200
commit7fab2353b8298492594ae672a3aadff89428cac2 (patch)
tree50d553a34a5a9f76d69c62f6c00d2cdcbf170fcd
parent084744de672cb2af32d3b1b7409dfd746dab022b (diff)
downloadurpmi-7fab2353b8298492594ae672a3aadff89428cac2.tar
urpmi-7fab2353b8298492594ae672a3aadff89428cac2.tar.gz
urpmi-7fab2353b8298492594ae672a3aadff89428cac2.tar.bz2
urpmi-7fab2353b8298492594ae672a3aadff89428cac2.tar.xz
urpmi-7fab2353b8298492594ae672a3aadff89428cac2.zip
Setting up H() function for cleaner color control
-rw-r--r--urpm/msg.pm21
-rwxr-xr-xurpmi169
2 files changed, 103 insertions, 87 deletions
diff --git a/urpm/msg.pm b/urpm/msg.pm
index a79e59b8..ca81d9fe 100644
--- a/urpm/msg.pm
+++ b/urpm/msg.pm
@@ -1,4 +1,5 @@
package urpm::msg;
+# vim:et:ai:ts=4:sts=4:sw=4
use strict;
@@ -6,6 +7,7 @@ no warnings;
use Exporter;
use URPM;
use urpm::util 'append_to_file';
+use Term::ANSIColor;
my $encoding;
BEGIN {
@@ -14,7 +16,7 @@ BEGIN {
}
our @ISA = 'Exporter';
-our @EXPORT = qw(N N_ P translate bug_log message_input toMb formatXiB sys_log);
+our @EXPORT = qw(H N N_ P translate bug_log message_input toMb formatXiB sys_log);
#- I18N.
use Locale::gettext;
@@ -65,6 +67,23 @@ sub P {
sprintf(translate($s_singular, $s_plural, $nb), @para);
}
+sub H {
+ my ($label, $istring) = @_;
+ my $color = '';
+ my %colors = (
+ "Alert" => 'red',
+ "Error" => 'red',
+ "Warning" => 'bright_yellow',
+ "Arg" => 'cyan',
+ "Package" => 'bold white',
+ "Highlight" => 'bright_yellow',
+ "Progress" => 'blue',
+ "Success" => 'bright_green'
+ );
+ my $output = color($colors{$label}) . $istring . color('reset');
+ return $output;
+}
+
sub N {
my ($format, @params) = @_;
sprintf(translate($format), @params);
diff --git a/urpmi b/urpmi
index b49e64f0..4ea3fa3a 100755
--- a/urpmi
+++ b/urpmi
@@ -64,98 +64,95 @@ $ENV{HOME} ||= "/root";
$ENV{USER} ||= "root";
sub usage () {
- print color('bright_yellow');
- print urpm::args::copyright('urpmi', [ '1999-2010', 'Mandriva' ], [ '2011-2021', 'Mageia' ]);
+ print H('Highlight',urpm::args::copyright('urpmi', [ '1999-2010', 'Mandriva' ], [ '2011-2021', 'Mageia' ]));
print "
-" . color('bold cyan') . " --help" . color('reset') . " - " . N("print this help message.") ."
-" . color('bold cyan') . " --media" . color('reset') . " - " . N("use only the given media, separated by comma.") ."
-" . color('bold cyan') . " --excludemedia" . color('reset') . " - " . N("do not use the given media, separated by comma.") ."
-" . color('bold cyan') . " --update" . color('reset') . " - " . N("use only update media.") ."
-" . color('bold cyan') . " --searchmedia" . color('reset') . " - " . N("use only the given media to search requested packages.") ."
-" . color('bold cyan') . " --sortmedia" . color('reset') . " - " . N("sort media according to substrings separated by comma.") ."
-" . color('bold cyan') . " --synthesis" . color('reset') . " - " . N("use the given synthesis instead of urpmi db.") ."
-" . color('bold cyan') . " --auto" . color('reset') . " - " . N("non-interactive mode, assume default answers to questions.") ."
-" . color('bold cyan') . " --auto-select" . color('reset') . " - " . N("automatically select packages to upgrade the system.") ."
-" . color('bold cyan') . " --auto-update" . color('reset') . " - " . N("update media then upgrade the system.") ."
-" . color('bold cyan') . " --no-md5sum" . color('reset') . " - " . N("disable MD5SUM file checking.") ."
-" . color('bold cyan') . " --force-key" . color('reset') . " - " . N("force update of gpg key.") ."
-" . color('bold cyan') . " --auto-orphans" . color('reset') . " - " . N("remove orphans without asking") ."
-" . color('bold cyan') . " --no-recommends" . color('reset') . " - " . N("do not auto select \"recommended\" packages.") ."
-" . color('bold cyan') . " --no-uninstall" . color('reset') . " - " . N("never ask to uninstall a package, abort the installation.") ."
-" . color('bold cyan') . " --no-install" . color('reset') . " - " . N("don't install packages (only download)") ."
-" . color('bold cyan') . " --keep" . color('reset') . " - " . N("keep existing packages if possible, reject requested
+" . H("Arg", " --help") . " - " . N("print this help message.") ."
+" . H('Arg', " --media") . " - " . N("use only the given media, separated by comma.") ."
+" . H('Arg', " --excludemedia") . " - " . N("do not use the given media, separated by comma.") ."
+" . H('Arg', " --update") . " - " . N("use only update media.") ."
+" . H('Arg', " --searchmedia") . " - " . N("use only the given media to search requested packages.") ."
+" . H('Arg', " --sortmedia") . " - " . N("sort media according to substrings separated by comma.") ."
+" . H('Arg', " --synthesis") . " - " . N("use the given synthesis instead of urpmi db.") ."
+" . H('Arg', " --auto") . " - " . N("non-interactive mode, assume default answers to questions.") ."
+" . H('Arg', " --auto-select") . " - " . N("automatically select packages to upgrade the system.") ."
+" . H('Arg', " --auto-update") . " - " . N("update media then upgrade the system.") ."
+" . H('Arg', " --no-md5sum") . " - " . N("disable MD5SUM file checking.") ."
+" . H('Arg', " --force-key") . " - " . N("force update of gpg key.") ."
+" . H('Arg', " --auto-orphans") . " - " . N("remove orphans without asking") ."
+" . H('Arg', " --no-recommends") . " - " . N("do not auto select \"recommended\" packages.") ."
+" . H('Arg', " --no-uninstall") . " - " . N("never ask to uninstall a package, abort the installation.") ."
+" . H('Arg', " --no-install") . " - " . N("don't install packages (only download)") ."
+" . H('Arg', " --keep") . " - " . N("keep existing packages if possible, reject requested
packages that lead to removals.") ."
-" . color('bold cyan') . " --split-level" . color('reset') . " - " . N("split in small transaction if more than given packages
+" . H('Arg', " --split-level") . " - " . N("split in small transaction if more than given packages
are going to be installed or upgraded,
default is %d."
, urpm::default_options()->{'split-level'}) . "
-" . color('bold cyan') . " --split-length" . color('reset') . " - " . N("small transaction length, default is %d."
+" . H('Arg', " --split-length") . " - " . N("small transaction length, default is %d."
, urpm::default_options()->{'split-length'}) . "
-" . color('bold cyan') . " --fuzzy, -y" . color('reset') . " - " . N("impose fuzzy search.") . "
-" . color('bold cyan') . " --buildrequires" . color('reset') . " - " . N("install the buildrequires of the packages.") . "
-" . color('bold cyan') . " --install-src" . color('reset') . " - " . N("install only source package (no binaries).") . "
-" . color('bold cyan') . " --clean" . color('reset') . " - " . N("remove rpm from cache before anything else.") . "
-" . color('bold cyan') . " --noclean" . color('reset') . " - " . N("don't clean rpms from cache.") . "
-" . color('bold cyan') . " --justdb" . color('reset') . " - " . N("update only the rpm db, not the filesystem.") . "
-" . color('bold cyan') . " --downgrade" . color('reset') . " - " . N("downgrade a package from the version currently installed
+" . H('Arg', " --fuzzy, -y") . " - " . N("impose fuzzy search.") . "
+" . H('Arg', " --buildrequires") . " - " . N("install the buildrequires of the packages.") . "
+" . H('Arg', " --install-src") . " - " . N("install only source package (no binaries).") . "
+" . H('Arg', " --clean") . " - " . N("remove rpm from cache before anything else.") . "
+" . H('Arg', " --noclean") . " - " . N("don't clean rpms from cache.") . "
+" . H('Arg', " --justdb") . " - " . N("update only the rpm db, not the filesystem.") . "
+" . H('Arg', " --downgrade") . " - " . N("downgrade a package from the version currently installed
to the previously highest version") . "
-" . color('bold cyan') . " --replacepkgs" . color('reset') . " - " . N("force installing packages which are already installed.") . "
-" . color('bold cyan') . " --force" . color('reset') . " - " . N("force invocation even if some packages do not exist.") . "
-" . color('bold cyan') . " --allow-nodeps" . color('reset') . " - " . N("allow asking user to install packages without
+" . H('Arg', " --replacepkgs") . " - " . N("force installing packages which are already installed.") . "
+" . H('Arg', " --force") . " - " . N("force invocation even if some packages do not exist.") . "
+" . H('Arg', " --allow-nodeps") . " - " . N("allow asking user to install packages without
dependencies checking.") . "
-" . color('bold cyan') . " --allow-force" . color('reset') . " - " . N("allow asking user to install packages without
+" . H('Arg', " --allow-force") . " - " . N("allow asking user to install packages without
dependencies checking and integrity.") . "
-" . color('bold cyan') . " --allow-recommends" . color('reset') . " - " . N("auto select \"recommended\" packages.") . "
-" . color('bold cyan') . " --parallel" . color('reset') . " - " . N("distributed urpmi across machines of alias.") . "
-" . color('bold cyan') . " --root" . color('reset') . " - " . N("use another root for rpm installation.") . "
-" . color('bold cyan') . " --urpmi-root" . color('reset') . " - " . N("use another root for urpmi db & rpm installation.") . "
-" . color('bold cyan') . " --use-distrib" . color('reset') . " - " . N("configure urpmi on the fly from a distrib tree, useful
+" . H('Arg', " --allow-recommends") . " - " . N("auto select \"recommended\" packages.") . "
+" . H('Arg', " --parallel") . " - " . N("distributed urpmi across machines of alias.") . "
+" . H('Arg', " --root") . " - " . N("use another root for rpm installation.") . "
+" . H('Arg', " --urpmi-root") . " - " . N("use another root for urpmi db & rpm installation.") . "
+" . H('Arg', " --use-distrib") . " - " . N("configure urpmi on the fly from a distrib tree, useful
to install a chroot with --root option.") . "
-" . color('bold cyan') . " --metalink" . color('reset') . " - " . N("generate and use a local metalink.") . "
-" . color('bold cyan') . " --download-all" . color('reset') . " - " . N("download all needed packages before trying to install them") . "
-" . color('bold cyan') . " --downloader" . color('reset') . " - " . N("program to use to retrieve distant files.
+" . H('Arg', " --metalink") . " - " . N("generate and use a local metalink.") . "
+" . H('Arg', " --download-all") . " - " . N("download all needed packages before trying to install them") . "
+" . H('Arg', " --downloader") . " - " . N("program to use to retrieve distant files.
known programs: %s", join(', ', urpm::download::ftp_http_downloaders())) . "
-" . color('bold cyan') . " --curl-options" . color('reset') . " - " . N("additional options to pass to curl.") . "
-" . color('bold cyan') . " --rsync-options" . color('reset') . " - " . N("additional options to pass to rsynci.") . "
-" . color('bold cyan') . " --wget-options" . color('reset') . " - " . N("additional options to pass to wget.") . "
-" . color("bold cyan") . " --prozilla-options" . color('reset') . " - " . N("additional options to pass to prozilla.") . "
-" . color("bold cyan") . " --aria2-options" . color('reset') . " - " . N("additional options to pass to aria2.") . "
-" . color("bold cyan") . " --limit-rate" . color('reset') . " - " . N("limit the download speed.") . "
-" . color("bold cyan") . " --resume" . color('reset') . " - " . N("resume transfer of partially-downloaded files.
+" . H('Arg', " --curl-options") . " - " . N("additional options to pass to curl.") . "
+" . H('Arg', " --rsync-options") . " - " . N("additional options to pass to rsynci.") . "
+" . H('Arg', " --wget-options") . " - " . N("additional options to pass to wget.") . "
+" . H('Arg', " --prozilla-options") . " - " . N("additional options to pass to prozilla.") . "
+" . H('Arg', " --aria2-options") . " - " . N("additional options to pass to aria2.") . "
+" . H('Arg', " --limit-rate") . " - " . N("limit the download speed.") . "
+" . H('Arg', " --resume") . " - " . N("resume transfer of partially-downloaded files.
(--no-resume disables it, default is disabled).") . "
-" . color("bold cyan") . " --proxy" . color('reset') . " - " . N("use specified HTTP proxy, the port number is assumed
+" . H('Arg', " --proxy") . " - " . N("use specified HTTP proxy, the port number is assumed
to be 1080 by default (format is <proxyhost[:port]>).") . "
-" . color("bold cyan") . " --proxy-user" . color('reset') . " - " . N("specify user and password to use for proxy
+" . H('Arg', " --proxy-user") . " - " . N("specify user and password to use for proxy
authentication (format is <user:password>).") . "
-" . color("bold cyan") . " --bug" . color('reset') . " - " . N("output a bug report in directory indicated by
+" . H('Arg', " --bug") . " - " . N("output a bug report in directory indicated by
next arg.") . "
-" . color("bold cyan") . " --env" . color('reset') . " - " . N("use specific environment (typically a bug report).") . "
-" . color("bold cyan") . " --verify-rpm" . color('reset') . " - " . N("verify rpm signature before installation
+" . H('Arg', " --env") . " - " . N("use specific environment (typically a bug report).") . "
+" . H('Arg', " --verify-rpm") . " - " . N("verify rpm signature before installation
(--no-verify-rpm disables it, default is enabled).") . "
-" . color("bold cyan") . " --test" . color('reset') . " - " . N("only verify if the installation can be achieved correctly.") . "
-" . color("bold cyan") . " --excludepath" . color('reset') . " - " . N("exclude path separated by comma.") . "
-" . color("bold cyan") . " --excludedocs" . color('reset') . " - " . N("exclude doc files.") . "
-" . color("bold cyan") . " --ignoresize" . color('reset') . " - " . N("don't verify disk space before installation.") . "
-" . color("bold cyan") . " --ignorearch" . color('reset') . " - " . N("allow to install rpms for unmatched architectures.") . "
-" . color("bold cyan") . " --noscripts" . color('reset') . " - " . N("do not execute package scriptlet(s).") . "
-" . color("bold cyan") . " --replacefiles" . color('reset') . " - " . N("ignore file conflicts.") . "
-" . color("bold cyan") . " --skip" . color('reset') . " - " . N("packages which installation should be skipped.") . "
-" . color("bold cyan") . " --prefer" . color('reset') . " - " . N("packages which should be preferred.") . "
-" . color("bold cyan") . " --more-choices" . color('reset') . " - " . N("when several packages are found, propose more choices
+" . H('Arg', " --test") . " - " . N("only verify if the installation can be achieved correctly.") . "
+" . H('Arg', " --excludepath") . " - " . N("exclude path separated by comma.") . "
+" . H('Arg', " --excludedocs") . " - " . N("exclude doc files.") . "
+" . H('Arg', " --ignoresize") . " - " . N("don't verify disk space before installation.") . "
+" . H('Arg', " --ignorearch") . " - " . N("allow to install rpms for unmatched architectures.") . "
+" . H('Arg', " --noscripts") . " - " . N("do not execute package scriptlet(s).") . "
+" . H('Arg', " --replacefiles") . " - " . N("ignore file conflicts.") . "
+" . H('Arg', " --skip") . " - " . N("packages which installation should be skipped.") . "
+" . H('Arg', " --prefer") . " - " . N("packages which should be preferred.") . "
+" . H('Arg', " --more-choices") . " - " . N("when several packages are found, propose more choices
than the default.") . "
-" . color("bold cyan") . " --nolock" . color('reset') . " - " . N("don't lock rpm db.") . "
-" . color("bold cyan") . " --strict-arch" . color('reset') . " - " . N("upgrade only packages with the same architecture.") . "
-" . color("bold cyan") . " -a" . color('reset') . " - " . N("select all matches on command line.") . "
-" . color("bold cyan") . " -p" . color('reset') . " - " . N("allow search in provides to find package.") . "
-" . color("bold cyan") . " -P" . color('reset') . " - " . N("do not search in provides to find package.") . "
-" . color("bold cyan") . " --quiet, -q" . color('reset') . " - " . N("quiet mode.") . "
-" . color("bold cyan") . " --verbose, -v" . color('reset') . " - " . N("verbose mode.") . "
-" . color("bold cyan") . " --debug" . color('reset') . " - " . N("very verbose mode.") . "
+" . H('Arg', " --nolock") . " - " . N("don't lock rpm db.") . "
+" . H('Arg', " --strict-arch") . " - " . N("upgrade only packages with the same architecture.") . "
+" . H('Arg', " -a") . " - " . N("select all matches on command line.") . "
+" . H('Arg', " -p") . " - " . N("allow search in provides to find package.") . "
+" . H('Arg', " -P") . " - " . N("do not search in provides to find package.") . "
+" . H('Arg', " --quiet, -q") . " - " . N("quiet mode.") . "
+" . H('Arg', " --verbose, -v") . " - " . N("verbose mode.") . "
+" . H('Arg', " --debug") . " - " . N("very verbose mode.") . "
" . "\n";
- print color('bright_yellow');
- print N(" names or rpm files given on command line will be installed.
-");
- print color('reset');
+ print H('Highlight', N(" names or rpm files given on command line will be installed.
+"));
exit(1);
}
@@ -182,15 +179,15 @@ if (member('--restricted', @ARGV)) {
my $urpm = urpm->new_parse_cmdline or exit(1);
if (@ARGV && $auto_select) {
- print STDERR color('red') . N("Error: can't use --auto-select along with package list.\n") . color('reset');
+ print STDERR H('Error', N("Error: can't use --auto-select along with package list.\n"));
exit 1;
}
# Verify that arguments were given
unless (@ARGV || $auto_select || $clean) {
if ($options{bug}) {
- print STDERR color('red') . N("Error: To generate a bug report, specify the usual command-line arguments
-along with --bug.\n") . color('reset');;
+ print STDERR H('Error',N("Error: To generate a bug report, specify the usual command-line arguments
+along with --bug.\n"));
exit 1;
}
usage();
@@ -268,7 +265,7 @@ if ($env) {
} else {
if ($< != 0 && !$options{debug__do_not_install}) {
#- need to be root if binary rpms are to be installed
- $auto_select || @names || @files and $urpm->{fatal}(1, N("Only superuser is allowed to install packages"));
+ $auto_select || @names || @files and $urpm->{fatal}(1, H('Error',N("Only superuser is allowed to install packages")));
}
}
@@ -442,10 +439,10 @@ sub ask_choice {
my $n = 1; #- default value.
if (@l > 1 && !$urpm->{options}{auto}) {
- print color('bright_yellow') . N("In order to satisfy the '%s' dependency, one of the following packages is needed:", $virtual_pkg_name) . color('reset'), "\n";
+ print H("Highlight",N("In order to satisfy the '%s' dependency, one of the following packages is needed:", $virtual_pkg_name))."\n";
my $i = 0;
foreach (@l) { print " " . ++$i . "- $_\n" }
- $n = message_input(N("What is your choice? (1-%d) ", $i), default => $prefer, range_min => 0, range => $i);
+ $n = message_input(H('Choice',N("What is your choice? (1-%d) ", $i)), default => $prefer, range_min => 0, range => $i);
defined($n) && $n ne "0" or exit 1; # abort.
if ($n =~ /\D/) {
my @nn = map { $choices[$_ - 1] } grep { !/\D/ } split /[, \t]+/, $n;
@@ -480,7 +477,7 @@ if ($options{replacepkgs}) {
{
my $msg = urpm::select::translate_already_installed($state);
- $msg and print "$msg\n";
+ $msg and print H('Warning',"$msg\n");
}
my @unselected_uninstalled = @{$state->{unselected_uninstalled} || []};
@@ -510,7 +507,7 @@ if (@ask_unselect) {
N("A requested package cannot be installed:\n%s", $list)
: N("Some requested packages cannot be installed:\n%s", $list);
if ($urpm->{options}{auto}) {
- print "$msg\n";
+ print H('Warning',"$msg\n");
} else {
my $noexpr = N("Nn");
$msg .= N("\nContinue installation anyway?");
@@ -540,7 +537,7 @@ if (my @conflicting_pkgs_msgs =
has to be removed for others to be upgraded:\n%s\n", $list)
: N("The installation cannot continue because the following packages
have to be removed for others to be upgraded:\n%s\n", $list);
- print "$msg\n";
+ print H('Error',"$msg\n");
exit 17;
}
@@ -549,7 +546,7 @@ have to be removed for others to be upgraded:\n%s\n", $list);
$msg = "$msg\n" . N("(test only, removal will not be actually done)");
}
if ($urpm->{options}{auto}) {
- print "$msg\n";
+ print H('Highlight',"$msg\n");
} else {
$force || urpm::msg::ask_yes_or_no($msg) or exit 17;
}
@@ -601,7 +598,7 @@ $urpm->{nb_install} = @to_install;
sub warn_msg {
my ($msg) = @_;
- $urpm->{print}(color('red') . N("WARNING: %s option is in use. Some strange problems may happen", $msg) . color('reset'));
+ $urpm->{print}(H('Highlight',N("WARNING: %s option is in use. Some strange problems may happen", $msg)));
}
warn_msg("--allow-force") if $urpm->{options}{'allow-force'};
@@ -696,7 +693,7 @@ $exit_code ||= $urpm::postponed_code;
#- restart urpmi if needed, keep command line for that.
if ($restart_itself && !$exit_code) {
- print color('bright_yellow') . N("restarting urpmi"), "\n" . color('reset');
+ print H('Highlight',N("restarting urpmi"))."\n";
#- it seems to work correctly with exec instead of system, provided
#- STDOUT or STDERR are not closed before (else no output at all).
#- added --previous-priority-upgrade to allow checking if yet if