From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Filipe Silva Newsgroups: gmane.emacs.devel Subject: Re: [PATCH 3/3] Let user turn 24-bit terminal colors on. Date: Sun, 12 Feb 2017 16:00:19 -0200 Message-ID: References: <1486893930-6709-1-git-send-email-rami.ylimaki@vincit.fi> <1486893930-6709-4-git-send-email-rami.ylimaki@vincit.fi> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114012d8a997200548591a22 X-Trace: blaine.gmane.org 1486922437 1393 195.159.176.226 (12 Feb 2017 18:00:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Feb 2017 18:00:37 +0000 (UTC) Cc: Emacs developers To: =?UTF-8?Q?Rami_Ylim=C3=A4ki?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Feb 12 19:00:32 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ccyRr-0008Mo-4h for ged-emacs-devel@m.gmane.org; Sun, 12 Feb 2017 19:00:31 +0100 Original-Received: from localhost ([::1]:52989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccyRv-0006fR-8z for ged-emacs-devel@m.gmane.org; Sun, 12 Feb 2017 13:00:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccyRk-0006dr-A5 for emacs-devel@gnu.org; Sun, 12 Feb 2017 13:00:25 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ccyRi-0000xb-N4 for emacs-devel@gnu.org; Sun, 12 Feb 2017 13:00:24 -0500 Original-Received: from mail-ot0-x242.google.com ([2607:f8b0:4003:c0f::242]:36675) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ccyRi-0000xC-H8 for emacs-devel@gnu.org; Sun, 12 Feb 2017 13:00:22 -0500 Original-Received: by mail-ot0-x242.google.com with SMTP id 36so8806866otx.3 for ; Sun, 12 Feb 2017 10:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=elyjwwp0X9RbyukRQlqmiqHtHw6jarSvNZr4Q0nYYVU=; b=DRMFbOJg6Mb5BuaWaDJrXgMvBoPc54L8Q7TDSLESGU3qGiH/DtxVDCthMvb1av4D0R zs6PglvRAxOT+sExD7KATkf2Krg6LsCKPEpTrY+vJMeNINEPZ8I6PCKuFUerN9YPT/ym A85TFGMq26QYijI9opfxICO3zyBIk2AAHEK2msmmFvFHYlhllhaCZooJPPDD2MATIFj3 b7WqsnWvApigFW5FzZtlMUjOVISy+NN/vErxZSiqUT6PibfAwY5hO9AicfPoCm8gFHH4 B7Ruxh2FW3He/gcZmSchgLb/xw5nNVwaICVs1VCPCVShN0AhT9FUo4vdMDUZmnNGKSUv Enyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=elyjwwp0X9RbyukRQlqmiqHtHw6jarSvNZr4Q0nYYVU=; b=BHZmiyM85a2XYeVAlNwrqdCsnlqQPstm75F+cN7MwbnhrtEI1jpLdJSDFjiU0BCNLC 5oO2tTEpL9ubYx/NaDeVbWiCQOL5eXvHLO+ZoIsoDo9Tk0RnOFlXY7ziIkonxDf7+18q EJ01AEt+roKze+WXq56i7mjVhf/SdWoPfa59qhWbUL4qBFxlFs/8DWfMdPSHxpgsJReN HOTm5WH3PBFfj1m5dkhEEnIJ7OGqRLyEklNkLbToHVCuZAJZWLNThoE4g2Kfqcy80zAt DEmLf41FCpBPnallWp1uN05ynU3URDCpOgni8tqetNlw8RJg27+d7JZzbA2NzJndqUxz C68Q== X-Gm-Message-State: AMke39lwhju++KjVXay728f7QL3K/9/9HNIiKc7TCL/RNSoUVardUKGhuVDEujwWwiN5FfDbT51j+r5m43RjZQ== X-Received: by 10.157.56.27 with SMTP id i27mr11174027otc.160.1486922420160; Sun, 12 Feb 2017 10:00:20 -0800 (PST) Original-Received: by 10.157.56.242 with HTTP; Sun, 12 Feb 2017 10:00:19 -0800 (PST) In-Reply-To: <1486893930-6709-4-git-send-email-rami.ylimaki@vincit.fi> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c0f::242 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212300 Archived-At: --001a114012d8a997200548591a22 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks for this Rami, I've being itching to get 24 bit colors in terminal emacs for years. =E2=80=8B On Sun, Feb 12, 2017 at 8:05 AM, Rami Ylim=C3=A4ki wrote: > From: Rami Ylim=C3=A4ki > > ITU-T T.412 9.1.4 and ITU-T T.416 13.1.8 specify control function for > changing terminal foreground and background colors. One possible format > for the control function parameters is: 2:n:r:g:b, where 2 is color > access mode indicating direct RGB space, n is an indentifier that gives > detailed information about the color space and r, g, b are the color > values. > > Most 24-bit terminals implement this function as 2;r;g;b. Color space > identifier has been omitted because of its complexity and rgb values are > assumed to be in range 0-255. Parameters are separated by semicolons > instead of colons for historical reasons. > > The terminfo database supports only indexed color control functions and > can't be used to determine whether a terminal has implemented direct > color control functions. > > However, this can be worked around by creating user defined functions > for setting 24-bit foreground and background colors. This can be done by > creating a terminfo source file with the required capabilities and > compiling a custom terminal type definition. > > For example: > > $ cat xterm-24bit > > # Replace semicolons with colons in setab24 and setaf24 on terminals > # that use ITU-T separators (iTerm2). A 24-bit integer (p1) is given > # as a parameter to the control functions which calculate rgb > # component values with following formulas: > # r =3D p1 / 65536, g =3D (p1 / 256) & 255, b =3D p1 & 255 > xterm-24bit|xterm with 16777216 colors, > use=3Dxterm-256color, > setab24=3D\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d= m, > setaf24=3D\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d= m, > > $ tic -x -o ~/.terminfo xterm-24bit > > $ TERM=3Dxterm-24bit emacs > > * src/term.c (init_tty): Use 24-bit terminal colors if corresponding > foreground and background functions are present in terminal type > definition. > * src/tparam.h: Define prototype for tigetstr. > --- > src/term.c | 14 ++++++++++++++ > src/tparam.h | 4 ++++ > 2 files changed, 18 insertions(+) > > diff --git a/src/term.c b/src/term.c > index b0ff9cb..9d1c3c1 100644 > --- a/src/term.c > +++ b/src/term.c > @@ -4131,6 +4131,20 @@ use the Bourne shell command 'TERM=3D...; export > TERM' (C-shell:\n\ > > tty->TN_max_colors =3D tgetnum ("Co"); > > +#if TERMINFO > + /* Non-standard support for 24-bit colors. */ > + { > + const char* fg =3D tigetstr ("setaf24"); > + const char* bg =3D tigetstr ("setab24"); > + if (fg && bg && fg !=3D (char *)-1 && bg !=3D (char *)-1) > + { > + tty->TS_set_foreground =3D fg; > + tty->TS_set_background =3D bg; > + tty->TN_max_colors =3D 16777216; > + } > + } > +#endif > + > tty->TN_no_color_video =3D tgetnum ("NC"); > if (tty->TN_no_color_video =3D=3D -1) > tty->TN_no_color_video =3D 0; > diff --git a/src/tparam.h b/src/tparam.h > index 15664d6..8e34c9e 100644 > --- a/src/tparam.h > +++ b/src/tparam.h > @@ -36,4 +36,8 @@ extern char PC; > extern char *BC; > extern char *UP; > > +#if TERMINFO > +char *tigetstr(const char *); > +#endif > + > #endif /* EMACS_TPARAM_H */ > -- > 2.7.4 > > > --001a114012d8a997200548591a22 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks for this Rami,=C2=A0

<= /div>
I've being itching to get 24 bit colors in terminal emac= s for years.=C2=A0

=E2=80=8B
=

On Sun, Feb 12, 2= 017 at 8:05 AM, Rami Ylim=C3=A4ki <rami.ylimaki@vincit.fi> wrote:
From: Rami Ylim=C3=A4ki <rjy@iki.fi>

ITU-T T.412 9.1.4 and ITU-T T.416 13.1.8 specify control function for
changing terminal foreground and background colors. One possible format
for the control function parameters is: 2:n:r:g:b, where 2 is color
access mode indicating direct RGB space, n is an indentifier that gives
detailed information about the color space and r, g, b are the color
values.

Most 24-bit terminals implement this function as 2;r;g;b. Color space
identifier has been omitted because of its complexity and rgb values are assumed to be in range 0-255. Parameters are separated by semicolons
instead of colons for historical reasons.

The terminfo database supports only indexed color control functions and
can't be used to determine whether a terminal has implemented direct color control functions.

However, this can be worked around by creating user defined functions
for setting 24-bit foreground and background colors. This can be done by creating a terminfo source file with the required capabilities and
compiling a custom terminal type definition.

For example:

=C2=A0 $ cat xterm-24bit

=C2=A0 # Replace semicolons with colons in setab24 and setaf24 on terminals=
=C2=A0 # that use ITU-T separators (iTerm2). A 24-bit integer (p1) is given=
=C2=A0 # as a parameter to the control functions which calculate rgb
=C2=A0 # component values with following formulas:
=C2=A0 # r =3D p1 / 65536, g =3D (p1 / 256) & 255, b =3D p1 & 255 =C2=A0 xterm-24bit|xterm with 16777216 colors,
=C2=A0 =C2=A0 use=3Dxterm-256color,
=C2=A0 =C2=A0 setab24=3D\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&= ;%d;%p1%{255}%&%dm,
=C2=A0 =C2=A0 setaf24=3D\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&= ;%d;%p1%{255}%&%dm,

=C2=A0 $ tic -x -o ~/.terminfo xterm-24bit

=C2=A0 $ TERM=3Dxterm-24bit emacs

* src/term.c (init_tty): Use 24-bit terminal colors if corresponding
foreground and background functions are present in terminal type
definition.
* src/tparam.h: Define prototype for tigetstr.
---
=C2=A0src/term.c=C2=A0 =C2=A0| 14 ++++++++++++++
=C2=A0src/tparam.h |=C2=A0 4 ++++
=C2=A02 files changed, 18 insertions(+)

diff --git a/src/term.c b/src/term.c
index b0ff9cb..9d1c3c1 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4131,6 +4131,20 @@ use the Bourne shell command 'TERM=3D...; export= TERM' (C-shell:\n\

=C2=A0 =C2=A0 =C2=A0 =C2=A0tty->TN_max_colors =3D tgetnum ("Co"= ;);

+#if TERMINFO
+=C2=A0 =C2=A0 =C2=A0 /* Non-standard support for 24-bit colors. */
+=C2=A0 =C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0const char* fg =3D tigetstr ("setaf24"= ;);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0const char* bg =3D tigetstr ("setab24"= ;);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (fg && bg && fg !=3D (char *= )-1 && bg !=3D (char *)-1)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tty->TS_set_foreground =3D fg;=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tty->TS_set_background =3D bg;=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tty->TN_max_colors =3D 1677721= 6;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
+=C2=A0 =C2=A0 =C2=A0 }
+#endif
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0tty->TN_no_color_video =3D tgetnum ("NC&= quot;);
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (tty->TN_no_color_video =3D=3D -1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tty->TN_no_color_video =3D 0;
diff --git a/src/tparam.h b/src/tparam.h
index 15664d6..8e34c9e 100644
--- a/src/tparam.h
+++ b/src/tparam.h
@@ -36,4 +36,8 @@ extern char PC;
=C2=A0extern char *BC;
=C2=A0extern char *UP;

+#if TERMINFO
+char *tigetstr(const char *);
+#endif
+
=C2=A0#endif /* EMACS_TPARAM_H */
--
2.7.4



--001a114012d8a997200548591a22--