From 85f9a2650850b181208492de61822cf840ee62e5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 23 Apr 2024 06:10:52 +0200 Subject: Merging upstream version 2.9.2. Signed-off-by: Daniel Baumann --- apt-pkg/aptconfiguration.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'apt-pkg/aptconfiguration.cc') diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 982e68b..f462b6e 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -563,4 +563,39 @@ bool Configuration::checkUsrMerged() return true; } /*}}}*/ +// isUsrMerged - whether usr is merged t /*{{{*/ +// --------------------------------------------------------------------- +/* */ +std::string Configuration::color(std::string const &colorName, std::string const &content) +{ + if (not _config->FindB("APT::Color")) + return content; + + auto colors = ::Configuration(_config->Tree("APT::Color")); + auto color = colors.Find(colorName); + + // Resolve the color recursively. A color string has the following format + // := \x1B ; fully resolved color + // | \\x1B ; color escaped. + // | ; a simple color name + // | ; a sequence of colors + if (color.find(" ") != color.npos) + { + std::string res; + for (auto &&colorPart : VectorizeString(color, ' ')) + res += Configuration::color(colorPart); + color = res; + } + else if (not color.empty() && color[0] != '\x1B') + { + if (APT::String::Startswith(color, "\\x1B")) + color = "\x1B" + color.substr(4); + else + color = Configuration::color(color); + } + if (content.empty()) + return color; + return color + content + Configuration::color("Neutral"); +} + /*}}}*/ } -- cgit v1.2.3