Skip to content

Commit

Permalink
ChafaTermDb: Eat advertises color support via TERM
Browse files Browse the repository at this point in the history
The Eat terminal advertises its color support by setting its TERM to:
* eat-truecolor when it supports more than 256 colors,
* eat-256color when it supports more than 16 colors,
* eat-16color when it supports more than 8 colors,
* eat-color when it supports more than 1 color,
* eat-mono when it supports no colors.

Note that eat-16color isn't actually supported yet, but a bug has been
filed upstream: https://codeberg.org/akib/emacs-eat/issues/154
  • Loading branch information
sfllaw committed Apr 18, 2024
1 parent c12ef2c commit 2126cd9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chafa/chafa-term-db.c
Expand Up @@ -267,6 +267,17 @@ static const SeqStr *color_16_list [] =
NULL
};

static const SeqStr *color_8_list [] =
{
color_8_seqs,
NULL
};

static const SeqStr *color_mono_list [] =
{
NULL
};

static const SeqStr color_fbterm_seqs [] =
{
{ CHAFA_TERM_SEQ_SET_COLOR_FG_16, "\033[1;%1}" },
Expand Down Expand Up @@ -544,6 +555,18 @@ detect_capabilities (ChafaTermInfo *ti, gchar **envp)
if (!strcmp (term, "rxvt-unicode"))
color_seq_list = color_16_list;

/* Eat uses the "eat-" prefix for TERM. */
if (!strcmp (term, "eat-truecolor"))
color_seq_list = color_direct_list;
if (!strcmp (term, "eat-256color"))
color_seq_list = color_256_list;
if (!strcmp (term, "eat-16color"))
color_seq_list = color_16_list;
if (!strcmp (term, "eat-color"))
color_seq_list = color_8_list;
if (!strcmp (term, "eat-mono"))
color_seq_list = color_mono_list;

/* 'screen' does not like truecolor at all, but 256 colors works fine.
* Sometimes we'll see the outer terminal appended to the TERM string,
* like so: screen.xterm-256color */
Expand Down
4 changes: 4 additions & 0 deletions tools/chafa/chafa.c
Expand Up @@ -1761,6 +1761,10 @@ detect_terminal (ChafaTermInfo **term_info_out, ChafaCanvasMode *mode_out,
&& chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_SET_COLOR_FG_16)
&& chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_SET_COLOR_BG_16))
mode = CHAFA_CANVAS_MODE_INDEXED_16;
else if (chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_SET_COLOR_FGBG_8)
&& chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_SET_COLOR_FG_8)
&& chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_SET_COLOR_BG_8))
mode = CHAFA_CANVAS_MODE_INDEXED_8;
else if (chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_INVERT_COLORS)
&& chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_RESET_ATTRIBUTES))
mode = CHAFA_CANVAS_MODE_FGBG_BGFG;
Expand Down

0 comments on commit 2126cd9

Please sign in to comment.