unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 50179@debbugs.gnu.org
Subject: bug#50179: [PATCH] Add support for "bright" ANSI colors to ansi-color and term-mode
Date: Tue, 24 Aug 2021 15:53:52 -0700	[thread overview]
Message-ID: <CANh=_JG5Opw5n6_t__7YBeGrEvDL2T=Q=ftizTS4motX9cNF0A@mail.gmail.com> (raw)
In-Reply-To: <CANh=_JFtvGMxxidbA5QsB8-GMwJEuV5e3p_=sTZ3OaNG5qwsEA@mail.gmail.com>

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

Ok, here are updated patches addressing your comments. I fixed the
grammatical error in the comment, improved the commit message for the
second patch, and switched to using `ansi-color-bold-is-bright' in
both files. I left `ansi-bright-color-names-vector' as a defcustom
though, since I think that's the right thing to do there (see my
previous message), but I can change that later if we agree on a
different/better route there.

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

From b924a57e06d66d1c960ee87d03fd9cdacedec1a4 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..0dc9a52388 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 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: 12371 bytes --]

From 3e1d91e34a563bb750a498d4a75433b3aac1f0e8 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Tue, 24 Aug 2021 15:46:06 -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-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): New faces.
(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            | 133 ++++++++++++++++++++++++++++++----------
 test/lisp/term-tests.el |  59 +++++++++++++++++-
 3 files changed, 167 insertions(+), 32 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b8e77bee68..e5aa055fb7 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 'ansi-color-bold-is-bright'
+is non-nil.
+
 ** Widget
 
 +++
diff --git a/lisp/term.el b/lisp/term.el
index b3870a814d..ef2532182c 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,50 @@ 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-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 +3273,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
+`ansi-color-bold-is-bright' are non-nil and COLOR is a regular color,
+return the bright version of COLOR; otherwise, return COLOR."
+  (if (and ansi-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 +3321,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 +3333,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 +3355,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


  reply	other threads:[~2021-08-24 22:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANh=_JG5Opw5n6_t__7YBeGrEvDL2T=Q=ftizTS4motX9cNF0A@mail.gmail.com' \
    --to=jporterbugs@gmail.com \
    --cc=50179@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).