From 3e0e6581dd3d3a453b60d6acd3ca3147c715c456 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 12:18:28 +0200 Subject: Merging upstream version 2.9.0. Signed-off-by: Daniel Baumann --- apt-private/private-output.h | 46 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'apt-private/private-output.h') diff --git a/apt-private/private-output.h b/apt-private/private-output.h index c3e73d5..4cc7c01 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -10,6 +10,7 @@ #include #include #include +#include // forward declaration class pkgCacheFile; @@ -35,16 +36,24 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now); APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now); +APT_PUBLIC void ShowWithColumns(std::ostream &out, const std::vector &List, size_t Indent, size_t ScreenWidth); + template bool ShowList(std::ostream &out, std::string const &Title, Container const &cont, PredicateC Predicate, DisplayP PkgDisplay, - DisplayV VerboseDisplay) + DisplayV VerboseDisplay, + std::string colorName = "APT::Color::Neutral") { size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0; int ScreenUsed = 0; bool const ShowVersions = _config->FindB("APT::Get::Show-Versions", false); + bool const ListColumns = _config->FindB("APT::Get::List-Columns", _config->FindI("APT::Output-Version") >= 30); bool printedTitle = false; + std::vector PackageList; + + auto setColor = _config->FindI("APT::Output-Version") >= 30 ? _config->Find(colorName) : ""; + auto resetColor = _config->FindI("APT::Output-Version") >= 30 ? _config->Find("APT::Color::Neutral") : ""; for (auto const &Pkg: cont) { @@ -59,7 +68,7 @@ template bool if (ShowVersions == true) { - out << std::endl << " " << PkgDisplay(Pkg); + out << std::endl << " " << setColor << PkgDisplay(Pkg) << resetColor; std::string const verbose = VerboseDisplay(Pkg); if (verbose.empty() == false) out << " (" << verbose << ")"; @@ -67,24 +76,37 @@ template bool else { std::string const PkgName = PkgDisplay(Pkg); - if (ScreenUsed == 0 || (ScreenUsed + PkgName.length()) >= ScreenWidth) + if (ListColumns) + PackageList.push_back(PkgName); + else { - out << std::endl << " "; - ScreenUsed = 0; + if (ScreenUsed == 0 || (ScreenUsed + PkgName.length()) >= ScreenWidth) + { + out << std::endl + << " "; + ScreenUsed = 0; + } + else if (ScreenUsed != 0) + { + out << " "; + ++ScreenUsed; + } + out << setColor << PkgName << resetColor; + ScreenUsed += PkgName.length(); } - else if (ScreenUsed != 0) - { - out << " "; - ++ScreenUsed; - } - out << PkgName; - ScreenUsed += PkgName.length(); } } if (printedTitle == true) { out << std::endl; + if (ListColumns && not PackageList.empty()) { + out << setColor; + ShowWithColumns(out, PackageList, 2, ScreenWidth); + out << resetColor; + } + if (_config->FindI("APT::Output-Version") >= 30) + out << std::endl; return false; } return true; -- cgit v1.2.3