diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2020-03-10 22:26:52 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2020-03-24 10:24:39 +0100 |
commit | 768f0031930a994ecfab84ecd6478852275a98c3 (patch) | |
tree | c2e50b9642325bbb020a015a4d0ae8d9b84e3554 /apt-pkg | |
parent | b0e2c9de13ff1df2f0f1cba2ceed88c710efea3a (diff) |
Add color highlighting to E:/W:/N: prefixes
This matches the definitions used by dpkg.
Closes: #953527
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/error.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index 7fb68a35e..ac53b9648 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -247,6 +247,32 @@ void GlobalError::MergeWithStack() { // GlobalError::Item::operator<< /*{{{*/ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) { + static constexpr auto COLOR_RESET = "\033[0m"; + static constexpr auto COLOR_NOTICE = "\033[33m"; // normal yellow + static constexpr auto COLOR_WARN = "\033[1;33m"; // bold yellow + static constexpr auto COLOR_ERROR = "\033[1;31m"; // bold red + + bool use_color = _config->FindB("APT::Color", false); + + if (use_color) + { + switch (i.Type) + { + case GlobalError::FATAL: + case GlobalError::ERROR: + out << COLOR_ERROR; + break; + case GlobalError::WARNING: + out << COLOR_WARN; + break; + case GlobalError::NOTICE: + out << COLOR_NOTICE; + break; + default: + break; + } + } + switch (i.Type) { case GlobalError::FATAL: @@ -264,6 +290,22 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) break; } out << ": "; + + if (use_color) + { + switch (i.Type) + { + case GlobalError::FATAL: + case GlobalError::ERROR: + case GlobalError::WARNING: + case GlobalError::NOTICE: + out << COLOR_RESET; + break; + default: + break; + } + } + std::string::size_type line_start = 0; std::string::size_type line_end; while ((line_end = i.Text.find_first_of("\n\r", line_start)) != std::string::npos) @@ -281,6 +323,10 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) else if (line_start != std::string::npos) out << std::endl << " " << i.Text.substr(line_start); + + if (use_color) + out << COLOR_RESET; + return out; } /*}}}*/ |