commit: 6a3ab956fd07936d77292275b7658123bd387670
Author: Alfred Wingate <parona <AT> protonmail <DOT> com>
AuthorDate: Sat Feb 1 04:49:26 2025 +0000
Commit: Sebastian Pipping <sping <AT> gentoo <DOT> org>
CommitDate: Sat Feb 8 22:08:22 2025 +0000
URL: https://gitweb.gentoo.org/proj/elogv.git/commit/?id=6a3ab956
elogv: strip ansi color codes
User installed QA scripts such as iwdevtools may include their own color
output in their logs, but curses cannot handle these without proper
explicit handling.
Strip the codes instead of complicating printing.
Signed-off-by: Alfred Wingate <parona <AT> protonmail.com>
elogv | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/elogv b/elogv
index e927da2..ca0ddf0 100755
--- a/elogv
+++ b/elogv
@@ -590,6 +590,9 @@ class ElogViewer:
self.log_win.erase()
shown_all = False
+ # Good enough to catch stray color codes generated by iwdevtools etc.
+ ansi_code = re.compile(r"\033\[[0-9;:]*m")
+
for i in range(0, self.height // 2 - 4):
try:
x = next(self.logf_wrap)
@@ -609,6 +612,8 @@ class ElogViewer:
elif x.startswith("LOG:"):
self.log_win.addstr(x[: self.width - 2],
curses.color_pair(elog))
else:
+ # Strip embedded color codes
+ x = re.sub(ansi_code, "", x)
self.log_win.addstr(x[: self.width - 2],
curses.color_pair(normal))
except curses.error:
pass