unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Filipe Silva <filipe.silva@gmail.com>
To: "Rami Ylimäki" <rami.ylimaki@vincit.fi>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: [PATCH 3/3] Let user turn 24-bit terminal colors on.
Date: Sun, 12 Feb 2017 16:00:19 -0200	[thread overview]
Message-ID: <CAEwkUWPHFAwsArM2LvZwToTDBApZwh45XpuoYaB9Z3AtyT8QCg@mail.gmail.com> (raw)
In-Reply-To: <1486893930-6709-4-git-send-email-rami.ylimaki@vincit.fi>

[-- Attachment #1: Type: text/plain, Size: 3477 bytes --]

Thanks for this Rami,

I've being itching to get 24 bit colors in terminal emacs for years.

​

On Sun, Feb 12, 2017 at 8:05 AM, Rami Ylimäki <rami.ylimaki@vincit.fi>
wrote:

> From: Rami Ylimäki <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:
>
>   $ 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 = p1 / 65536, g = (p1 / 256) & 255, b = p1 & 255
>   xterm-24bit|xterm with 16777216 colors,
>     use=xterm-256color,
>     setab24=\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm,
>     setaf24=\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm,
>
>   $ tic -x -o ~/.terminfo xterm-24bit
>
>   $ TERM=xterm-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=...; export
> TERM' (C-shell:\n\
>
>        tty->TN_max_colors = tgetnum ("Co");
>
> +#if TERMINFO
> +      /* Non-standard support for 24-bit colors. */
> +      {
> +       const char* fg = tigetstr ("setaf24");
> +       const char* bg = tigetstr ("setab24");
> +       if (fg && bg && fg != (char *)-1 && bg != (char *)-1)
> +         {
> +           tty->TS_set_foreground = fg;
> +           tty->TS_set_background = bg;
> +           tty->TN_max_colors = 16777216;
> +         }
> +      }
> +#endif
> +
>        tty->TN_no_color_video = tgetnum ("NC");
>        if (tty->TN_no_color_video == -1)
>          tty->TN_no_color_video = 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
>
>
>

[-- Attachment #2: Type: text/html, Size: 4732 bytes --]

  reply	other threads:[~2017-02-12 18:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-12 10:05 [PATCH v2] Support 24-bit terminal colors Rami Ylimäki
2017-02-12 10:05 ` [PATCH 1/3] Remove unused terminal color pair count Rami Ylimäki
2017-02-12 10:05 ` [PATCH 2/3] Support 24-bit terminal colors Rami Ylimäki
2017-02-12 10:05 ` [PATCH 3/3] Let user turn 24-bit terminal colors on Rami Ylimäki
2017-02-12 18:00   ` Filipe Silva [this message]
2017-02-12 19:27   ` Rami Ylimäki
2017-02-12 20:47 ` [PATCH v2] Support 24-bit terminal colors Eli Zaretskii
2017-02-12 22:53   ` Rami Ylimäki
2017-02-13  5:41     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEwkUWPHFAwsArM2LvZwToTDBApZwh45XpuoYaB9Z3AtyT8QCg@mail.gmail.com \
    --to=filipe.silva@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=rami.ylimaki@vincit.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).