diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2024-04-19 16:05:08 +0200 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-04-19 16:58:24 +0200 |
commit | e07450beb5a474ec3c099ff3eb329892b040d04c (patch) | |
tree | 12ec39caf852bec96cc01e85fc77cf868a548751 | |
parent | 58ee0fabc9028fcdf86faab3bb9c1db2b27e3644 (diff) |
Use APT::Configuration::color to apply color to output
-rw-r--r-- | apt-private/acqprogress.cc | 5 | ||||
-rw-r--r-- | apt-private/private-install.cc | 2 | ||||
-rw-r--r-- | apt-private/private-output.cc | 18 | ||||
-rw-r--r-- | apt-private/private-output.h | 8 |
4 files changed, 18 insertions, 15 deletions
diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc index 1f5acdd97..b4b16e6a9 100644 --- a/apt-private/acqprogress.cc +++ b/apt-private/acqprogress.cc @@ -9,6 +9,7 @@ // Include files /*{{{*/ #include <config.h> +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/acquire-item.h> #include <apt-pkg/acquire-worker.h> #include <apt-pkg/acquire.h> @@ -281,14 +282,14 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner) // Draw the current status if (_config->FindB("Apt::Color", false) == true) - out << _config->Find("APT::Color::Yellow"); + out << APT::Configuration::color("Yellow"); if (LastLineLength > Line.length()) clearLastLine(); else out << '\r'; out << Line << std::flush; if (_config->FindB("Apt::Color", false) == true) - out << _config->Find("APT::Color::Neutral") << std::flush; + out << APT::Configuration::color("Neutral") << std::flush; LastLineLength = Line.length(); Update = false; diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index ecbd703d8..87793d973 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -1104,7 +1104,7 @@ bool DoInstall(CommandLine &CmdL) if (_config->FindI("APT::Output-Version") < 30 && Cache->InstCount() != verset[MOD_INSTALL].size()) ShowList(c1out, _("The following additional packages will be installed:"), Universe, PkgIsExtraInstalled(&Cache, &verset[MOD_INSTALL]), - &PrettyFullName, CandidateVersion(&Cache), "APT::Color::Green"); + &PrettyFullName, CandidateVersion(&Cache), "green"); /* Print out a list of suggested and recommended packages */ if (_config->FindI("APT::Output-Version") < 30) diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 522fba4c6..380558964 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -1,6 +1,7 @@ // Include files /*{{{*/ #include <config.h> +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/cachefile.h> #include <apt-pkg/configuration.h> #include <apt-pkg/depcache.h> @@ -30,6 +31,7 @@ /*}}}*/ using namespace std; +using APT::Configuration::color; std::ostream c0out(0); std::ostream c1out(0); @@ -302,8 +304,8 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ else if (V.ParentPkg()->CurrentState == pkgCache::State::ConfigFiles) StatusStr = _("[residual-config]"); output = SubstVar(output, "${apt:Status}", StatusStr); - output = SubstVar(output, "${color:highlight}", _config->Find("APT::Color::Highlight", "")); - output = SubstVar(output, "${color:neutral}", _config->Find("APT::Color::Neutral", "")); + output = SubstVar(output, "${color:highlight}", color("Highlight")); + output = SubstVar(output, "${color:neutral}", color("Neutral")); output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P)); if (output.find("${LongDescription}") != string::npos) output = SubstVar(output, "${LongDescription}", GetLongDescription(CacheFile, records, P)); @@ -555,7 +557,7 @@ void ShowNew(ostream &out,CacheFile &Cache) [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall(); }, &PrettyFullName, CandidateVersion(&Cache), - "APT::Color::Green"); + "green"); return; } @@ -563,12 +565,12 @@ void ShowNew(ostream &out,CacheFile &Cache) [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall() && (Cache[Pkg].Flags & pkgCache::Flag::Auto) == 0; }, &PrettyFullName, CandidateVersion(&Cache), - "APT::Color::Green"); + "green"); ShowList(out,_("Installing dependencies:"), Universe, [&Cache](pkgCache::PkgIterator const &Pkg) { return Cache[Pkg].NewInstall() && Cache[Pkg].Flags & pkgCache::Flag::Auto;}, &PrettyFullName, CandidateVersion(&Cache), - "APT::Color::Green"); + "green"); } /*}}}*/ // ShowDel - Show packages to delete /*{{{*/ @@ -586,7 +588,7 @@ void ShowDel(ostream &out,CacheFile &Cache) return str; }, CandidateVersion(&Cache), - "APT::Color::Red"); + "red"); } /*}}}*/ // ShowPhasing - Show packages kept due to phasing /*{{{*/ @@ -625,7 +627,7 @@ void ShowUpgraded(ostream &out,CacheFile &Cache) }, &PrettyFullName, CurrentToCandidateVersion(&Cache), - "APT::Color::Green"); + "green"); } /*}}}*/ // ShowDowngraded - Show downgraded packages /*{{{*/ @@ -642,7 +644,7 @@ bool ShowDowngraded(ostream &out,CacheFile &Cache) }, &PrettyFullName, CurrentToCandidateVersion(&Cache), - "APT::Color::Yellow"); + "yellow"); } /*}}}*/ // ShowHold - Show held but changed packages /*{{{*/ diff --git a/apt-private/private-output.h b/apt-private/private-output.h index 4cc7c01b4..330801bb0 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -1,6 +1,7 @@ #ifndef APT_PRIVATE_OUTPUT_H #define APT_PRIVATE_OUTPUT_H +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/cacheset.h> #include <apt-pkg/configuration.h> #include <apt-pkg/macros.h> @@ -18,7 +19,6 @@ class CacheFile; class pkgDepCache; class pkgRecords; - APT_PUBLIC extern std::ostream c0out; APT_PUBLIC extern std::ostream c1out; APT_PUBLIC extern std::ostream c2out; @@ -43,7 +43,7 @@ template<class Container, class PredicateC, class DisplayP, class DisplayV> bool PredicateC Predicate, DisplayP PkgDisplay, DisplayV VerboseDisplay, - std::string colorName = "APT::Color::Neutral") + std::string colorName = "") { size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0; int ScreenUsed = 0; @@ -52,8 +52,8 @@ template<class Container, class PredicateC, class DisplayP, class DisplayV> bool bool printedTitle = false; std::vector<std::string> 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") : ""; + auto setColor = _config->FindI("APT::Output-Version") >= 30 ? APT::Configuration::color(colorName) : ""; + auto resetColor = _config->FindI("APT::Output-Version") >= 30 && not setColor.empty() ? APT::Configuration::color("neutral") : ""; for (auto const &Pkg: cont) { |