From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: mohkale@kisara.moe Newsgroups: gmane.emacs.bugs Subject: bug#62994: [PATCH v4 3/3] Add support for colored underlines on tty frames Date: Sun, 11 Feb 2024 17:15:56 +0000 Message-ID: <20240211171556.597236-4-mohkale@kisara.moe> References: <20240211171556.597236-1-mohkale@kisara.moe> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22158"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Mohsin Kaleem To: 62994@debbugs.gnu.org, Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 11 18:34:16 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rZDiZ-0005Qk-ML for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Feb 2024 18:34:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZDi9-0003Hs-Ly; Sun, 11 Feb 2024 12:33:49 -0500 Original-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 1rZDi7-0003He-PA for bug-gnu-emacs@gnu.org; Sun, 11 Feb 2024 12:33:47 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZDi6-00064v-8I for bug-gnu-emacs@gnu.org; Sun, 11 Feb 2024 12:33:46 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rZDiM-0000ps-8H for bug-gnu-emacs@gnu.org; Sun, 11 Feb 2024 12:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: mohkale@kisara.moe Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Feb 2024 17:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62994 X-GNU-PR-Package: emacs Original-Received: via spool by 62994-submit@debbugs.gnu.org id=B62994.17076728093121 (code B ref 62994); Sun, 11 Feb 2024 17:34:02 +0000 Original-Received: (at 62994) by debbugs.gnu.org; 11 Feb 2024 17:33:29 +0000 Original-Received: from localhost ([127.0.0.1]:34047 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZDhp-0000oG-5E for submit@debbugs.gnu.org; Sun, 11 Feb 2024 12:33:29 -0500 Original-Received: from 119.ip-51-38-65.eu ([51.38.65.119]:38528 helo=mail.kisara.moe) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZDhn-0000o2-8q for 62994@debbugs.gnu.org; Sun, 11 Feb 2024 12:33:28 -0500 Original-Received: from mk-desktop.Home (05408574.skybroadband.com [5.64.133.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by mail.kisara.moe (Postfix) with ESMTPSA id C11E7A2799; Sun, 11 Feb 2024 18:16:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kisara.moe; s=default; t=1707671767; bh=sr36NDmg7wH9UdOIvqHPh38uCjBSPcb+sv7YnMZF6wU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tc3XRh6uYfUQzOh6ia4zBChqx3a3Yt8BSFa5ka03wCLel2Dze6Om59Np8QB5PUSCP DYSbnRBCNfGTic0GJ3lViP1yP/Mf94vTxJTL57ZDGDBSYJlr1JUWQ53hKPGrx8/qA2 k5vcy13bHG1R8hrt0aSnx58JiHr6yEx5E4hxrT79oI95HR1zs4ahhxpvqoOwAxSvEA UIAARnqGuvucpT6Xr5wNNJ9RptA9LkYr+9O3ZX8wE+bB9vqp+uAiuzncc2HrquHCr8 E8T+XwHQ/TiWSNV91sRZTfs7C2mYgTmCGXBSWeElmtn82R5f0nzQAeiHI6WrEZMQjt MEBEwy1MSjRlg== X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240211171556.597236-1-mohkale@kisara.moe> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279856 Archived-At: From: Mohsin Kaleem * src/term.c (turn_on_face, init_tty): Output escape sequence to set underline color when set in the face and supported by the tty. Save a default value for this sequence on init_tty when styled underlines are supported. * src/termchar.c (tty_display_info): Add an entry for the escape sequence to set the underline color on terminal frames. * src/xfaces.c (tty_supports_face_attributes_p, realize_tty_face): Assert whether colored underlines are supported by the current terminal on display-supports-face-attributes-p checks. Load and save the color of the underline from the face spec when realizing a face. --- etc/NEWS | 11 +++++++---- src/term.c | 11 +++++++++++ src/termchar.h | 3 +++ src/xfaces.c | 16 +++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index d868ee773fd..73a15eb44a4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -421,20 +421,23 @@ respectively, in addition to the existing translations 'C-x 8 / e' and 'C-x 8 / E'. --- -** Support for 'styled-underline' face attributes on TTY frames +** Support for 'styled' and 'colored' underline face attributes on TTY frames If your terminals termcap or terminfo database entry has the 'Su' or 'Smulx' capability defined, Emacs will now emit the prescribed escape sequence necessary to render faces with styled underlines on TTY frames. Styled underlines are any underlines containing a non-default -underline style. The available underline styles for TTY frames are -'double', 'wave', 'dotted', and 'dashed'. +underline style or a color other than the foreground-color. +The available underline styles for TTY frames are 'double', 'wave', +'dotted', and 'dashed'. The 'Smulx' capability should define the actual sequence needed to render styled underlines. If ommitted, but the 'Su' flag is defined, then a default sequence will be used. It's recommended to use 'Smulx' -instead of 'Su', with priority being given to 'Smulx'. +instead of 'Su', with priority being given to 'Smulx'. Support for +colored underlines is automatically enabled with a default escape +sequence when styled underline are supported. * Changes in Specialized Modes and Packages in Emacs 30.1 diff --git a/src/term.c b/src/term.c index 06dbb95171e..1ab6936db76 100644 --- a/src/term.c +++ b/src/term.c @@ -2050,6 +2050,14 @@ turn_on_face (struct frame *f, int face_id) OUTPUT (tty, p); xfree (p); } + + ts = tty->TF_set_underline_color; + if (ts && face->underline_color) + { + p = tparam (ts, NULL, 0, face->underline_color, 0, 0, 0); + OUTPUT (tty, p); + xfree (p); + } } } @@ -4387,6 +4395,9 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed) if (!tty->TF_set_underline_style && tgetflag("Su")) tty->TF_set_underline_style = "\x1b[4:%p1%dm"; + if (tty->TF_set_underline_style) + tty->TF_set_underline_color = "\x1b[58:2::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm"; + #else /* DOS_NT */ #ifdef WINDOWSNT { diff --git a/src/termchar.h b/src/termchar.h index 7fc1f347230..846cd3001cc 100644 --- a/src/termchar.h +++ b/src/termchar.h @@ -175,6 +175,9 @@ #define EMACS_TERMCHAR_H style based on the parameter. Param should be one of: 0 (none), 1 (straight), 2 (double), 3 (wave), 4 (dotted), or 5 (dashed). */ + const char *TF_set_underline_color; /* Enabled when TF_set_underline_style is set: + Sets the color of the underline. Accepts a + single parameter, the color index. */ int RPov; /* # chars to start a TS_repeat */ diff --git a/src/xfaces.c b/src/xfaces.c index 684e72bd897..4d860540cb9 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -5469,7 +5469,7 @@ tty_supports_face_attributes_p (struct frame *f, if (!UNSPECIFIEDP (val)) { if (STRINGP (val)) - return false; /* ttys can't use colored underlines */ + test_caps |= TTY_CAP_UNDERLINE_STYLED; else if (EQ (CAR_SAFE (val), QCstyle)) { if (!(EQ (CAR_SAFE (CDR_SAFE (val)), Qline) || @@ -6572,14 +6572,18 @@ realize_tty_face (struct face_cache *cache, underline = attrs[LFACE_UNDERLINE_INDEX]; if (NILP (underline)) { face->tty_underline = FACE_NO_UNDERLINE; + face->underline_color = 0; } else if (EQ (underline, Qt)) { face->tty_underline = FACE_UNDER_LINE; + face->underline_color = 0; } else if (STRINGP (underline)) { face->tty_underline = FACE_UNDER_LINE; + face->underline_color = load_color (f, face, underline, LFACE_UNDERLINE_INDEX); } else if (CONSP (underline)) { - /* `(:style STYLE)'. + /* `(:color COLOR :style STYLE)'. STYLE being one of `line', `double', `wave', `dotted' or `dashed'. */ face->tty_underline = FACE_UNDER_LINE; + face->underline_color = 0; while (CONSP (underline)) { Lisp_Object keyword, value; @@ -6592,7 +6596,13 @@ realize_tty_face (struct face_cache *cache, value = XCAR (underline); underline = XCDR (underline); - if (EQ (keyword, QCstyle)) { + if (EQ (keyword, QCcolor)) { + if (EQ (value, Qforeground_color)) + face->underline_color = 0; + else if (STRINGP (value)) + face->underline_color = load_color (f, face, value, LFACE_UNDERLINE_INDEX); + } + else if (EQ (keyword, QCstyle)) { if (EQ (value, Qline)) face->tty_underline = FACE_UNDER_LINE; else if (EQ (value, Qdouble)) -- 2.43.0