>From 3104e51811e74ed8963a518ead6ce90306957929 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 9 Jul 2021 20:03:51 -0700 Subject: [PATCH] POC: Interpret expanded color range in ERC goodies * lisp/erc/erc-goodies (erc-get-bg-color-face, erc-get-fg-color-face): Non-newsworthy breaking change: return lists instead of symbols. (erc-controls-propertize): Allow passing 'face in addition to 'font-lock-face as text property key for expanded color range. --- lisp/erc/erc-goodies.el | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index fc9a8d39ef..c302cc829f 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -339,19 +339,39 @@ bg:erc-color-face15 "ERC face." :group 'erc-faces) +;; https://modern.ircdocs.horse/formatting.html#colors-16-98 +(defvar erc-color-upper-non-ansi + ["#470000" "#472100" "#474700" "#324700" "#004700" "#00472c" + "#004747" "#002747" "#000047" "#2e0047" "#470047" "#47002a" + "#740000" "#743a00" "#747400" "#517400" "#007400" "#007449" + "#007474" "#004074" "#000074" "#4b0074" "#740074" "#740045" + "#b50000" "#b56300" "#b5b500" "#7db500" "#00b500" "#00b571" + "#00b5b5" "#0063b5" "#0000b5" "#7500b5" "#b500b5" "#b5006b" + "#ff0000" "#ff8c00" "#ffff00" "#b2ff00" "#00ff00" "#00ffa0" + "#00ffff" "#008cff" "#0000ff" "#a500ff" "#ff00ff" "#ff0098" + "#ff5959" "#ffb459" "#ffff71" "#cfff60" "#6fff6f" "#65ffc9" + "#6dffff" "#59b4ff" "#5959ff" "#c459ff" "#ff66ff" "#ff59bc" + "#ff9c9c" "#ffd39c" "#ffff9c" "#e2ff9c" "#9cff9c" "#9cffdb" + "#9cffff" "#9cd3ff" "#9c9cff" "#dc9cff" "#ff9cff" "#ff94d3" + "#000000" "#131313" "#282828" "#363636" "#4d4d4d" "#656565" + "#818181" "#9f9f9f" "#bcbcbc" "#e2e2e2" "#ffffff"]) + (defun erc-get-bg-color-face (n) "Fetches the right face for background color N (0-15)." (if (stringp n) (setq n (string-to-number n))) (if (not (numberp n)) (prog1 'default (erc-error "erc-get-bg-color-face: n is NaN: %S" n)) - (when (> n 16) + (when (> n 99) (erc-log (format " Wrong color: %s" n)) (setq n (mod n 16))) (cond ((and (>= n 0) (< n 16)) - (intern (concat "bg:erc-color-face" (number-to-string n)))) - (t (erc-log (format " Wrong color: %s" n)) 'default)))) + (list (intern (concat "bg:erc-color-face" (number-to-string n))))) + ((< 15 n 99) + (list :background (aref erc-color-upper-non-ansi (- n 16)))) + ((= n 99) '(default)) + (t (erc-log (format " Wrong color: %s" n)) '(default))))) (defun erc-get-fg-color-face (n) "Fetches the right face for foreground color N (0-15)." @@ -359,13 +379,16 @@ erc-get-fg-color-face (if (not (numberp n)) (prog1 'default (erc-error "erc-get-fg-color-face: n is NaN: %S" n)) - (when (> n 16) + (when (> n 99) (erc-log (format " Wrong color: %s" n)) (setq n (mod n 16))) (cond ((and (>= n 0) (< n 16)) - (intern (concat "fg:erc-color-face" (number-to-string n)))) - (t (erc-log (format " Wrong color: %s" n)) 'default)))) + (list (intern (concat "fg:erc-color-face" (number-to-string n))))) + ((< 15 n 99) + (list :foreground (aref erc-color-upper-non-ansi (- n 16)))) + ((= n 99) '(default)) + (t (erc-log (format " Wrong color: %s" n)) '(default))))) (define-erc-module irccontrols nil "This mode enables the interpretation of IRC control chars." @@ -503,7 +526,9 @@ erc-controls-propertize (font-lock-prepend-text-property from to - 'font-lock-face + (if (and-let* ((n (or fg bg)) ((> 99 (string-to-number n) 15)))) + 'face + 'font-lock-face) (append (if boldp '(erc-bold-face) nil) @@ -517,10 +542,10 @@ erc-controls-propertize '(erc-underline-face) nil) (if fg - (list (erc-get-fg-color-face fg)) + (erc-get-fg-color-face fg) nil) (if bg - (list (erc-get-bg-color-face bg)) + (erc-get-bg-color-face bg) nil)) str) str) -- 2.31.1