From 4cb5bd31a7a21c7b30bdc12bed61e56e4b7166c6 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?=
Date: Thu, 5 Dec 2019 19:49:06 +0100
Subject: [PATCH] m.code: improve ANSI coloring to work on ASan output as well.
---
doc/plugins/math-and-code-console.ansi | 4 ++++
plugins/ansilexer.py | 23 +++++++++++++----------
plugins/m/test/code/page.html | 6 +++++-
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/doc/plugins/math-and-code-console.ansi b/doc/plugins/math-and-code-console.ansi
index db53fd3f..742c3f5e 100644
--- a/doc/plugins/math-and-code-console.ansi
+++ b/doc/plugins/math-and-code-console.ansi
@@ -1,3 +1,7 @@
![0;34m[[1;37mmosra@don-perverzo [0;37mm.css[0;34m][1;36m$ [0mls
CONTRIBUTING.rst CREDITS.rst [0m[01;34mdoc[0m [01;34mplugins[0m README.rst
COPYING [01;34mcss[0m [01;34mdocumentation[0m [01;34mpelican-theme[0m [01;34msite[0m
+
+ASan reports:
+
+=>0x0c287fff8030: [1m[0m00[1m[0m[[1m[34mfc[1m[0m][1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[34mfc[1m[0m [1m[31mfa[1m[0m [1m[31mfa[1m[0m [1m[31mfa[1m[0m [1m[31mfa[1m[0m [1m[31mfa[1m[0m
diff --git a/plugins/ansilexer.py b/plugins/ansilexer.py
index e22686b7..945c5194 100644
--- a/plugins/ansilexer.py
+++ b/plugins/ansilexer.py
@@ -44,23 +44,23 @@ class AnsiLexer(RegexLexer):
yield (match.start(), Text, text)
return
- if color == ';30':
+ if color == '30':
token += 'Black'
- elif color == ';31':
+ elif color == '31':
token += 'Red'
- elif color == ';32':
+ elif color == '32':
token += 'Green'
- elif color == ';33':
+ elif color == '33':
token += 'Yellow'
- elif color == ';34':
+ elif color == '34':
token += 'Blue'
- elif color == ';35':
+ elif color == '35':
token += 'Magenta'
- elif color == ';36':
+ elif color == '36':
token += 'Cyan'
- elif color == ';37':
+ elif color == '37':
token += 'White'
- elif color == ';39':
+ elif color == '39':
token += 'Default'
else:
yield (match.start(), Text, text)
@@ -83,7 +83,10 @@ class AnsiLexer(RegexLexer):
('[^\x1b]+', Text),
('\x1b\\[38;2;(\\d+);(\\d+);(\\d+)m\x1b\\[48;2;\\d+;\\d+;\\d+m([^\x1b]+)\x1b\\[0m', callback_fg_bg_color),
('\x1b\\[38;2;(\\d+);(\\d+);(\\d+)m([^\x1b]+)\x1b\\[0m', callback_fg_color),
- ('\x1b\\[(\\d+)(;\\d+)?m([^\x1b]*)', callback)]
+ # Brightness and color separately (used by ASan reports)
+ ('\x1b\\[([01])m\x1b\\[(\\d+)m([^\x1b]*)', callback),
+ ('\x1b\\[(\\d+)(?:;(\\d+))?m([^\x1b]*)', callback)
+ ]
}
_ansi_fg_color_re = re.compile('class="g g-AnsiForegroundColor([0-9a-f]{6})">')
diff --git a/plugins/m/test/code/page.html b/plugins/m/test/code/page.html
index ba58943b..54c84c42 100644
--- a/plugins/m/test/code/page.html
+++ b/plugins/m/test/code/page.html
@@ -33,7 +33,11 @@
rendered as plain monospace text: code
.
![mosra@don-perverzo m.css]$ ls
CONTRIBUTING.rst CREDITS.rst doc plugins README.rst
-COPYING css documentation pelican-theme site
+COPYING css documentation pelican-theme site
+
+ASan reports:
+
+=>0x0c287fff8030: 00[fc]fc fc fc fc fc fc fc fc fc fa fa fa fa fa
Console colors:
ââ ââ ââ ââ ââ ââ ââ
--
2.30.2