summaryrefslogtreecommitdiff
path: root/test/lisp/term-tests.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2021-09-22 18:39:52 -0700
committerLars Ingebrigtsen <larsi@gnus.org>2021-09-23 22:57:53 +0200
commitd4a6e42e92ee215659d09b0456032714aab73ca5 (patch)
treec4f17cd9bc0d3afe1d6ab7e027aa75495edfbb1f /test/lisp/term-tests.el
parentceb9da3b7125fbdf0da04a3b158ac1e792c87f4f (diff)
downloademacs-d4a6e42e92ee215659d09b0456032714aab73ca5.tar.gz
Add support for "bright" ANSI colors in term-mode
* list/term.el (ansi-term-color-vector): Add new faces. (term-color-black, term-color-red, term-color-green, term-color-yellow) (term-color-blue, term-color-magenta, term-color-cyan, term-color-white): Inherit from 'ansi-color-COLOR'. (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.
Diffstat (limited to 'test/lisp/term-tests.el')
-rw-r--r--test/lisp/term-tests.el65
1 files changed, 64 insertions, 1 deletions
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 50ac370b5b5..96b6d734882 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -28,6 +28,51 @@
(defvar term-height) ; Number of lines in window.
(defvar term-width) ; Number of columns in window.
+(defvar yellow-fg-props
+ `( :foreground ,(face-foreground 'term-color-yellow nil 'default)
+ :background "unspecified-bg" :inverse-video nil))
+(defvar yellow-bg-props
+ `( :foreground "unspecified-fg"
+ :background ,(face-background 'term-color-yellow nil 'default)
+ :inverse-video nil))
+(defvar bright-yellow-fg-props
+ `( :foreground ,(face-foreground 'term-color-bright-yellow nil 'default)
+ :background "unspecified-bg" :inverse-video nil))
+(defvar bright-yellow-bg-props
+ `( :foreground "unspecified-fg"
+ :background ,(face-background 'term-color-bright-yellow nil 'default)
+ :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 +93,7 @@
(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 +122,24 @@ first line\r_next line\r\n"))
(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 ((ansi-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.