diff options
author | Robin Jarry <robin@jarry.cc> | 2023-01-15 23:27:29 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-26 00:20:48 +0100 |
commit | 98e32d2ff22cba1e60caf6a252eee0d38f26f736 (patch) | |
tree | 249564b1942d0a42225243a8a598ec48bc896c6b /widgets | |
parent | 3191ee171c435a43912264b131340af66fea8112 (diff) | |
download | aerc-98e32d2ff22cba1e60caf6a252eee0d38f26f736.tar.gz |
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 <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/msgviewer.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 29ad0a83..8d9ca76e 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -605,6 +605,8 @@ func NewPartViewer( fmt.Sprintf("AERC_SUBJECT=%s", info.Envelope.Subject)) filter.Env = append(filter.Env, fmt.Sprintf("AERC_FROM=%s", format.FormatAddresses(info.Envelope.From))) + filter.Env = append(filter.Env, fmt.Sprintf("AERC_STYLESET=%s", + acct.UiConfig().StyleSetPath())) log.Debugf("<%s> part=%v %s: %v | %v", info.Envelope.MessageId, curindex, mime, filter, pager) if pagerin, err = pager.StdinPipe(); err != nil { |