diff options
author | Michael Vogt <mvo@debian.org> | 2015-08-18 11:57:35 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2015-08-18 11:57:35 +0200 |
commit | b53c9cea2902572822bbbece5bac236c1bbf846e (patch) | |
tree | 6c6b0524e0971c0623ccbff71383523ee0b2a5cc /apt-private/private-output.h | |
parent | 21248c0f00ee71412dbadc6ebf84011cf974346d (diff) | |
parent | 2a22cd60f04c4291ea9b9b72e15b6d2ec378b001 (diff) |
Merge remote-tracking branch 'upstream/debian/experimental' into feature/srv-records
Diffstat (limited to 'apt-private/private-output.h')
-rw-r--r-- | apt-private/private-output.h | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/apt-private/private-output.h b/apt-private/private-output.h index d5b57adec..4930fd981 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -1,9 +1,11 @@ #ifndef APT_PRIVATE_OUTPUT_H #define APT_PRIVATE_OUTPUT_H +#include <apt-pkg/configuration.h> #include <apt-pkg/pkgcache.h> #include <apt-pkg/macros.h> +#include <functional> #include <fstream> #include <string> #include <iostream> @@ -32,8 +34,61 @@ 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 bool ShowList(std::ostream &out, std::string Title, std::string List, - std::string VersionsList); +template<class Container, class PredicateC, class DisplayP, class DisplayV> APT_PUBLIC bool ShowList(std::ostream &out, std::string const &Title, + Container const &cont, + PredicateC Predicate, + DisplayP PkgDisplay, + DisplayV VerboseDisplay) +{ + size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0; + int ScreenUsed = 0; + bool const ShowVersions = _config->FindB("APT::Get::Show-Versions", false); + bool printedTitle = false; + + for (auto const &Pkg: cont) + { + if (Predicate(Pkg) == false) + continue; + + if (printedTitle == false) + { + out << Title; + printedTitle = true; + } + + if (ShowVersions == true) + { + out << std::endl << " " << PkgDisplay(Pkg); + std::string const verbose = VerboseDisplay(Pkg); + if (verbose.empty() == false) + out << " (" << verbose << ")"; + } + else + { + std::string const PkgName = PkgDisplay(Pkg); + if (ScreenUsed == 0 || (ScreenUsed + PkgName.length()) >= ScreenWidth) + { + out << std::endl << " "; + ScreenUsed = 0; + } + else if (ScreenUsed != 0) + { + out << " "; + ++ScreenUsed; + } + out << PkgName; + ScreenUsed += PkgName.length(); + } + } + + if (printedTitle == true) + { + out << std::endl; + return false; + } + return true; +} + void ShowNew(std::ostream &out,CacheFile &Cache); void ShowDel(std::ostream &out,CacheFile &Cache); void ShowKept(std::ostream &out,CacheFile &Cache); @@ -49,4 +104,12 @@ void Stats(std::ostream &out, pkgDepCache &Dep); bool YnPrompt(bool Default=true); bool AnalPrompt(const char *Text); +std::string PrettyFullName(pkgCache::PkgIterator const &Pkg); +std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); +std::function<std::string(pkgCache::PkgIterator const &)> CandidateVersion(pkgCacheFile * const Cache); +std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg); +std::function<std::string(pkgCache::PkgIterator const &)> CurrentToCandidateVersion(pkgCacheFile * const Cache); +std::string EmptyString(pkgCache::PkgIterator const &); +bool AlwaysTrue(pkgCache::PkgIterator const &); + #endif |