summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2024-04-22 17:31:46 +0000
committerJulian Andres Klode <jak@debian.org>2024-04-22 17:31:46 +0000
commit20ab001670226e92ca8a74f1e2308197111a8420 (patch)
tree79b91f7e1543fb7a6a1585c0876a58b270448e0c
parent4e9a9dbf9bd52d38ab5818f3eb32c8189fd25671 (diff)
parent129662acca40d3bd212f19e94db6df9d0ba4ba80 (diff)
Merge branch 'ui-2.9.2' into 'main'
UI changes for 2.9.2 See merge request apt-team/apt!343
-rw-r--r--apt-pkg/contrib/error.cc21
-rw-r--r--apt-pkg/tagfile.cc32
-rw-r--r--apt-pkg/tagfile.h8
-rw-r--r--apt-private/private-install.cc27
-rw-r--r--apt-private/private-main.cc2
-rw-r--r--apt-private/private-output.cc3
-rw-r--r--apt-private/private-output.h5
-rw-r--r--apt-private/private-show.cc10
-rw-r--r--apt-private/private-update.cc6
-rw-r--r--doc/examples/configure-index3
10 files changed, 83 insertions, 34 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index 4715568d0..4eaa3dc52 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -34,6 +34,7 @@
#include <string>
#include <unistd.h>
+#include <apti18n.h>
/*}}}*/
// Global Error Object /*{{{*/
@@ -254,11 +255,13 @@ void GlobalError::MergeWithStack() {
APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i)
{
static constexpr auto COLOR_RESET = "\033[0m";
- static constexpr auto COLOR_NOTICE = "\033[33m"; // normal yellow
+ static constexpr auto COLOR_BOLD = "\033[1m"; // bold neutral
+ static constexpr auto COLOR_NOTICE = "\033[1m"; // bold neutral
static constexpr auto COLOR_WARN = "\033[1;33m"; // bold yellow
static constexpr auto COLOR_ERROR = "\033[1;31m"; // bold red
bool use_color = _config->FindB("APT::Color", false);
+ auto out_ver = _config->FindI("APT::Output-Version");
if (use_color)
{
@@ -284,22 +287,26 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i)
{
case GlobalError::FATAL:
case GlobalError::ERROR:
- out << 'E';
+ // TRANSLATOR: This is a warning level displayed before the message
+ out << (out_ver < 30 ? "E:" : _("Error:"));
break;
case GlobalError::WARNING:
- out << 'W';
+ // TRANSLATOR: This is a warning level displayed before the message
+ out << (out_ver < 30 ? "W:" : _("Warning:"));
break;
case GlobalError::NOTICE:
- out << 'N';
+ // TRANSLATOR: This is a warning level displayed before the message
+ out << (out_ver < 30 ? "N:" : _("Notice:"));
break;
case GlobalError::AUDIT:
out << 'A';
break;
case GlobalError::DEBUG:
- out << 'D';
+ // TRANSLATOR: This is a warning level displayed before the message
+ out << _("Debug:");
break;
}
- out << ": ";
+ out << " ";
if (use_color)
{
@@ -311,6 +318,8 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i)
case GlobalError::NOTICE:
case GlobalError::AUDIT:
out << COLOR_RESET;
+ if (out_ver >= 30)
+ out << COLOR_BOLD;
break;
default:
break;
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index 95ae4a483..934a89d59 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -12,6 +12,7 @@
// Include Files /*{{{*/
#include <config.h>
+#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/string_view.h>
@@ -30,8 +31,9 @@
#include <apti18n.h>
/*}}}*/
-using std::string;
using APT::StringView;
+using APT::Configuration::color;
+using std::string;
class APT_HIDDEN pkgTagFilePrivate /*{{{*/
{
@@ -972,19 +974,23 @@ pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string const &Name, std::str
else
return Tag(REWRITE, Name, Data);
}
-static bool WriteTag(FileFd &File, std::string Tag, StringView Value)
+static bool WriteTag(FileFd &File, std::string Tag, StringView Value, pkgTagSection::WriteFlags flags)
{
if (Value.empty() || isspace_ascii(Value[0]) != 0)
Tag.append(":");
else
Tag.append(": ");
+
+ if (flags & pkgTagSection::WRITE_HUMAN)
+ Tag = color("Show::Field", Tag);
+
Tag.append(Value.data(), Value.length());
Tag.append("\n");
return File.Write(Tag.c_str(), Tag.length());
}
-static bool RewriteTags(FileFd &File, pkgTagSection const * const This, char const * const Tag,
- std::vector<pkgTagSection::Tag>::const_iterator &R,
- std::vector<pkgTagSection::Tag>::const_iterator const &REnd)
+static bool RewriteTags(FileFd &File, pkgTagSection const *const This, char const *const Tag,
+ std::vector<pkgTagSection::Tag>::const_iterator &R,
+ std::vector<pkgTagSection::Tag>::const_iterator const &REnd, pkgTagSection::WriteFlags flags)
{
size_t const TagLen = strlen(Tag);
for (; R != REnd; ++R)
@@ -1002,19 +1008,23 @@ static bool RewriteTags(FileFd &File, pkgTagSection const * const This, char con
else
continue;
- return WriteTag(File, Tag, data);
+ return WriteTag(File, Tag, data, flags);
}
return true;
}
bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::vector<Tag> const &Rewrite) const
{
+ return Write(File, WRITE_DEFAULT, Order, Rewrite);
+}
+bool pkgTagSection::Write(FileFd &File, pkgTagSection::WriteFlags flags, char const *const *const Order, std::vector<Tag> const &Rewrite) const
+{
// first pass: Write everything we have an order for
if (Order != NULL)
{
for (unsigned int I = 0; Order[I] != 0; ++I)
{
std::vector<Tag>::const_iterator R = Rewrite.begin();
- if (RewriteTags(File, this, Order[I], R, Rewrite.end()) == false)
+ if (RewriteTags(File, this, Order[I], R, Rewrite.end(), flags) == false)
return false;
if (R != Rewrite.end())
continue;
@@ -1022,7 +1032,7 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v
if (Exists(Order[I]) == false)
continue;
- if (WriteTag(File, Order[I], FindRaw(Order[I])) == false)
+ if (WriteTag(File, Order[I], FindRaw(Order[I]), flags) == false)
return false;
}
}
@@ -1047,12 +1057,12 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v
std::string const name(fieldname, fieldnamelen);
std::vector<Tag>::const_iterator R = Rewrite.begin();
- if (RewriteTags(File, this, name.c_str(), R, Rewrite.end()) == false)
+ if (RewriteTags(File, this, name.c_str(), R, Rewrite.end(), flags) == false)
return false;
if (R != Rewrite.end())
continue;
- if (WriteTag(File, name, FindRaw(name)) == false)
+ if (WriteTag(File, name, FindRaw(name), flags) == false)
return false;
}
}
@@ -1076,7 +1086,7 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v
continue;
}
- if (WriteTag(File, name, ((R->Action == Tag::RENAME) ? FindRaw(R->Name) : R->Data)) == false)
+ if (WriteTag(File, name, ((R->Action == Tag::RENAME) ? FindRaw(R->Name) : R->Data), flags) == false)
return false;
}
return true;
diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h
index 0020d284b..45529c9f5 100644
--- a/apt-pkg/tagfile.h
+++ b/apt-pkg/tagfile.h
@@ -166,6 +166,14 @@ class APT_PUBLIC pkgTagSection
* @return \b true if successful, otherwise \b false
*/
bool Write(FileFd &File, char const * const * const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const;
+#ifdef APT_COMPILING_APT
+ enum WriteFlags
+ {
+ WRITE_DEFAULT = 0,
+ WRITE_HUMAN = (1 << 0), /* write human readable output, may include highlighting */
+ };
+ bool Write(FileFd &File, WriteFlags flags, char const *const *const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const;
+#endif
};
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 774c03d0a..9a2ed0b2a 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -227,11 +227,11 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo
// Show all the various warning indicators
if (_config->FindI("APT::Output-Version") < 30)
ShowDel(c1out,Cache);
+ if (_config->FindI("APT::Output-Version") >= 30 && _config->FindB("APT::Get::Show-Upgraded",true) == true)
+ ShowUpgraded(c1out,Cache);
ShowNew(c1out,Cache);
if (_config->FindI("APT::Output-Version") >= 30)
ShowWeakDependencies(Cache);
- if (_config->FindI("APT::Output-Version") >= 30 && _config->FindB("APT::Get::Show-Upgraded",true) == true)
- ShowUpgraded(c1out,Cache);
if (ShwKept == true)
{
ShowPhasing(c1out, Cache, PhasingPackages);
@@ -684,6 +684,16 @@ bool DoAutomaticRemove(CacheFile &Cache)
// if we don't remove them, we should show them!
if (doAutoRemove == false && autoRemoveCount != 0)
{
+ std::string note;
+ std::string autocmd = "apt autoremove";
+ if (getenv("SUDO_USER") != nullptr)
+ {
+ auto const envsudocmd = getenv("SUDO_COMMAND");
+ auto const envshell = getenv("SHELL");
+ if (envsudocmd == nullptr || envshell == nullptr || strcmp(envsudocmd, envshell) != 0)
+ autocmd = "sudo " + autocmd;
+ }
+ strprintf(note, P_("Use '%s' to remove it.", "Use '%s' to remove them.", autoRemoveCount), autocmd.c_str());
if (smallList == false)
{
// trigger marking now so that the package list is correct
@@ -693,21 +703,14 @@ bool DoAutomaticRemove(CacheFile &Cache)
"The following packages were automatically installed and are no longer required:",
autoRemoveCount), Universe,
[&Cache](pkgCache::PkgIterator const &Pkg) { return (*Cache)[Pkg].Garbage == true && (*Cache)[Pkg].Delete() == false; },
- &PrettyFullName, CandidateVersion(&Cache));
+ &PrettyFullName, CandidateVersion(&Cache), "", note);
}
else
+ {
ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n",
"%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount);
- std::string autocmd = "apt autoremove";
- if (getenv("SUDO_USER") != nullptr)
- {
- auto const envsudocmd = getenv("SUDO_COMMAND");
- auto const envshell = getenv("SHELL");
- if (envsudocmd == nullptr || envshell == nullptr || strcmp(envsudocmd, envshell) != 0)
- autocmd = "sudo " + autocmd;
+ c1out << note << std::endl;
}
- ioprintf(c1out, P_("Use '%s' to remove it.", "Use '%s' to remove them.", autoRemoveCount), autocmd.c_str());
- c1out << std::endl;
}
return true;
}
diff --git a/apt-private/private-main.cc b/apt-private/private-main.cc
index a80f03c99..f28f5cb80 100644
--- a/apt-private/private-main.cc
+++ b/apt-private/private-main.cc
@@ -68,6 +68,8 @@ void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/
" Keep also in mind that locking is deactivated,\n"
" so don't depend on the relevance to the real current situation!\n"),
_config->Find("Binary").c_str());
+ if (_config->FindI("APT::Output-Version") >= 30)
+ std::cout << std::endl;
_config->Set("Debug::NoLocking",true);
}
}
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc
index 35fe9cdca..09d03d340 100644
--- a/apt-private/private-output.cc
+++ b/apt-private/private-output.cc
@@ -96,6 +96,7 @@ bool InitOutput(std::basic_streambuf<char> * const out) /*{{{*/
} else {
// Colors
_config->CndSet("APT::Color::Highlight", "\x1B[32m");
+ _config->CndSet("APT::Color::Bold", "\x1B[1m");
_config->CndSet("APT::Color::Neutral", "\x1B[0m");
_config->CndSet("APT::Color::Red", "\x1B[31m");
@@ -111,6 +112,8 @@ bool InitOutput(std::basic_streambuf<char> * const out) /*{{{*/
_config->CndSet("APT::Color::Action::Install-Dependencies", "green");
_config->CndSet("APT::Color::Action::Downgrade", "yellow");
_config->CndSet("APT::Color::Action::Remove", "red");
+ _config->CndSet("APT::Color::Show::Field", "\x1B[1m");
+ _config->CndSet("APT::Color::Show::Package", "\x1B[32m");
}
return true;
diff --git a/apt-private/private-output.h b/apt-private/private-output.h
index a3e961458..0eba6f4fb 100644
--- a/apt-private/private-output.h
+++ b/apt-private/private-output.h
@@ -43,7 +43,8 @@ template<class Container, class PredicateC, class DisplayP, class DisplayV> bool
PredicateC Predicate,
DisplayP PkgDisplay,
DisplayV VerboseDisplay,
- std::string colorName = "")
+ std::string colorName = "",
+ std::string Note = "")
{
size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0;
int ScreenUsed = 0;
@@ -105,6 +106,8 @@ template<class Container, class PredicateC, class DisplayP, class DisplayV> bool
ShowWithColumns(out, PackageList, 2, ScreenWidth);
out << resetColor;
}
+ if (not Note.empty())
+ out << Note << std::endl;
if (_config->FindI("APT::Output-Version") >= 30)
out << std::endl;
return false;
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc
index cefbd9b67..4ae043071 100644
--- a/apt-private/private-show.cc
+++ b/apt-private/private-show.cc
@@ -1,6 +1,7 @@
// Includes /*{{{*/
#include <config.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/cacheset.h>
#include <apt-pkg/cmndline.h>
@@ -33,6 +34,8 @@
#include <apti18n.h>
/*}}}*/
+using APT::Configuration::color;
+
pkgRecords::Parser &LookupParser(pkgRecords &Recs, pkgCache::VerIterator const &V, pkgCache::VerFileIterator &Vf) /*{{{*/
{
Vf = V.FileList();
@@ -271,7 +274,8 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/
RW.push_back(pkgTagSection::Tag::Remove("Description"));
RW.push_back(pkgTagSection::Tag::Remove("Description-md5"));
// improve
- RW.push_back(pkgTagSection::Tag::Rewrite("Package", V.ParentPkg().FullName(true)));
+ RW.push_back(pkgTagSection::Tag::Rewrite("Package", color("Show::Package", V.ParentPkg().FullName(true))));
+
RW.push_back(pkgTagSection::Tag::Rewrite("Installed-Size", installed_size));
RW.push_back(pkgTagSection::Tag::Remove("Size"));
RW.push_back(pkgTagSection::Tag::Rewrite("Download-Size", package_size));
@@ -282,7 +286,7 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/
FileFd stdoutfd;
if (stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false) == false ||
- Tags.Write(stdoutfd, TFRewritePackageOrder, RW) == false || stdoutfd.Close() == false)
+ Tags.Write(stdoutfd, pkgTagSection::WRITE_HUMAN, TFRewritePackageOrder, RW) == false || stdoutfd.Close() == false)
return _error->Error("Internal Error, Unable to parse a package record");
// write the description
@@ -291,7 +295,7 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/
if (Desc.end() == false)
{
pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
- out << "Description: " << P.LongDesc();
+ out << color("Show::Field", "Description: ") << P.LongDesc();
}
// write a final newline (after the description)
diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc
index cc0753c26..6edde05ed 100644
--- a/apt-private/private-update.cc
+++ b/apt-private/private-update.cc
@@ -266,7 +266,11 @@ bool DoUpdate()
if (upgradable == 0)
c1out << _("All packages are up to date.") << std::endl;
else
- ioprintf(c1out, msg, upgradable);
+ {
+ c1out << _config->Find("APT::Color::Bold");
+ ioprintf(c1out, msg, upgradable);
+ c1out << _config->Find("APT::Color::Neutral");
+ }
RunScripts("APT::Update::Post-Invoke-Stats");
}
diff --git a/doc/examples/configure-index b/doc/examples/configure-index
index 3f6140038..981fe6f93 100644
--- a/doc/examples/configure-index
+++ b/doc/examples/configure-index
@@ -726,6 +726,7 @@ apt::planner "<STRING>";
apt::system "<STRING>";
apt::acquire::translation "<STRING>"; // deprecated in favor of Acquire::Languages
apt::color::highlight "<STRING>";
+apt::color::bold "<STRING>";
apt::color::neutral "<STRING>";
apt::output-version "<INT>";
@@ -888,6 +889,8 @@ Rred::Compress "<STRING>";
APT::Internal::OpProgress::Absolute "<BOOL>";
APT::Internal::OpProgress::EraseLines "<BOOL>";
APT::Color "<BOOL>";
+APT::Color::Show::Field "<STRING>";
+APT::Color::Show::Package "<STRING>";
update-manager::always-include-phased-updates "<BOOL>";
update-manager::never-include-phased-updates "<BOOL>";