[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 3d609375f99: Track nil colors in term
From: |
Daniel Colascione |
Subject: |
master 3d609375f99: Track nil colors in term |
Date: |
Thu, 3 Oct 2024 00:40:18 -0400 (EDT) |
branch: master
commit 3d609375f99cd0d4b7a441802d4616bad385e31d
Author: Daniel Colascione <dancol@dancol.org>
Commit: Daniel Colascione <dancol@dancol.org>
Track nil colors in term
Teach term the difference between an unset foreground or
background color and a color that happens to match an existing
color. This way, when we insert text after a color
reset:(e.g. from an SGR0), we insert it without :foreground or
:background (whichever we've reset) face properties, allowing
that inserted text to inherit the colors of the underlying face.
This way, if we change, e.g., the background color of a buffer,
the background color of already-inserted text from the term
child changes along with that of the buffer instead of being
"locked" to whatever the background color of the buffer was at
the time the text was inserted.
This change aligns term.el with other terminal emulators.
* lisp/term.el (term-ansi-current-color):
(term--color-as-hex): track nil fg, bg colors
---
lisp/term.el | 44 +++++++++++++++++++++++---------------------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/lisp/term.el b/lisp/term.el
index 9a8dc25e1a2..7b9886e720a 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -732,9 +732,9 @@ Buffer local variable.")
(defvar term-ansi-current-underline nil)
(defvar term-ansi-current-slow-blink nil)
(defvar term-ansi-current-fast-blink nil)
-(defvar term-ansi-current-color 0)
+(defvar term-ansi-current-color nil)
(defvar term-ansi-face-already-done nil)
-(defvar term-ansi-current-bg-color 0)
+(defvar term-ansi-current-bg-color nil)
(defvar term-ansi-current-reverse nil)
(defvar term-ansi-current-invisible nil)
@@ -1084,9 +1084,9 @@ For custom keybindings purposes please note there is also
(setq term-ansi-current-slow-blink nil)
(setq term-ansi-current-fast-blink nil)
(setq term-ansi-current-reverse nil)
- (setq term-ansi-current-color 0)
+ (setq term-ansi-current-color nil)
(setq term-ansi-current-invisible nil)
- (setq term-ansi-current-bg-color 0))
+ (setq term-ansi-current-bg-color nil))
(defvar touch-screen-display-keyboard)
@@ -3430,19 +3430,21 @@ option is enabled. See `term-set-goto-process-mark'."
(defun term--color-as-hex (for-foreground)
"Return the current ANSI color as a hexadecimal color string.
Use the current background color if FOR-FOREGROUND is nil,
-otherwise use the current foreground color."
+otherwise use the current foreground color. Return nil if the
+color is unset in the terminal state."
(let ((color (if for-foreground term-ansi-current-color
term-ansi-current-bg-color)))
- (or (ansi-color--code-as-hex (1- color))
- (progn
- (and ansi-color-bold-is-bright term-ansi-current-bold
- (<= 1 color 8)
- (setq color (+ color 8)))
- (if for-foreground
- (face-foreground (elt ansi-term-color-vector color)
- nil 'default)
- (face-background (elt ansi-term-color-vector color)
- nil 'default))))))
+ (when color
+ (or (ansi-color--code-as-hex (1- color))
+ (progn
+ (and ansi-color-bold-is-bright term-ansi-current-bold
+ (<= 1 color 8)
+ (setq color (+ color 8)))
+ (if for-foreground
+ (face-foreground (elt ansi-term-color-vector color)
+ nil 'default)
+ (face-background (elt ansi-term-color-vector color)
+ nil 'default)))))))
;; New function to deal with ansi colorized output, as you can see you can
;; have any bold/underline/fg/bg/reverse combination. -mm
@@ -3499,7 +3501,7 @@ otherwise use the current foreground color."
(_ (term-ansi-reset))))
;; Reset foreground (terminfo: op)
- (39 (setq term-ansi-current-color 0))
+ (39 (setq term-ansi-current-color nil))
;; Background (terminfo: setab)
((and param (guard (<= 40 param 47)))
@@ -3529,7 +3531,7 @@ otherwise use the current foreground color."
(_ (term-ansi-reset))))
;; Reset background (terminfo: op)
- (49 (setq term-ansi-current-bg-color 0))
+ (49 (setq term-ansi-current-bg-color nil))
;; 0 (Reset) (terminfo: sgr0) or unknown (reset anyway)
(_ (term-ansi-reset))))
@@ -3541,10 +3543,10 @@ otherwise use the current foreground color."
(setq fg (term--color-as-hex t)
bg (term--color-as-hex nil)))
(setq term-current-face
- `( :foreground ,fg
- :background ,bg
- ,@(unless term-ansi-current-invisible
- (list :inverse-video term-ansi-current-reverse)))))
+ `(,@(when fg `(:foreground ,fg))
+ ,@(when bg `(:background ,bg))
+ ,@(unless term-ansi-current-invisible
+ (list :inverse-video term-ansi-current-reverse)))))
(setq term-current-face
`(,term-current-face
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 3d609375f99: Track nil colors in term,
Daniel Colascione <=