From: Vladimír Vondruš Date: Thu, 5 Dec 2019 18:49:06 +0000 (+0100) Subject: m.code: improve ANSI coloring to work on ASan output as well. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=4cb5bd31a7a21c7b30bdc12bed61e56e4b7166c6;p=blog.git m.code: improve ANSI coloring to work on ASan output as well. --- 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 @@ ![mosra@don-perverzo m.css]$ ls CONTRIBUTING.rst CREDITS.rst doc plugins README.rst 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 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:

‌██ ‌██ ‌██ ‌██ ‌██ ‌▓▓ ‌▒▒