all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#50179: [PATCH] Add support for "bright" ANSI colors to ansi-color and term-mode
@ 2021-08-24  4:02 Jim Porter
  2021-08-24 12:07 ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Jim Porter @ 2021-08-24  4:02 UTC (permalink / raw)
  To: 50179

[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]

Note: My copyright assignment paperwork is out of date, but I've
already sent a message to assign@ to get it updated. Thus, these
patches won't be able to merge right away. However, I wanted to start
the review process now so that there's plenty of time for
back-and-forth before Emacs 28.1 is released.

With the administrative issues out of the way... these patches provide
support for "bright" ANSI colors (SGR 90-97 and 100-107 for foreground
and background, respectively)[1]. Most of the complexity here is due
to the new defcustoms `*-bold-is-bright'. Enabling this results in
ANSI "bold" text (SGR 1) to be rendered in the bright color palette
(as well as being bold). This is a pretty common option in terminal
emulators; all the ones I looked at[2] support it, and it's often the
default behavior. For me, the main benefit of this option is so I can
easily match the color palettes between Emacs and my terminal
emulator.

I've split this into two patches, one for 'ansi-color' and one for
'term-mode'. Despite the similarity in functionality, the
implementations are pretty different. It might be nice if they could
be unified somehow, but that may be more trouble than it's worth...

- Jim

[1] https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
[2] gnome-terminal, alacritty, and PuTTY

[-- Attachment #2: 0001-Add-support-for-bright-ANSI-colors-in-ansi-color.patch --]
[-- Type: application/octet-stream, Size: 11382 bytes --]

From 7bdaf244ec1aba9cabaeb8be3cbff7c5b798f4e8 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Mon, 23 Aug 2021 17:51:05 -0700
Subject: [PATCH 1/2] Add support for "bright" ANSI colors in ansi-color

* lisp/ansi-color.el (ansi-bright-color-names-vector): New defcustom.
(ansi-color-bold-is-bright): New defcustom.
(ansi-color--find-face): Sort ANSI codes and check
'ansi-color-bold-is-bright'.
(ansi-color-apply-sequence): Support bright ANSI colors.
(ansi-color--fill-color-map): New function.
(ansi-color-make-color-map): Add bright ANSI colors.
(ansi-color-get-face-1): Add BRIGHT parameter.
* test/lisp/ansi-color-tests.el
(ansi-color-apply-on-region-bold-is-bright-test): New function.
---
 etc/NEWS                      |   7 ++
 lisp/ansi-color.el            | 116 ++++++++++++++++++++++++++--------
 test/lisp/ansi-color-tests.el |  51 +++++++++++++--
 3 files changed, 140 insertions(+), 34 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b221f13624..b8e77bee68 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -375,6 +375,13 @@ 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.
+
 \f
 * Editing Changes in Emacs 28.1
 
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index 79dc821ea1..23749304a0 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -150,6 +150,48 @@ ansi-color-names-vector
   :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]"
@@ -304,9 +346,14 @@ ansi-color-filter-apply
 
 (defun ansi-color--find-face (codes)
   "Return the face corresponding to CODES."
-  (let (faces)
+  ;; Sort the codes in ascending order to can 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) #'<)))
     (while codes
-      (let ((face (ansi-color-get-face-1 (pop codes))))
+      (let ((face (ansi-color-get-face-1 (pop codes) bright)))
+        (when (and ansi-color-bold-is-bright (eq face 'bold))
+          (setq bright t))
 	;; In the (default underline) face, say, the value of the
 	;; "underline" attribute of the `default' face wins.
 	(unless (eq face 'default)
@@ -570,11 +617,11 @@ ansi-color-apply-sequence
 
 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 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."
+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."
   (let ((new-codes (ansi-color-parse-sequence escape-sequence)))
     (while new-codes
       (let* ((new (pop new-codes))
@@ -591,7 +638,7 @@ ansi-color-apply-sequence
 					(22 (remq 1 codes))
 					(25 (remq 6 codes))
 					(_ codes)))))
-		((or 3 4) (let ((r (mod new 10)))
+		((or 3 4 9 10) (let ((r (mod new 10)))
 			    (unless (= r 8)
 			      (let (beg)
 				(while (and codes (/= q (/ (car codes) 10)))
@@ -603,6 +650,19 @@ ansi-color-apply-sequence
 		(_ 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.
 
@@ -611,7 +671,7 @@ ansi-color-make-color-map
 
 The face definitions are based upon the variables
 `ansi-color-faces-vector' and `ansi-color-names-vector'."
-  (let ((map (make-vector 50 nil))
+  (let ((map (make-vector 110 nil))
         (index 0))
     ;; miscellaneous attributes
     (mapc
@@ -620,23 +680,21 @@ ansi-color-make-color-map
        (setq index (1+ index)) )
      ansi-color-faces-vector)
     ;; foreground attributes
-    (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)
+    (ansi-color--fill-color-map
+     map 30 'foreground ansi-color-names-vector
+     (lambda (e) (if (consp e) (car e) e)))
     ;; background attributes
-    (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)
+    (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)))
     map))
 
 (defvar ansi-color-map (ansi-color-make-color-map)
@@ -660,9 +718,13 @@ ansi-color-map-update
   (set-default symbol value)
   (setq ansi-color-map (ansi-color-make-color-map)))
 
-(defun ansi-color-get-face-1 (ansi-code)
+(defun ansi-color-get-face-1 (ansi-code &optional bright)
   "Get face definition from `ansi-color-map'.
-ANSI-CODE is used as an index into the vector."
+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)))
   (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 107dc8e400..c94561bda1 100644
--- a/test/lisp/ansi-color-tests.el
+++ b/test/lisp/ansi-color-tests.el
@@ -25,17 +25,54 @@
 ;;; Code:
 
 (require 'ansi-color)
+(eval-when-compile (require 'cl-lib))
 
-(defvar test-strings '(("\e[33mHello World\e[0m" . "Hello World")
-                       ("\e[1m\e[3m\e[5mbold italics blink\e[0m" . "bold italics blink")))
+(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))))
 
 (ert-deftest ansi-color-apply-on-region-test ()
-    (dolist (pair test-strings)
-      (with-temp-buffer
-        (insert (car pair))
+  (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)
         (ansi-color-apply-on-region (point-min) (point-max))
-        (should (equal (buffer-string) (cdr pair)))
-        (should (not (equal (overlays-at (point-min)) nil))))))
+        (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)))))))
 
 (ert-deftest ansi-color-apply-on-region-preserving-test ()
     (dolist (pair test-strings)
-- 
2.25.1


[-- Attachment #3: 0002-Add-support-for-bright-ANSI-colors-in-term-mode.patch --]
[-- Type: application/octet-stream, Size: 12430 bytes --]

From 68098c8f5ff27f30f835953214fb177cda0a7a5e Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Mon, 23 Aug 2021 20:12:10 -0700
Subject: [PATCH 2/2] Add support for "bright" ANSI colors in term-mode

* list/term.el (ansi-term-color-vector): Add new faces.
(term-color-white): Tweak colors.
(term-color-bright-*): New faces.
(term-color-bold-is-bright): New defcustom.
(term--maybe-brighten-color): New function.
(term-handle-colors-array): Handle bright colors.
* test/lisp/term-tests.el (term-colors, term-colors-bold-is-bright):
New functions.
---
 etc/NEWS                |   7 ++
 lisp/term.el            | 140 +++++++++++++++++++++++++++++++---------
 test/lisp/term-tests.el |  59 ++++++++++++++++-
 3 files changed, 174 insertions(+), 32 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b8e77bee68..ddc73d01af 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2367,6 +2367,13 @@ based on the current window size.  In previous versions of Emacs, this
 was always done (and that could lead to odd displays when resizing the
 window after starting).  This variable defaults to nil.
 
+---
+*** 'term-mode' now supports "bright" color codes.
+"Bright" ANSI color codes are now displayed using the color values
+defined in 'term-color-bright-*'.  In addition, bold text with regular
+ANSI colors can be displayed as "bright" if 'term-color-bold-is-bright'
+is non-nil.
+
 ** Widget
 
 +++
diff --git a/lisp/term.el b/lisp/term.el
index b3870a814d..398b61b630 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -727,7 +727,15 @@ ansi-term-color-vector
    term-color-blue
    term-color-magenta
    term-color-cyan
-   term-color-white])
+   term-color-white
+   term-color-bright-black
+   term-color-bright-red
+   term-color-bright-green
+   term-color-bright-yellow
+   term-color-bright-blue
+   term-color-bright-magenta
+   term-color-bright-cyan
+   term-color-bright-white])
 
 (defcustom term-default-fg-color nil
   "If non-nil, default color for foreground in Term mode."
@@ -797,10 +805,57 @@ term-color-cyan
   :group 'term)
 
 (defface term-color-white
-  '((t :foreground "white" :background "white"))
+  '((t :foreground "grey90" :background "gray90"))
   "Face used to render white color code."
   :group 'term)
 
+(defface term-color-bright-black
+  '((t :foreground "gray30" :background "gray30"))
+  "Face used to render bright black color code."
+  :group 'term)
+
+(defface term-color-bright-red
+  '((t :foreground "red2" :background "red2"))
+  "Face used to render bright red color code."
+  :group 'term)
+
+(defface term-color-bright-green
+  '((t :foreground "green2" :background "green2"))
+  "Face used to render bright green color code."
+  :group 'term)
+
+(defface term-color-bright-yellow
+  '((t :foreground "yellow2" :background "yellow2"))
+  "Face used to render bright yellow color code."
+  :group 'term)
+
+(defface term-color-bright-blue
+  '((t :foreground "blue1" :background "blue1"))
+  "Face used to render bright blue color code."
+  :group 'term)
+
+(defface term-color-bright-magenta
+  '((t :foreground "magenta2" :background "magenta2"))
+  "Face used to render bright magenta color code."
+  :group 'term)
+
+(defface term-color-bright-cyan
+  '((t :foreground "cyan2" :background "cyan2"))
+  "Face used to render bright cyan color code."
+  :group 'term)
+
+(defface term-color-bright-white
+  '((t :foreground "white" :background "white"))
+  "Face used to render bright white color code."
+  :group 'term)
+
+(defcustom term-color-bold-is-bright nil
+  "If set to non-nil, combining ANSI bold and a color produces the bright
+version of that color."
+  :group 'term
+  :type 'boolean
+  :version "28.1")
+
 (defcustom term-buffer-maximum-size 8192
   "The maximum size in lines for term buffers.
 Term buffers are truncated from the top to be no greater than this number.
@@ -3225,6 +3280,15 @@ term-reset-terminal
   ;; FIXME: No idea why this is here, it looks wrong.  --Stef
   (setq term-ansi-face-already-done nil))
 
+(defun term--maybe-brighten-color (color bold)
+  "Possibly convert COLOR to its bright variant.
+COLOR is an index into `ansi-term-color-vector'.  If BOLD and
+`term-color-bold-is-bright' are non-nil and COLOR is a regular color,
+return the bright version of COLOR; otherwise, return COLOR."
+  (if (and term-color-bold-is-bright bold (<= 1 color 8))
+      (+ color 8)
+    color))
+
 ;; New function to deal with ansi colorized output, as you can see you can
 ;; have any bold/underline/fg/bg/reverse combination. -mm
 
@@ -3264,6 +3328,10 @@ term-handle-colors-array
    ((and (>= parameter 30) (<= parameter 37))
     (setq term-ansi-current-color (- parameter 29)))
 
+   ;; Bright foreground
+   ((and (>= parameter 90) (<= parameter 97))
+    (setq term-ansi-current-color (- parameter 81)))
+
    ;; Reset foreground
    ((eq parameter 39)
     (setq term-ansi-current-color 0))
@@ -3272,6 +3340,10 @@ term-handle-colors-array
    ((and (>= parameter 40) (<= parameter 47))
     (setq term-ansi-current-bg-color (- parameter 39)))
 
+   ;; Bright foreground
+   ((and (>= parameter 100) (<= parameter 107))
+    (setq term-ansi-current-bg-color (- parameter 91)))
+
    ;; Reset background
    ((eq parameter 49)
     (setq term-ansi-current-bg-color 0))
@@ -3290,37 +3362,43 @@ term-handle-colors-array
   ;;          term-ansi-current-bg-color)
 
   (unless term-ansi-face-already-done
-    (if term-ansi-current-invisible
-        (let ((color
-               (if term-ansi-current-reverse
-                   (face-foreground
-                    (elt ansi-term-color-vector term-ansi-current-color)
-                    nil 'default)
-                 (face-background
-                  (elt ansi-term-color-vector term-ansi-current-bg-color)
-                  nil 'default))))
-          (setq term-current-face
-                (list :background color
-                      :foreground color))
-          ) ;; No need to bother with anything else if it's invisible.
-      (setq term-current-face
-            (list :foreground
-                  (face-foreground
-                   (elt ansi-term-color-vector term-ansi-current-color)
-                   nil 'default)
-                  :background
-                  (face-background
-                   (elt ansi-term-color-vector term-ansi-current-bg-color)
-                   nil 'default)
-                  :inverse-video term-ansi-current-reverse))
-
-      (when term-ansi-current-bold
+    (let ((current-color (term--maybe-brighten-color
+                          term-ansi-current-color
+                          term-ansi-current-bold))
+          (current-bg-color (term--maybe-brighten-color
+                             term-ansi-current-bg-color
+                             term-ansi-current-bold)))
+      (if term-ansi-current-invisible
+          (let ((color
+                 (if term-ansi-current-reverse
+                     (face-foreground
+                      (elt ansi-term-color-vector current-color)
+                      nil 'default)
+                   (face-background
+                    (elt ansi-term-color-vector current-bg-color)
+                    nil 'default))))
+            (setq term-current-face
+                  (list :background color
+                        :foreground color))
+            ) ;; No need to bother with anything else if it's invisible.
         (setq term-current-face
-              `(,term-current-face :inherit term-bold)))
+              (list :foreground
+                    (face-foreground
+                     (elt ansi-term-color-vector current-color)
+                     nil 'default)
+                    :background
+                    (face-background
+                     (elt ansi-term-color-vector current-bg-color)
+                     nil 'default)
+                    :inverse-video term-ansi-current-reverse))
+
+        (when term-ansi-current-bold
+          (setq term-current-face
+                `(,term-current-face :inherit term-bold)))
 
-      (when term-ansi-current-underline
-        (setq term-current-face
-              `(,term-current-face :inherit term-underline)))))
+        (when term-ansi-current-underline
+          (setq term-current-face
+                `(,term-current-face :inherit term-underline))))))
 
   ;;	(message "Debug %S" term-current-face)
   ;; FIXME: shouldn't we set term-ansi-face-already-done to t here?  --Stef
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 50ac370b5b..a61d0939ea 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -28,6 +28,45 @@
 (defvar term-height)                    ; Number of lines in window.
 (defvar term-width)                     ; Number of columns in window.
 
+(defvar yellow-fg-props
+  '(:foreground "yellow3" :background "unspecified-bg" :inverse-video nil))
+(defvar yellow-bg-props
+  '(:foreground "unspecified-fg" :background "yellow3" :inverse-video nil))
+(defvar bright-yellow-fg-props
+  '(:foreground "yellow2" :background "unspecified-bg" :inverse-video nil))
+(defvar bright-yellow-bg-props
+  '(:foreground "unspecified-fg" :background "yellow2" :inverse-video nil))
+
+(defvar ansi-test-strings
+  `(("\e[33mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face yellow-fg-props))
+    ("\e[43mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face yellow-bg-props))
+    ("\e[93mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face bright-yellow-fg-props))
+    ("\e[103mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face bright-yellow-bg-props))
+    ("\e[1;33mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,yellow-fg-props :inherit term-bold))
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,bright-yellow-fg-props :inherit term-bold)))
+    ("\e[33;1mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,yellow-fg-props :inherit term-bold))
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,bright-yellow-fg-props :inherit term-bold)))
+    ("\e[1m\e[33mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,yellow-fg-props :inherit term-bold))
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,bright-yellow-fg-props :inherit term-bold)))
+    ("\e[33m\e[1mHello World\e[0m"
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,yellow-fg-props :inherit term-bold))
+     ,(propertize "Hello World" 'font-lock-face
+                  `(,bright-yellow-fg-props :inherit term-bold)))))
+
 (defun term-test-screen-from-input (width height input &optional return-var)
   (with-temp-buffer
     (term-mode)
@@ -48,7 +87,7 @@ term-test-screen-from-input
                 (mapc (lambda (input) (term-emulate-terminal proc input)) input)
               (term-emulate-terminal proc input))
       (if return-var (buffer-local-value return-var (current-buffer))
-        (buffer-substring-no-properties (point-min) (point-max))))))
+        (buffer-substring (point-min) (point-max))))))
 
 (ert-deftest term-simple-lines ()
   (skip-unless (not (memq system-type '(windows-nt ms-dos))))
@@ -77,6 +116,24 @@ term-line-wrap
            (term-test-screen-from-input 40 12 (let ((str (make-string 30 ?a)))
                                                 (list str str))))))
 
+(ert-deftest term-colors ()
+  (skip-unless (not (memq system-type '(windows-nt ms-dos))))
+  (pcase-dolist (`(,str ,expected) ansi-test-strings)
+    (let ((result (term-test-screen-from-input 40 12 str)))
+      (should (equal result expected))
+      (should (equal (text-properties-at 0 result)
+                     (text-properties-at 0 expected))))))
+
+(ert-deftest term-colors-bold-is-bright ()
+  (skip-unless (not (memq system-type '(windows-nt ms-dos))))
+  (let ((term-color-bold-is-bright t))
+    (pcase-dolist (`(,str ,expected ,bright-expected) ansi-test-strings)
+      (let ((expected (or bright-expected expected))
+            (result (term-test-screen-from-input 40 12 str)))
+        (should (equal result expected))
+        (should (equal (text-properties-at 0 result)
+                       (text-properties-at 0 expected)))))))
+
 (ert-deftest term-cursor-movement ()
   (skip-unless (not (memq system-type '(windows-nt ms-dos))))
   ;; Absolute positioning.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-09-23 21:21 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-24  4:02 bug#50179: [PATCH] Add support for "bright" ANSI colors to ansi-color and term-mode Jim Porter
2021-08-24 12:07 ` Eli Zaretskii
2021-08-24 17:38   ` Jim Porter
2021-08-24 17:59     ` Eli Zaretskii
2021-08-24 18:59       ` Jim Porter
2021-08-24 22:53         ` Jim Porter
2021-08-25 12:04           ` Lars Ingebrigtsen
2021-08-25 16:41             ` Jim Porter
2021-08-25 16:46               ` Lars Ingebrigtsen
2021-08-25 16:54                 ` Eli Zaretskii
2021-08-26 13:23                   ` Lars Ingebrigtsen
2021-09-18 18:58                     ` bug#50179: [UPDATED PATCH] " Jim Porter
2021-09-19 14:45                       ` Lars Ingebrigtsen
2021-09-22 19:39                         ` bug#50179: [WIP PATCH v3] " Jim Porter
2021-09-22 19:49                           ` Lars Ingebrigtsen
2021-09-23  1:47                             ` bug#50179: [PATCH v4] " Jim Porter
2021-09-23 20:58                               ` Lars Ingebrigtsen
2021-09-23 21:21                                 ` Jim Porter
2021-08-25  7:06       ` bug#50179: [PATCH] " Kévin Le Gouguec
2021-08-25 11:57         ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.