[PATCH 2/4] Use distinct colors for output msg types

Michał Górny <[email protected]> Tue, 28 Sep 2021 16:20:02 +0200
Newsgroups gmane.linux.gentoo.portage.devel
Message-ID <[email protected]>
Introduce distinct colors per output function.  For elog and eerror
the colors remain the same but the names change.  For einfo and eqawarn,
use darker colors to distinguish them.

Signed-off-by: Michał Górny <[email protected]>
---
 bin/isolated-functions.sh    | 30 +++++++++++-------
 bin/save-ebuild-env.sh       |  6 ++--
 lib/portage/elog/messages.py | 10 +++---
 lib/portage/elog/mod_echo.py |  4 +--
 lib/portage/output.py        | 59 +++++++++++++++++++++++++++++++-----
 5 files changed, 81 insertions(+), 28 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 3e79ea6e3..df806d403 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -270,7 +270,7 @@ eqawarn() {
 	__elog_base QA "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " ${PORTAGE_COLOR_WARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
+		echo " ${PORTAGE_COLOR_QAWARN}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
 	done
 	LAST_E_CMD="eqawarn"
 	return 0
@@ -280,7 +280,7 @@ elog() {
 	__elog_base LOG "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
+		echo " ${PORTAGE_COLOR_LOG}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
 	done
 	LAST_E_CMD="elog"
 	return 0
@@ -290,7 +290,7 @@ einfo() {
 	__elog_base INFO "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
+		echo " ${PORTAGE_COLOR_INFO}*${PORTAGE_COLOR_NORMAL} ${REPLY}" >&2
 	done
 	LAST_E_CMD="einfo"
 	return 0
@@ -299,7 +299,7 @@ einfo() {
 einfon() {
 	__elog_base INFO "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
-	echo -ne " ${PORTAGE_COLOR_GOOD}*${PORTAGE_COLOR_NORMAL} $*" >&2
+	echo -ne " ${PORTAGE_COLOR_INFO}*${PORTAGE_COLOR_NORMAL} $*" >&2
 	LAST_E_CMD="einfon"
 	return 0
 }
@@ -318,7 +318,7 @@ eerror() {
 	__elog_base ERROR "$*"
 	[[ ${RC_ENDCOL} != "yes" && ${LAST_E_CMD} == "ebegin" ]] && echo >&2
 	echo -e "$@" | while read -r ; do
-		echo " ${PORTAGE_COLOR_BAD}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2
+		echo " ${PORTAGE_COLOR_ERR}*${PORTAGE_COLOR_NORMAL} ${RC_INDENTATION}${REPLY}" >&2
 	done
 	LAST_E_CMD="eerror"
 	return 0
@@ -378,12 +378,16 @@ __unset_colors() {
 	COLS=80
 	ENDCOL=
 
-	PORTAGE_COLOR_GOOD=
-	PORTAGE_COLOR_WARN=
 	PORTAGE_COLOR_BAD=
+	PORTAGE_COLOR_BRACKET=
+	PORTAGE_COLOR_ERR=
+	PORTAGE_COLOR_GOOD=
 	PORTAGE_COLOR_HILITE=
+	PORTAGE_COLOR_INFO=
+	PORTAGE_COLOR_LOG=
 	PORTAGE_COLOR_NORMAL=
-	PORTAGE_COLOR_BRACKET=
+	PORTAGE_COLOR_QAWARN=
+	PORTAGE_COLOR_WARN=
 }
 
 __set_colors() {
@@ -403,12 +407,16 @@ __set_colors() {
 	if [ -n "${PORTAGE_COLORMAP}" ] ; then
 		eval ${PORTAGE_COLORMAP}
 	else
-		PORTAGE_COLOR_GOOD=$'\e[32;01m'
-		PORTAGE_COLOR_WARN=$'\e[33;01m'
 		PORTAGE_COLOR_BAD=$'\e[31;01m'
-		PORTAGE_COLOR_HILITE=$'\e[36;01m'
 		PORTAGE_COLOR_BRACKET=$'\e[34;01m'
+		PORTAGE_COLOR_ERR=$'\e[31;01m'
+		PORTAGE_COLOR_GOOD=$'\e[32;01m'
+		PORTAGE_COLOR_HILITE=$'\e[36;01m'
+		PORTAGE_COLOR_INFO=$'\e[32m'
+		PORTAGE_COLOR_LOG=$'\e[32;01m'
 		PORTAGE_COLOR_NORMAL=$'\e[0m'
+		PORTAGE_COLOR_QAWARN=$'\e[33m'
+		PORTAGE_COLOR_WARN=$'\e[33;01m'
 	fi
 }
 
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
index 8d2ec67ed..98808814b 100644
--- a/bin/save-ebuild-env.sh
+++ b/bin/save-ebuild-env.sh
@@ -102,8 +102,10 @@ __save_ebuild_env() {
 		LAST_E_CMD LAST_E_LEN LD_PRELOAD MISC_FUNCTIONS_ARGS MOPREFIX \
 		NOCOLOR PKGDIR PKGUSE PKG_LOGDIR PKG_TMPDIR \
 		PORTAGE_BASHRC_FILES PORTAGE_BASHRCS_SOURCED \
-		PORTAGE_COLOR_BAD PORTAGE_COLOR_BRACKET PORTAGE_COLOR_GOOD \
-		PORTAGE_COLOR_HILITE PORTAGE_COLOR_NORMAL PORTAGE_COLOR_WARN \
+		PORTAGE_COLOR_BAD PORTAGE_COLOR_BRACKET PORTAGE_COLOR_ERR \
+		PORTAGE_COLOR_GOOD PORTAGE_COLOR_HILITE PORTAGE_COLOR_INFO \
+		PORTAGE_COLOR_LOG PORTAGE_COLOR_NORMAL PORTAGE_COLOR_QAWARN \
+		PORTAGE_COLOR_WARN \
 		PORTAGE_COMPRESS PORTAGE_COMPRESS_EXCLUDE_SUFFIXES \
 		PORTAGE_DOHTML_UNWARNED_SKIPPED_EXTENSIONS \
 		PORTAGE_DOHTML_UNWARNED_SKIPPED_FILES \
diff --git a/lib/portage/elog/messages.py b/lib/portage/elog/messages.py
index 923e10b69..6a67a45de 100644
--- a/lib/portage/elog/messages.py
+++ b/lib/portage/elog/messages.py
@@ -125,7 +125,7 @@ def _elog_base(level, msg, phase="other", key=None, color=None, out=None):
         out = sys.stdout
 
     if color is None:
-        color = "GOOD"
+        color = "INFO"
 
     msg = _unicode_decode(msg, encoding=_encodings["content"], errors="replace")
 
@@ -183,11 +183,11 @@ def _reset_buffer():
 
 # creating and exporting the actual messaging functions
 _functions = {
-    "einfo": ("INFO", "GOOD"),
-    "elog": ("LOG", "GOOD"),
+    "einfo": ("INFO", "INFO"),
+    "elog": ("LOG", "LOG"),
     "ewarn": ("WARN", "WARN"),
-    "eqawarn": ("QA", "WARN"),
-    "eerror": ("ERROR", "BAD"),
+    "eqawarn": ("QA", "QAWARN"),
+    "eerror": ("ERROR", "ERR"),
 }
 
 
diff --git a/lib/portage/elog/mod_echo.py b/lib/portage/elog/mod_echo.py
index fa9203c32..a63939988 100644
--- a/lib/portage/elog/mod_echo.py
+++ b/lib/portage/elog/mod_echo.py
@@ -60,10 +60,10 @@ def _finalize():
             for msgtype, msgcontent in logentries[phase]:
                 fmap = {
                     "INFO": printer.einfo,
+                    "LOG": printer.elog,
                     "WARN": printer.ewarn,
                     "ERROR": printer.eerror,
-                    "LOG": printer.einfo,
-                    "QA": printer.ewarn,
+                    "QA": printer.eqawarn,
                 }
                 if isinstance(msgcontent, str):
                     msgcontent = [msgcontent]
diff --git a/lib/portage/output.py b/lib/portage/output.py
index 9d8601b24..42f487f8a 100644
--- a/lib/portage/output.py
+++ b/lib/portage/output.py
@@ -140,12 +140,16 @@ codes["darkyellow"] = codes["0xAAAA00"]
 
 
 # Colors from /etc/init.d/functions.sh
-_styles["NORMAL"] = ("normal",)
-_styles["GOOD"] = ("green",)
-_styles["WARN"] = ("yellow",)
 _styles["BAD"] = ("red",)
-_styles["HILITE"] = ("teal",)
 _styles["BRACKET"] = ("blue",)
+_styles["ERR"] = ("red",)
+_styles["GOOD"] = ("green",)
+_styles["HILITE"] = ("teal",)
+_styles["INFO"] = ("darkgreen",)
+_styles["LOG"] = ("green",)
+_styles["NORMAL"] = ("normal",)
+_styles["QAWARN"] = ("brown",)
+_styles["WARN"] = ("yellow",)
 
 # Portage functions
 _styles["INFORM"] = ("darkgreen",)
@@ -377,7 +381,18 @@ def style_to_ansi_code(style):
 
 def colormap():
     mycolors = []
-    for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET", "NORMAL"):
+    for c in (
+        "BAD",
+        "BRACKET",
+        "ERR",
+        "GOOD",
+        "HILITE",
+        "INFO",
+        "LOG",
+        "NORMAL",
+        "QAWARN",
+        "WARN",
+    ):
         mycolors.append("PORTAGE_COLOR_{}=$'{}'".format(c, style_to_ansi_code(c)))
     return "\n".join(mycolors)
 
@@ -665,7 +680,7 @@ class EOutput:
         if not self.quiet:
             if self.__last_e_cmd == "ebegin":
                 self._write(out, "\n")
-            self._write(out, colorize("BAD", " * ") + msg + "\n")
+            self._write(out, colorize("ERR", " * ") + msg + "\n")
         self.__last_e_cmd = "eerror"
 
     def einfo(self, msg):
@@ -679,7 +694,7 @@ class EOutput:
         if not self.quiet:
             if self.__last_e_cmd == "ebegin":
                 self._write(out, "\n")
-            self._write(out, colorize("GOOD", " * ") + msg + "\n")
+            self._write(out, colorize("INFO", " * ") + msg + "\n")
         self.__last_e_cmd = "einfo"
 
     def einfon(self, msg):
@@ -693,9 +708,37 @@ class EOutput:
         if not self.quiet:
             if self.__last_e_cmd == "ebegin":
                 self._write(out, "\n")
-            self._write(out, colorize("GOOD", " * ") + msg)
+            self._write(out, colorize("INFO", " * ") + msg)
         self.__last_e_cmd = "einfon"
 
+    def eqawarn(self, msg):
+        """
+        Shows a QA warning.
+
+        @param msg: A very brief (shorter than one line) warning message.
+        @type msg: StringType
+        """
+        out = sys.stderr
+        if not self.quiet:
+            if self.__last_e_cmd == "ebegin":
+                self._write(out, "\n")
+            self._write(out, colorize("QAWARN", " * ") + msg + "\n")
+        self.__last_e_cmd = "ewarn"
+
+    def elog(self, msg):
+        """
+        Shows a logged informative message terminated with a newline.
+
+        @param msg: A very brief (shorter than one line) informative message.
+        @type msg: StringType
+        """
+        out = sys.stdout
+        if not self.quiet:
+            if self.__last_e_cmd == "ebegin":
+                self._write(out, "\n")
+            self._write(out, colorize("LOG", " * ") + msg + "\n")
+        self.__last_e_cmd = "elog"
+
     def ewarn(self, msg):
         """
         Shows a warning message.
-- 
2.33.0