Commit Graph

8 Commits

Author SHA1 Message Date
Robin Jarry 9d71da175a colorize: make it compatible with BSD awk
Fix the following error seen on MacOS:

/usr/bin/awk: syntax error at source line 22 source file
                header_pattern = >>>  @ <<< /^[A-Z][[:alnum:]-]+:/

The @ character in front of regular expressions to pre-compile them
seems not in the POSIX specification. Replace them with regular strings
and call match() instead of the ~ operator.

Also, adjust the url_pattern expression for BSD awk which explicitly
states:

 The awk utility is compliant with the IEEE Std 1003.1-2008 (“POSIX.1”)
 specification, except awk does not support {n,m} pattern matching.

Use [[:lower:]]+ instead of [a-z]{2,6}.

Tested with:

  GNU Awk 5.1.1
  awk version 20121220 (FreeBSD)

Link: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
Fixes: https://todo.sr.ht/~rjarry/aerc/96
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-10-23 20:51:02 +02:00
Robin Jarry 41c14b206c filters/colorize: various fixes
Diff chunks can occur in the middle of email conversations followed by
regular and/or quoted text. Handle that properly.

Change diff meta lines inside quotes to bold. Update the meta lines with
more combination for renamed, copied and deleted files.

Fix the diff_chunk invalid color code, only colorize the chunk
characters, not the whole line.

Remove redundant variable resets to 0.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-on-irc-by: Tim Culverhouse <tim@timculverhouse.com>
2022-10-20 00:28:58 +02:00
Robin Jarry 3ef4a3ca05 filters: try and make awk scripts posix compliant
\x escape sequences are GNU specific. Use the octal escape code instead.

filters/calendar is beyond help. It would need a complete rewrite to
make it work with POSIX awk.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
2022-07-18 13:58:21 +02:00
Robin Jarry 142647d7c9 filters/colorize: use /usr/bin/awk shebang
/bin is reserved for essential commands that may be used when in single
user mode.

Link: https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#binEssentialUserCommandBinaries
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-07-11 21:15:56 +02:00
Robin Jarry 807870ea35 colorize: handle mailto prefixes in urls
mailto:email@domain.tld is the only exception that does not use the
<scheme>:// prefix.

Requested-by: Moritz Poldrack <moritz@poldrack.dev>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
2022-03-18 23:41:56 +01:00
Robin Jarry d2c239292e filters: fix colorize urls in signatures
When a signature contains a line that starts with an url, the url is not
highlighted properly:

  --
  Foobar
  [38;2;255;255;175mmhttps://foobar.org

The trailing m of the signature color start \x1b[38;2;175;135;255m is
considered as part of the URL scheme (i.e. mhttps:// instead of
https://). Colorize the URLs first before wrapping with the signature
color.

Fixes: df8c129235 ("filters: port colorize to awk")
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-03-03 21:38:02 +01:00
Robin Jarry df8c129235 filters: port colorize to awk
Python is not available on all systems. Port the colorize filter to awk
as it is a more widespread POSIX utility.

Users are free to copy the filter into their home dir and tweak the
colors to their needs. The highlighted items are:

  =============== ======= ======= ========= =================
  Item            Red     Green   Blue      Color
  =============== ======= ======= ========= =================
  quoted text 1   95      175     255       Blue
  quoted text 2   255     135     0         Orange
  quoted text 3   175     135     255       Purple
  quoted text 4   255     95      215       Pink
  quoted text *   128     128     128       Grey
  diff meta       255     255     255       White bold
  diff chunk      205     0       205       Cyan
  diff added      0       205     0         Red
  diff removed    205     0       0         Green
  signature       175     135     255       Purple
  header          175     135     255       Purple
  url             255     255     175       Yellow
  =============== ======= ======= ========= =================

This assumes a terminal emulator with true color support and with
a dark/black background.

Link: https://github.com/termstandard/colors
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-02-21 19:16:00 +01:00
Robin Jarry c63ca9bd9c filters: rename plaintext to colorize
This filter script is not compatible with the previous one. Rename it to
avoid issues with existing configs.

Fixes: bca93cd915 ("filters: add a more complete plaintext filter")
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-02-20 23:46:29 +01:00
Renamed from filters/plaintext (Browse further)