Clarify check of 256 colors support.

(tty_use_truecolors): don't check 256 colors here.
(tty_use_256colors): generate error message if 256 colors aren't
supported.
(tty_init): sync with modified tty_use_256colors().
(tty_color_try_alloc_pair_lib): likewise.
(mc_skin_init): likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-02-07 15:08:13 +03:00
parent f29533f00f
commit 4cbc61a775
5 changed files with 17 additions and 15 deletions

View File

@ -159,7 +159,7 @@ mc_skin_init (const gchar * skin_override, GError ** mcerror)
(void) mc_skin_ini_file_parse (&mc_skin__default);
is_good_init = FALSE;
}
if (is_good_init && mc_skin__default.have_256_colors && !tty_use_256colors ())
if (is_good_init && mc_skin__default.have_256_colors && !tty_use_256colors (&error))
{
mc_propagate_error (mcerror, 0,
_

View File

@ -181,7 +181,7 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
attr = mc_color_pair->attr;
/* In legacy color mode, change bright colors into bold */
if (!tty_use_256colors () && !tty_use_truecolors (NULL))
if (!tty_use_256colors (NULL) && !tty_use_truecolors (NULL))
{
if (ifg >= 8 && ifg < 16)
{
@ -228,8 +228,10 @@ tty_set_normal_attrs (void)
/* --------------------------------------------------------------------------------------------- */
gboolean
tty_use_256colors (void)
tty_use_256colors (GError ** error)
{
(void) error;
return (COLORS == 256);
}

View File

@ -210,9 +210,17 @@ tty_set_normal_attrs (void)
/* --------------------------------------------------------------------------------------------- */
gboolean
tty_use_256colors (void)
tty_use_256colors (GError ** error)
{
return (SLtt_Use_Ansi_Colors && SLtt_tgetnum ((char *) "Co") == 256);
gboolean ret;
ret = (SLtt_Use_Ansi_Colors && SLtt_tgetnum ((char *) "Co") == 256);
if (!ret)
g_set_error (error, MC_ERROR, -1,
_("Your terminal doesn't even seem to support 256 colors."));
return ret;
}
/* --------------------------------------------------------------------------------------------- */
@ -232,14 +240,6 @@ tty_use_truecolors (GError ** error)
return FALSE;
}
/* Sanity check that at least 256 colors are supported. */
if (!tty_use_256colors ())
{
g_set_error (error, MC_ERROR, -1,
_("Your terminal doesn't even seem to support 256 colors."));
return FALSE;
}
/* Duplicate slang's check so that we can pop up an error message
rather than silently use wrong colors. */
colorterm = getenv ("COLORTERM");

View File

@ -47,7 +47,7 @@ void tty_set_normal_attrs (void);
void tty_color_set_defaults (const char *, const char *, const char *);
extern gboolean tty_use_256colors (void);
extern gboolean tty_use_256colors (GError **);
extern gboolean tty_use_truecolors (GError **);
/*** inline functions ****************************************************************************/

View File

@ -310,7 +310,7 @@ tty_init (gboolean mouse_enable, gboolean is_xterm)
tty_reset_prog_mode ();
load_terminfo_keys ();
SLtt_Blink_Mode = (tty_use_256colors () || tty_use_truecolors (NULL)) ? 1 : 0;
SLtt_Blink_Mode = (tty_use_256colors (NULL) || tty_use_truecolors (NULL)) ? 1 : 0;
tty_start_interrupt_key ();