private-output.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef APT_PRIVATE_OUTPUT_H
  2. #define APT_PRIVATE_OUTPUT_H
  3. #include <apt-pkg/configuration.h>
  4. #include <apt-pkg/pkgcache.h>
  5. #include <apt-pkg/macros.h>
  6. #include <functional>
  7. #include <fstream>
  8. #include <string>
  9. #include <iostream>
  10. // forward declaration
  11. class pkgCacheFile;
  12. class CacheFile;
  13. class pkgDepCache;
  14. class pkgRecords;
  15. APT_PUBLIC extern std::ostream c0out;
  16. APT_PUBLIC extern std::ostream c1out;
  17. APT_PUBLIC extern std::ostream c2out;
  18. APT_PUBLIC extern std::ofstream devnull;
  19. APT_PUBLIC extern unsigned int ScreenWidth;
  20. APT_PUBLIC bool InitOutput(std::basic_streambuf<char> * const out = std::cout.rdbuf());
  21. void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records,
  22. pkgCache::VerIterator const &V, std::ostream &out,
  23. std::string const &format);
  24. // helper to describe global state
  25. APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now);
  26. APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now);
  27. template<class Container, class PredicateC, class DisplayP, class DisplayV> bool ShowList(std::ostream &out, std::string const &Title,
  28. Container const &cont,
  29. PredicateC Predicate,
  30. DisplayP PkgDisplay,
  31. DisplayV VerboseDisplay)
  32. {
  33. size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0;
  34. int ScreenUsed = 0;
  35. bool const ShowVersions = _config->FindB("APT::Get::Show-Versions", false);
  36. bool printedTitle = false;
  37. for (auto const &Pkg: cont)
  38. {
  39. if (Predicate(Pkg) == false)
  40. continue;
  41. if (printedTitle == false)
  42. {
  43. out << Title;
  44. printedTitle = true;
  45. }
  46. if (ShowVersions == true)
  47. {
  48. out << std::endl << " " << PkgDisplay(Pkg);
  49. std::string const verbose = VerboseDisplay(Pkg);
  50. if (verbose.empty() == false)
  51. out << " (" << verbose << ")";
  52. }
  53. else
  54. {
  55. std::string const PkgName = PkgDisplay(Pkg);
  56. if (ScreenUsed == 0 || (ScreenUsed + PkgName.length()) >= ScreenWidth)
  57. {
  58. out << std::endl << " ";
  59. ScreenUsed = 0;
  60. }
  61. else if (ScreenUsed != 0)
  62. {
  63. out << " ";
  64. ++ScreenUsed;
  65. }
  66. out << PkgName;
  67. ScreenUsed += PkgName.length();
  68. }
  69. }
  70. if (printedTitle == true)
  71. {
  72. out << std::endl;
  73. return false;
  74. }
  75. return true;
  76. }
  77. void ShowNew(std::ostream &out,CacheFile &Cache);
  78. void ShowDel(std::ostream &out,CacheFile &Cache);
  79. void ShowKept(std::ostream &out,CacheFile &Cache);
  80. void ShowUpgraded(std::ostream &out,CacheFile &Cache);
  81. bool ShowDowngraded(std::ostream &out,CacheFile &Cache);
  82. bool ShowHold(std::ostream &out,CacheFile &Cache);
  83. bool ShowEssential(std::ostream &out,CacheFile &Cache);
  84. void Stats(std::ostream &out, pkgDepCache &Dep);
  85. // prompting
  86. bool YnPrompt(char const * const Question, bool Default=true);
  87. bool AnalPrompt(std::string const &Question, const char *Text);
  88. std::string PrettyFullName(pkgCache::PkgIterator const &Pkg);
  89. std::string CandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg);
  90. std::function<std::string(pkgCache::PkgIterator const &)> CandidateVersion(pkgCacheFile * const Cache);
  91. std::string CurrentToCandidateVersion(pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg);
  92. std::function<std::string(pkgCache::PkgIterator const &)> CurrentToCandidateVersion(pkgCacheFile * const Cache);
  93. std::string EmptyString(pkgCache::PkgIterator const &);
  94. bool AlwaysTrue(pkgCache::PkgIterator const &);
  95. #endif