From: Alex Schroeder Date: Thu, 23 Jul 2020 14:10:29 +0000 (+0200) Subject: Use xterm-color instead of ansi-color, if possible X-Git-Tag: v3.0.0~22^2~35 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=58c468838df30dd4f7ab8c588c6f835fc306200e;p=elpher.git Use xterm-color instead of ansi-color, if possible xterm-color isn't part of Emacs, so require it but if it can't be found, require ansi-color instead. Then use two aliases that point either the xterm-color code or to ansi-color code. --- diff --git a/elpher.el b/elpher.el index 9b57324..64ec7ca 100644 --- a/elpher.el +++ b/elpher.el @@ -5,8 +5,8 @@ ;; Copyright (C) 2021 Christopher Brannon ;; Copyright (C) 2021 Omar Polo ;; Copyright (C) 2021 Noodles! +;; Copyright (C) 2020-2021 Alex Schroeder ;; Copyright (C) 2020 Étienne Deparis -;; Copyright (C) 2020 Alex Schroeder ;; Copyright (C) 2020 Simon Nicolussi ;; Copyright (C) 2020 Michel Alexandre Salim ;; Copyright (C) 2020 Koushk Roy @@ -75,11 +75,27 @@ (require 'url-util) (require 'subr-x) (require 'dns) -(require 'ansi-color) (require 'nsm) (require 'gnutls) (require 'socks) +;;; ANSI colors or XTerm colors + +(or (require 'xterm-color nil t) + (require 'ansi-color)) + +(defalias 'elpher-color-filter-apply + (if (fboundp 'xterm-color-filter) + (lambda (s) + (let ((xterm-color-render nil)) + (xterm-color-filter s))) + 'ansi-color-filter-apply) + "A function to filter out ANSI escape sequences.") +(defalias 'elpher-color-apply + (if (fboundp 'xterm-color-filter) + 'xterm-color-filter + 'ansi-color-apply) + "A function to apply ANSI escape sequences.") ;;; Global constants ;; @@ -973,7 +989,7 @@ If ADDRESS is not supplied or nil the record is rendered as an (if type-map-entry (let* ((margin-code (elt type-map-entry 2)) (face (elt type-map-entry 3)) - (filtered-display-string (ansi-color-filter-apply display-string)) + (filtered-display-string (elpher-color-filter-apply display-string)) (page (elpher-make-page filtered-display-string address))) (elpher-insert-margin margin-code) (insert-text-button filtered-display-string @@ -1038,8 +1054,8 @@ If ADDRESS is not supplied or nil the record is rendered as an "Perform any desired processing of STRING prior to display as text. Currently includes buttonifying URLs and processing ANSI escape codes." (elpher-buttonify-urls (if elpher-filter-ansi-from-text - (ansi-color-filter-apply string) - (ansi-color-apply string)))) + (elpher-color-filter-apply string) + (elpher-color-apply string)))) (defun elpher-render-text (data &optional _mime-type-string) "Render DATA as text. MIME-TYPE-STRING is unused." @@ -1391,7 +1407,7 @@ treatment that a separate function is warranted." (insert elpher-gemini-link-string) (if type-map-entry (let* ((face (elt type-map-entry 3)) - (filtered-display-string (ansi-color-filter-apply display-string)) + (filtered-display-string (elpher-color-filter-apply display-string)) (page (elpher-make-page filtered-display-string address))) (insert-text-button filtered-display-string 'face face