unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#73560: [PATCH] fix term color reset handling
@ 2024-09-30  2:45 Daniel Colascione
  2024-10-05 10:38 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Colascione @ 2024-09-30  2:45 UTC (permalink / raw)
  To: 73560


term responds to SGR0 by resetting term-current-face face to the
foreground and background of the current face instead of omitting these
attributes entirely.  Consequently, text inserted by term becomes
"opinionated" about what the foreground and background colors are and if
the default face changes, already-inserted-by-term text doesn't change
to match, since it has hardcoded hex color face text properties.

The patch below makes term behave more like other terminal emulators and
distinguish the absence of a foreground or background color from
specifying some specific foreground or background color.



commit 49de0c38598bf00db84029dbef8a94dcf6a27b21
Author: Daniel Colascione <dancol@dancol.org>
Date:   Sun Sep 29 17:18:28 2024 -0400

    Track current terminal colors better

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 @@ term-ansi-current-italic
 (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 @@ term-ansi-reset
   (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 @@ term-reset-terminal
 (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 @@ term--handle-colors-list
          (_ (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 @@ term--handle-colors-list
          (_ (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 @@ term--handle-colors-list
       (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





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

* bug#73560: [PATCH] fix term color reset handling
  2024-09-30  2:45 bug#73560: [PATCH] fix term color reset handling Daniel Colascione
@ 2024-10-05 10:38 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2024-10-05 10:38 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 73560-done

> From: Daniel Colascione <dancol@dancol.org>
> Date: Sun, 29 Sep 2024 22:45:22 -0400
> 
> 
> term responds to SGR0 by resetting term-current-face face to the
> foreground and background of the current face instead of omitting these
> attributes entirely.  Consequently, text inserted by term becomes
> "opinionated" about what the foreground and background colors are and if
> the default face changes, already-inserted-by-term text doesn't change
> to match, since it has hardcoded hex color face text properties.
> 
> The patch below makes term behave more like other terminal emulators and
> distinguish the absence of a foreground or background color from
> specifying some specific foreground or background color.

Since this patch was installed on the master branhc, I'm now closing
this bug.

Thanks.





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

end of thread, other threads:[~2024-10-05 10:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30  2:45 bug#73560: [PATCH] fix term color reset handling Daniel Colascione
2024-10-05 10:38 ` Eli Zaretskii

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).