emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fc4d3ee 3/3: Revert "Add support for "bright" ANSI colors in ansi


From: Lars Ingebrigtsen
Subject: master fc4d3ee 3/3: Revert "Add support for "bright" ANSI colors in ansi-color"
Date: Thu, 26 Aug 2021 09:22:52 -0400 (EDT)

branch: master
commit fc4d3eea5ad675fe87d03cb0d16f8a33c3177e95
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Revert "Add support for "bright" ANSI colors in ansi-color"
    
    This reverts commit c8e3347ec01a9ed6dc8d88c2dbbb3a08497e8eb2.
    
    Jim Porter's paperwork isn't finalised yet.
---
 etc/NEWS                      |   7 ---
 lisp/ansi-color.el            | 116 ++++++++++--------------------------------
 test/lisp/ansi-color-tests.el |  51 +++----------------
 3 files changed, 34 insertions(+), 140 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 785fd68..78aca8c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -375,13 +375,6 @@ emulators by using the new input-meta-mode with the 
special value
 This parameter, similar to 'drag-with-header-line', allows moving frames
 by dragging the tab lines of their topmost windows with the mouse.
 
----
-** 'ansi-color' now supports "bright" color codes.
-"Bright" ANSI color codes are now displayed when applying ANSI color
-filters using the color values defined in 'ansi-bright-color-names-vector'.
-In addition, bold text with regular ANSI colors can be displayed as
-"bright" if 'ansi-color-bold-is-bright' is non-nil.
-
 
 * Editing Changes in Emacs 28.1
 
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index 0dc9a52..79dc821 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -150,48 +150,6 @@ foreground and background colors, respectively."
   :version "24.4" ; default colors copied from `xterm-standard-colors'
   :group 'ansi-colors)
 
-(defcustom ansi-bright-color-names-vector
-  ["gray30" "red2" "green2" "yellow2" "blue1" "magenta2" "cyan2" "white"]
-  "Colors used for SGR control sequences determining a \"bright\" color.
-This vector holds the colors used for SGR control sequences parameters
-90 to 97 (bright foreground colors) and 100 to 107 (brightbackground
-colors).
-
-Parameter   Color
-  90  100   bright black
-  91  101   bright red
-  92  102   bright green
-  93  103   bright yellow
-  94  104   bright blue
-  95  105   bright magenta
-  96  106   bright cyan
-  97  107   bright white
-
-This vector is used by `ansi-color-make-color-map' to create a color
-map.  This color map is stored in the variable `ansi-color-map'.
-
-Each element may also be a cons cell where the car and cdr specify the
-foreground and background colors, respectively."
-  :type '(vector (choice color (cons color color))
-                 (choice color (cons color color))
-                 (choice color (cons color color))
-                 (choice color (cons color color))
-                 (choice color (cons color color))
-                 (choice color (cons color color))
-                 (choice color (cons color color))
-                 (choice color (cons color color)))
-  :set 'ansi-color-map-update
-  :initialize 'custom-initialize-default
-  :version "28.1"
-  :group 'ansi-colors)
-
-(defcustom ansi-color-bold-is-bright nil
-  "If set to non-nil, combining ANSI bold and a color produces the bright
-version of that color."
-  :type 'boolean
-  :version "28.1"
-  :group 'ansi-colors)
-
 (defconst ansi-color-control-seq-regexp
   ;; See ECMA 48, section 5.4 "Control Sequences".
   "\e\\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]"
@@ -346,14 +304,9 @@ This function can be added to 
`comint-preoutput-filter-functions'."
 
 (defun ansi-color--find-face (codes)
   "Return the face corresponding to CODES."
-  ;; Sort the codes in ascending order to guarantee that "bold" comes before
-  ;; any of the colors.  This ensures that `ansi-color-bold-is-bright' is
-  ;; applied correctly.
-  (let (faces bright (codes (sort (copy-sequence codes) #'<)))
+  (let (faces)
     (while codes
-      (let ((face (ansi-color-get-face-1 (pop codes) bright)))
-        (when (and ansi-color-bold-is-bright (eq face 'bold))
-          (setq bright t))
+      (let ((face (ansi-color-get-face-1 (pop codes))))
        ;; In the (default underline) face, say, the value of the
        ;; "underline" attribute of the `default' face wins.
        (unless (eq face 'default)
@@ -617,11 +570,11 @@ ESCAPE-SEQUENCE is an escape sequence parsed by
 
 For each new code, the following happens: if it is 1-7, add it to
 the list of codes; if it is 21-25 or 27, delete appropriate
-parameters from the list of codes; if it is 30-37 (or 90-97) resp. 39,
-the foreground color code is replaced or added resp. deleted; if it
-is 40-47 (or 100-107) resp. 49, the background color code is replaced
-or added resp. deleted; any other code is discarded together with the
-old codes.  Finally, the so changed list of codes is returned."
+parameters from the list of codes; if it is 30-37 resp. 39, the
+foreground color code is replaced or added resp. deleted; if it
+is 40-47 resp. 49, the background color code is replaced or added
+resp. deleted; any other code is discarded together with the old
+codes. Finally, the so changed list of codes is returned."
   (let ((new-codes (ansi-color-parse-sequence escape-sequence)))
     (while new-codes
       (let* ((new (pop new-codes))
@@ -638,7 +591,7 @@ old codes.  Finally, the so changed list of codes is 
returned."
                                        (22 (remq 1 codes))
                                        (25 (remq 6 codes))
                                        (_ codes)))))
-               ((or 3 4 9 10) (let ((r (mod new 10)))
+               ((or 3 4) (let ((r (mod new 10)))
                            (unless (= r 8)
                              (let (beg)
                                (while (and codes (/= q (/ (car codes) 10)))
@@ -650,19 +603,6 @@ old codes.  Finally, the so changed list of codes is 
returned."
                (_ nil)))))
     codes))
 
-(defun ansi-color--fill-color-map (map map-index property vector get-color)
-  "Fill a range of color values from VECTOR and store in MAP.
-
-Start filling MAP from MAP-INDEX, and make faces for PROPERTY (`foreground'
-or `background'). GET-COLOR is a function taking an element of VECTOR and
-returning the color value to use."
-  (mapc
-   (lambda (e)
-     (aset map map-index
-           (ansi-color-make-face property (funcall get-color e)))
-     (setq map-index (1+ map-index)) )
-   vector))
-
 (defun ansi-color-make-color-map ()
   "Creates a vector of face definitions and returns it.
 
@@ -671,7 +611,7 @@ The index into the vector is an ANSI code.  See the 
documentation of
 
 The face definitions are based upon the variables
 `ansi-color-faces-vector' and `ansi-color-names-vector'."
-  (let ((map (make-vector 110 nil))
+  (let ((map (make-vector 50 nil))
         (index 0))
     ;; miscellaneous attributes
     (mapc
@@ -680,21 +620,23 @@ The face definitions are based upon the variables
        (setq index (1+ index)) )
      ansi-color-faces-vector)
     ;; foreground attributes
-    (ansi-color--fill-color-map
-     map 30 'foreground ansi-color-names-vector
-     (lambda (e) (if (consp e) (car e) e)))
+    (setq index 30)
+    (mapc
+     (lambda (e)
+       (aset map index
+             (ansi-color-make-face 'foreground
+                         (if (consp e) (car e) e)))
+       (setq index (1+ index)) )
+     ansi-color-names-vector)
     ;; background attributes
-    (ansi-color--fill-color-map
-     map 40 'background ansi-color-names-vector
-     (lambda (e) (if (consp e) (cdr e) e)))
-    ;; bright foreground attributes
-    (ansi-color--fill-color-map
-     map 90 'foreground ansi-bright-color-names-vector
-     (lambda (e) (if (consp e) (car e) e)))
-    ;; bright background attributes
-    (ansi-color--fill-color-map
-     map 100 'background ansi-bright-color-names-vector
-     (lambda (e) (if (consp e) (cdr e) e)))
+    (setq index 40)
+    (mapc
+     (lambda (e)
+       (aset map index
+             (ansi-color-make-face 'background
+                         (if (consp e) (cdr e) e)))
+       (setq index (1+ index)) )
+     ansi-color-names-vector)
     map))
 
 (defvar ansi-color-map (ansi-color-make-color-map)
@@ -718,13 +660,9 @@ property of `ansi-color-faces-vector' and 
`ansi-color-names-vector'."
   (set-default symbol value)
   (setq ansi-color-map (ansi-color-make-color-map)))
 
-(defun ansi-color-get-face-1 (ansi-code &optional bright)
+(defun ansi-color-get-face-1 (ansi-code)
   "Get face definition from `ansi-color-map'.
-ANSI-CODE is used as an index into the vector.  BRIGHT, if non-nil,
-requests \"bright\" ANSI colors, even if ANSI-CODE is a normal-intensity
-color."
-  (when (and bright (<= 30 ansi-code 49))
-    (setq ansi-code (+ ansi-code 60)))
+ANSI-CODE is used as an index into the vector."
   (condition-case nil
       (aref ansi-color-map ansi-code)
     (args-out-of-range nil)))
diff --git a/test/lisp/ansi-color-tests.el b/test/lisp/ansi-color-tests.el
index c94561b..107dc8e 100644
--- a/test/lisp/ansi-color-tests.el
+++ b/test/lisp/ansi-color-tests.el
@@ -25,54 +25,17 @@
 ;;; Code:
 
 (require 'ansi-color)
-(eval-when-compile (require 'cl-lib))
 
-(defvar yellow (aref ansi-color-names-vector 3))
-(defvar bright-yellow (aref ansi-bright-color-names-vector 3))
-
-(defvar test-strings
-  `(("\e[33mHello World\e[0m" "Hello World"
-     (foreground-color . ,yellow))
-    ("\e[43mHello World\e[0m" "Hello World"
-     (background-color . ,yellow))
-    ("\e[93mHello World\e[0m" "Hello World"
-     (foreground-color . ,bright-yellow))
-    ("\e[103mHello World\e[0m" "Hello World"
-     (background-color . ,bright-yellow))
-    ("\e[1;33mHello World\e[0m" "Hello World"
-     (bold (foreground-color . ,yellow))
-     (bold (foreground-color . ,bright-yellow)))
-    ("\e[33;1mHello World\e[0m" "Hello World"
-     (bold (foreground-color . ,yellow))
-     (bold (foreground-color . ,bright-yellow)))
-    ("\e[1m\e[33mHello World\e[0m" "Hello World"
-     (bold (foreground-color . ,yellow))
-     (bold (foreground-color . ,bright-yellow)))
-    ("\e[33m\e[1mHello World\e[0m" "Hello World"
-     (bold (foreground-color . ,yellow))
-     (bold (foreground-color . ,bright-yellow)))
-    ("\e[1m\e[3m\e[5mbold italics blink\e[0m" "bold italics blink"
-     (bold italic success))))
+(defvar test-strings '(("\e[33mHello World\e[0m" . "Hello World")
+                       ("\e[1m\e[3m\e[5mbold italics blink\e[0m" . "bold 
italics blink")))
 
 (ert-deftest ansi-color-apply-on-region-test ()
-  (pcase-dolist (`(,input ,text ,face) test-strings)
-    (with-temp-buffer
-      (insert input)
-      (ansi-color-apply-on-region (point-min) (point-max))
-      (should (equal (buffer-string) text))
-      (should (equal (get-char-property (point-min) 'face) face))
-      (should (not (equal (overlays-at (point-min)) nil))))))
-
-(ert-deftest ansi-color-apply-on-region-bold-is-bright-test ()
-  (pcase-dolist (`(,input ,text ,face ,bright-face) test-strings)
-    (with-temp-buffer
-      (let ((ansi-color-bold-is-bright t))
-        (insert input)
+    (dolist (pair test-strings)
+      (with-temp-buffer
+        (insert (car pair))
         (ansi-color-apply-on-region (point-min) (point-max))
-        (should (equal (buffer-string) text))
-        (should (equal (get-char-property (point-min) 'face)
-                       (or bright-face face)))
-        (should (not (equal (overlays-at (point-min)) nil)))))))
+        (should (equal (buffer-string) (cdr pair)))
+        (should (not (equal (overlays-at (point-min)) nil))))))
 
 (ert-deftest ansi-color-apply-on-region-preserving-test ()
     (dolist (pair test-strings)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]