From unknown Thu Aug 14 21:50:55 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73560: [PATCH] fix term color reset handling Resent-From: Daniel Colascione Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Sep 2024 03:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73560 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 73560@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.172766702530070 (code B ref -1); Mon, 30 Sep 2024 03:31:02 +0000 Received: (at submit) by debbugs.gnu.org; 30 Sep 2024 03:30:25 +0000 Received: from localhost ([127.0.0.1]:43977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sv779-0007ou-3l for submit@debbugs.gnu.org; Sun, 29 Sep 2024 23:30:25 -0400 Received: from lists.gnu.org ([209.51.188.17]:39614) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sv75y-0007a7-4O for submit@debbugs.gnu.org; Sun, 29 Sep 2024 23:29:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sv75R-0004zb-Kk for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2024 23:28:37 -0400 Received: from dancol.org ([2600:3c01:e000:3d8::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sv75Q-0004nM-2d for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2024 23:28:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dancol.org; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/BOz30BPInafiSfSXSVgOfywod1/gqPg4RDuOZ5JBhE=; b=XLsoGcrcn9210ET5Wu1JWseKzK FCphkhpaje+V7eSBj80jfH/IbVsbb8zQk/X0bB2dSUTudI93m0hAYtC7YUtXr1BA6ZT2cVtQCggSq /WKZXBgKb7UkoiMTWxgM4P+2bxtmALZV3aGc9pSmp+AAqCaoEnH08nDtqffoVW5+6g3hU2ROQ8IBp Vba/PlOcKkHSfcEaPm9YLaDeACMM65veg2dbIiubFZq6j6aIXKHfqD2qAi9j093fJQ9Y0TAcs074M XHDxeMlAn2M54zaK48LayRfCqNvFPdDYxQc5gf/KMcY8k0mSBa58Ya3/5SrtV9ZZ7h0qnXg506JMF bTyFcUBA==; Received: from [2600:3c01:e000:3d8:1::1001] (port=50664 helo=localhost) by dancol.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sv6Pi-0000zR-23 for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2024 22:45:33 -0400 From: Daniel Colascione User-Agent: mu4e 1.12.6; emacs 31.0.50 Date: Sun, 29 Sep 2024 22:45:22 -0400 Message-ID: <875xqd3lml.fsf@dancol.org> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2600:3c01:e000:3d8::1; envelope-from=dancol@dancol.org; helo=dancol.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) 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 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 From unknown Thu Aug 14 21:50:55 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Daniel Colascione Subject: bug#73560: closed (Re: bug#73560: [PATCH] fix term color reset handling) Message-ID: References: <86h69qx2am.fsf@gnu.org> <875xqd3lml.fsf@dancol.org> X-Gnu-PR-Message: they-closed 73560 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 73560@debbugs.gnu.org Date: Sat, 05 Oct 2024 10:39:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1728124742-25371-1" This is a multi-part message in MIME format... ------------=_1728124742-25371-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #73560: [PATCH] fix term color reset handling=20 which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 73560@debbugs.gnu.org. --=20 73560: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D73560 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1728124742-25371-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 73560-done) by debbugs.gnu.org; 5 Oct 2024 10:38:40 +0000 Received: from localhost ([127.0.0.1]:37358 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sx2BL-0006ab-Ut for submit@debbugs.gnu.org; Sat, 05 Oct 2024 06:38:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sx2BJ-0006aM-5K for 73560-done@debbugs.gnu.org; Sat, 05 Oct 2024 06:38:37 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sx2B9-0003vg-FL; Sat, 05 Oct 2024 06:38:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=giSFF/1ZFXeoyP3gG/lS3hHKJs1P3SOtXgiFge0b5nU=; b=A/csnyoJiDhJ 16+f9YZPSgurJ6XTsaMNm+FUzolJ0HO+hxEWZMQwFg6A0IcnjaLhLJ7l+Wil7oP8pqaxBQavqiaQO ODIiWmxFLVjl+mxlhP1cTUe2+f1ERHA/E8uYxZwSFCn7BzbZgd4Iu3EssJqSUylxECtzC+lPsOgEV qm9MMjsXaxgUWoO01cbioQY3waPP9MaxJPom+PbTjODhdgtIWDQrWO2Nc0I6lBeaCvbGsZD8eiPud 5D6bKEOlbL6pK5bJhQpbRgk06TcR3Iv36sSt1440Wn04puZcxCE6p/aL1978786RwvdZtmghFEy0k 6r1EIfyqk0afYnD2LOBWhQ==; Date: Sat, 05 Oct 2024 13:38:25 +0300 Message-Id: <86h69qx2am.fsf@gnu.org> From: Eli Zaretskii To: Daniel Colascione In-Reply-To: <875xqd3lml.fsf@dancol.org> (message from Daniel Colascione on Sun, 29 Sep 2024 22:45:22 -0400) Subject: Re: bug#73560: [PATCH] fix term color reset handling References: <875xqd3lml.fsf@dancol.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73560-done Cc: 73560-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Daniel Colascione > 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. ------------=_1728124742-25371-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 30 Sep 2024 03:30:25 +0000 Received: from localhost ([127.0.0.1]:43977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sv779-0007ou-3l for submit@debbugs.gnu.org; Sun, 29 Sep 2024 23:30:25 -0400 Received: from lists.gnu.org ([209.51.188.17]:39614) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sv75y-0007a7-4O for submit@debbugs.gnu.org; Sun, 29 Sep 2024 23:29:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sv75R-0004zb-Kk for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2024 23:28:37 -0400 Received: from dancol.org ([2600:3c01:e000:3d8::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sv75Q-0004nM-2d for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2024 23:28:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dancol.org; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/BOz30BPInafiSfSXSVgOfywod1/gqPg4RDuOZ5JBhE=; b=XLsoGcrcn9210ET5Wu1JWseKzK FCphkhpaje+V7eSBj80jfH/IbVsbb8zQk/X0bB2dSUTudI93m0hAYtC7YUtXr1BA6ZT2cVtQCggSq /WKZXBgKb7UkoiMTWxgM4P+2bxtmALZV3aGc9pSmp+AAqCaoEnH08nDtqffoVW5+6g3hU2ROQ8IBp Vba/PlOcKkHSfcEaPm9YLaDeACMM65veg2dbIiubFZq6j6aIXKHfqD2qAi9j093fJQ9Y0TAcs074M XHDxeMlAn2M54zaK48LayRfCqNvFPdDYxQc5gf/KMcY8k0mSBa58Ya3/5SrtV9ZZ7h0qnXg506JMF bTyFcUBA==; Received: from [2600:3c01:e000:3d8:1::1001] (port=50664 helo=localhost) by dancol.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sv6Pi-0000zR-23 for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2024 22:45:33 -0400 From: Daniel Colascione To: bug-gnu-emacs@gnu.org Subject: [PATCH] fix term color reset handling User-Agent: mu4e 1.12.6; emacs 31.0.50 Date: Sun, 29 Sep 2024 22:45:22 -0400 Message-ID: <875xqd3lml.fsf@dancol.org> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2600:3c01:e000:3d8::1; envelope-from=dancol@dancol.org; helo=dancol.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) 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 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 ------------=_1728124742-25371-1--