From 98e32d2ff22cba1e60caf6a252eee0d38f26f736 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sun, 15 Jan 2023 23:27:29 +0100 Subject: filters: rewrite colorize in c Since its introduction, we had multiple issues with the colorize awk script with regard to non-GNU awk compatibility. Also, this script is standalone and the color theme must be hard coded into it. Reading from an external configuration file (aerc's styleset) from a non-GNU awk is close to impossible (and even far from trivial with GNU awk). Rewrite the builtin colorize filter in C to allow getting the color theme from aerc's active styleset. The theme is configured using the existing styleset syntax and attributes under a separate [viewer] section (see examples and man page). Export the active styleset file path to AERC_STYLESET env var when invoking the filter command so that colorize can access it and use it. I have tested compilation (with clang-analyzer and gcc -fanalyzer) and basic operation on FreeBSD, Fedora (glibc) and Alpine (muslibc). More tests would probably be required on MacOSX and older Linux distros. I also added test vectors to give some confidence that this works as expected. The execution with these vectors passed valgrind --leak-check=full without errors. NB: the default theme has changed to be more minimal. Sample stylesets have more colorful examples. The awk -v theme=xxx option is no longer supported. usage: colorize [-h] [-s FILE] [-f FILE] options: -h show this help message -s FILE use styleset file (default $AERC_STYLESET) -f FILE read from filename (default stdin) Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy Acked-by: Moritz Poldrack --- doc/aerc-stylesets.7.scd | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'doc/aerc-stylesets.7.scd') diff --git a/doc/aerc-stylesets.7.scd b/doc/aerc-stylesets.7.scd index 1303787c..eaedb4cb 100644 --- a/doc/aerc-stylesets.7.scd +++ b/doc/aerc-stylesets.7.scd @@ -136,6 +136,36 @@ styling. | *selector_chooser* : The item chooser in a selector ui element. +These next style objects only affect the built-in *colorize* filter and must be +declared under a *[viewer]* section of the styleset file. + +[[ *Style Object* +:[ *Description* +| *url* +: URLs. +| *header* +: RFC-822-like header names. +| *signature* +: Email signatures. +| *diff_meta* +: Patch diff meta lines. +| *diff_chunk* +: Patch diff chunks. +| *diff_add* +: Patch diff added lines. +| *diff_del* +: Patch diff deleted lines. +| *quote_1* +: First level quoted text. +| *quote_2* +: Second level quoted text. +| *quote_3* +: Third level quoted text. +| *quote_4* +: Fourth level quoted text. +| *quote_x* +: Above fourth level quoted text. + ## FNMATCH STYLE WILDCARD MATCHING The styleset configuration can be made simpler by using the fnmatch -- cgit