Skip to content

Commit 6dc6dd0

Browse files
Manuel Einfaltzyv
authored andcommitted
Ticket #4981: do not show color warning with --nocolor
Suppress the color capability warning when --nocolor is used. Keep the warning if a skin is explicitly requested. Signed-off-by: Manuel Einfalt <einfalt1@proton.me> Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
1 parent a01afd4 commit 6dc6dd0

11 files changed

Lines changed: 233 additions & 18 deletions

File tree

.github/workflows/ci-ubuntu.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ jobs:
6767
../configure \
6868
--prefix="$(pwd)/install" \
6969
--disable-shared \
70-
--disable-static \
7170
--disable-maintainer-mode \
7271
--disable-largefile \
7372
--disable-nls \

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ tests/Makefile
690690
tests/lib/Makefile
691691
tests/lib/mcconfig/Makefile
692692
tests/lib/search/Makefile
693+
tests/lib/skin/Makefile
693694
tests/lib/strutil/Makefile
694695
tests/lib/vfs/Makefile
695696
tests/lib/vfs/mc.charsets

lib/skin/common.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ mc_skin_t mc_skin__default;
4545

4646
/*** file scope variables ************************************************************************/
4747

48-
static gboolean mc_skin_is_init = FALSE;
49-
5048
/* --------------------------------------------------------------------------------------------- */
5149
/*** file scope functions ************************************************************************/
5250
/* --------------------------------------------------------------------------------------------- */
@@ -149,27 +147,28 @@ mc_skin_init (const gchar *skin_override, GError **mcerror)
149147
}
150148
if (is_good_init && mc_skin__default.have_true_colors && !tty_use_truecolors (&error))
151149
{
152-
mc_propagate_error (mcerror, 0,
153-
_ ("Unable to use '%s' skin with true colors support:\n%s\nDefault "
154-
"skin has been loaded"),
155-
mc_skin__default.name, error->message);
150+
if (!mc_global.tty.disable_colors || skin_override != NULL)
151+
mc_propagate_error (mcerror, 0,
152+
_ ("Unable to use '%s' skin with true colors support:\n%s\n"
153+
"Default skin has been loaded"),
154+
mc_skin__default.name, error->message);
156155
g_error_free (error);
157156
mc_skin_try_to_load_default ();
158157
(void) mc_skin_ini_file_parse (&mc_skin__default);
159158
is_good_init = FALSE;
160159
}
161160
if (is_good_init && mc_skin__default.have_256_colors && !tty_use_256colors (&error))
162161
{
163-
mc_propagate_error (mcerror, 0,
164-
_ ("Unable to use '%s' skin with 256 colors support:\n%s\nDefault "
165-
"skin has been loaded"),
166-
mc_skin__default.name, error->message);
162+
if (!mc_global.tty.disable_colors || skin_override != NULL)
163+
mc_propagate_error (mcerror, 0,
164+
_ ("Unable to use '%s' skin with 256 colors support:\n%s\n"
165+
"Default skin has been loaded"),
166+
mc_skin__default.name, error->message);
167167
g_error_free (error);
168168
mc_skin_try_to_load_default ();
169169
(void) mc_skin_ini_file_parse (&mc_skin__default);
170170
is_good_init = FALSE;
171171
}
172-
mc_skin_is_init = TRUE;
173172
return is_good_init;
174173
}
175174

@@ -188,8 +187,6 @@ mc_skin_deinit (void)
188187

189188
mc_config_deinit (mc_skin__default.config);
190189
mc_skin__default.config = NULL;
191-
192-
mc_skin_is_init = FALSE;
193190
}
194191

195192
/* --------------------------------------------------------------------------------------------- */

lib/tty/color.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ gboolean need_convert_256color = FALSE;
6262

6363
/*** file scope variables ************************************************************************/
6464

65-
static GHashTable *mc_tty_color__hashtable = NULL;
65+
#ifdef HAVE_TESTS
66+
extern GHashTable *mc_tty_color__hashtable;
67+
#endif
68+
69+
MC_TESTABLE GHashTable *mc_tty_color__hashtable = NULL;
6670

6771
/* --------------------------------------------------------------------------------------------- */
6872
/*** file scope functions ************************************************************************/

lib/tty/color.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void tty_color_free_all (void);
6969
void tty_setcolor (int color);
7070
void tty_set_normal_attrs (void);
7171

72-
extern gboolean tty_use_256colors (GError **error);
73-
extern gboolean tty_use_truecolors (GError **error);
72+
MC_MOCKABLE gboolean tty_use_256colors (GError **error);
73+
MC_MOCKABLE gboolean tty_use_truecolors (GError **error);
7474

7575
/*** inline functions ****************************************************************************/
7676

tests/lib/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PACKAGE_STRING = "/lib"
22

3-
SUBDIRS = . mcconfig search strutil vfs widget
3+
SUBDIRS = . mcconfig search strutil vfs widget skin
44

55
AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@
66

tests/lib/skin/Makefile.am

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
PACKAGE_STRING = "/lib/skin"
2+
3+
AM_CPPFLAGS = \
4+
-DTEST_SHARE_DIR=\"$(abs_srcdir)/fixtures\" \
5+
$(GLIB_CFLAGS) \
6+
-I$(top_srcdir) \
7+
@CHECK_CFLAGS@
8+
9+
LIBS = @CHECK_LIBS@ \
10+
$(top_builddir)/lib/libmc.la \
11+
$(top_builddir)/src/libinternal.la
12+
13+
if ENABLE_MCLIB
14+
LIBS += $(GLIB_LIBS) \
15+
@E2P_LIBS@
16+
endif
17+
18+
EXTRA_DIST = \
19+
fixtures/skins/dark.ini \
20+
fixtures/skins/julia256.ini \
21+
fixtures/skins/seasons-summer16M.ini
22+
23+
TESTS = \
24+
common__mc_skin_init
25+
26+
check_PROGRAMS = $(TESTS)
27+
28+
common__mc_skin_init_SOURCES = \
29+
common__mc_skin_init.c
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
lib/skin - mc_skin_init() function testing
3+
4+
Copyright (C) 2026
5+
Free Software Foundation, Inc.
6+
7+
Written by:
8+
Manuel Einfalt <einfalt1@proton.me>, 2026
9+
10+
This file is part of the Midnight Commander.
11+
12+
The Midnight Commander is free software: you can redistribute it
13+
and/or modify it under the terms of the GNU General Public License as
14+
published by the Free Software Foundation, either version 3 of the License,
15+
or (at your option) any later version.
16+
17+
The Midnight Commander is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
GNU General Public License for more details.
21+
22+
You should have received a copy of the GNU General Public License
23+
along with this program. If not, see <https://www.gnu.org/licenses/>.
24+
*/
25+
26+
#define TEST_SUITE_NAME "/lib/skin"
27+
28+
#include "tests/mctest.h"
29+
30+
#include "lib/util.h"
31+
#include "lib/skin.h"
32+
33+
#include "lib/strutil.h" // str_init_strings
34+
#include "src/vfs/local/local.h" // vfs_init_localfs
35+
36+
/* --------------------------------------------------------------------------------------------- */
37+
38+
static const struct skin_tests // xterm, xterm-256color, xterm-direct
39+
{
40+
const char *term;
41+
const gboolean nocolor;
42+
const gchar *skin_name;
43+
const gboolean has_error;
44+
const gboolean ret;
45+
} skin_tests[] = {
46+
{ "xterm", FALSE, "dark", FALSE, TRUE },
47+
{ "xterm", FALSE, "julia256", TRUE, FALSE },
48+
{ "xterm", FALSE, "seasons-summer16M", TRUE, FALSE },
49+
{ "xterm", TRUE, "dark", FALSE, TRUE },
50+
{ "xterm", TRUE, "julia256", TRUE, FALSE },
51+
{ "xterm", TRUE, "seasons-summer16M", TRUE, FALSE },
52+
53+
{ "xterm-256color", FALSE, "dark", FALSE, TRUE },
54+
{ "xterm-256color", FALSE, "julia256", FALSE, TRUE },
55+
{ "xterm-256color", FALSE, "seasons-summer16M", TRUE, FALSE },
56+
{ "xterm-256color", TRUE, "dark", FALSE, TRUE },
57+
{ "xterm-256color", TRUE, "julia256", FALSE, TRUE },
58+
{ "xterm-256color", TRUE, "seasons-summer16M", TRUE, FALSE },
59+
60+
{ "xterm-256direct", FALSE, "dark", FALSE, TRUE },
61+
{ "xterm-256direct", FALSE, "julia256", FALSE, TRUE },
62+
{ "xterm-256direct", FALSE, "seasons-summer16M", FALSE, TRUE },
63+
{ "xterm-256direct", TRUE, "dark", FALSE, TRUE },
64+
{ "xterm-256direct", TRUE, "julia256", FALSE, TRUE },
65+
{ "xterm-256direct", TRUE, "seasons-summer16M", FALSE, TRUE },
66+
};
67+
68+
extern GHashTable *mc_tty_color__hashtable;
69+
70+
/* --------------------------------------------------------------------------------------------- */
71+
72+
static void
73+
setup (void)
74+
{
75+
mc_global.share_data_dir = (char *) TEST_SHARE_DIR;
76+
mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
77+
78+
str_init_strings (NULL);
79+
vfs_init ();
80+
vfs_init_localfs ();
81+
tty_color_role_to_pair = g_new (int, COLOR_MAP_SIZE);
82+
mc_tty_color__hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
83+
}
84+
85+
static void
86+
teardown (void)
87+
{
88+
vfs_shut ();
89+
str_uninit_strings ();
90+
}
91+
92+
/* --------------------------------------------------------------------------------------------- */
93+
94+
// Mock
95+
gboolean
96+
tty_use_truecolors (GError **error)
97+
{
98+
const char *termname = getenv ("TERM");
99+
100+
if (termname == NULL)
101+
{
102+
mc_propagate_error (error, 0, _ ("foobar"));
103+
return FALSE;
104+
}
105+
106+
if (strcmp (termname, "xterm-256direct") == 0)
107+
return TRUE;
108+
109+
mc_propagate_error (error, 0, _ ("foobar"));
110+
return FALSE;
111+
}
112+
113+
// Mock
114+
gboolean
115+
tty_use_256colors (GError **error)
116+
{
117+
const char *termname = getenv ("TERM");
118+
119+
if (termname == NULL)
120+
{
121+
mc_propagate_error (error, 0, _ ("foobar"));
122+
return FALSE;
123+
}
124+
125+
if (strcmp (termname, "xterm-256color") == 0 || tty_use_truecolors (NULL))
126+
return TRUE;
127+
128+
mc_propagate_error (error, 0, _ ("foobar"));
129+
return FALSE;
130+
}
131+
132+
/* --------------------------------------------------------------------------------------------- */
133+
134+
START_PARAMETRIZED_TEST (skin_test, skin_tests)
135+
{
136+
GError *mcerror = NULL;
137+
138+
mc_global.tty.disable_colors = data->nocolor;
139+
setenv ("TERM", data->term, 1);
140+
141+
if (data->ret)
142+
{
143+
mctest_assert_true (mc_skin_init (data->skin_name, &mcerror));
144+
}
145+
else
146+
{
147+
mctest_assert_false (mc_skin_init (data->skin_name, &mcerror));
148+
}
149+
150+
if (data->has_error)
151+
{
152+
mctest_assert_not_null (mcerror);
153+
g_error_free (mcerror);
154+
}
155+
else
156+
mctest_assert_null (mcerror);
157+
}
158+
END_PARAMETRIZED_TEST
159+
160+
/* --------------------------------------------------------------------------------------------- */
161+
162+
int
163+
main (void)
164+
{
165+
TCase *tc_core;
166+
167+
tc_core = tcase_create ("Core");
168+
tcase_add_checked_fixture (tc_core, setup, teardown);
169+
170+
// Add new tests here: ***************
171+
mctest_add_parameterized_test (tc_core, skin_test, skin_tests);
172+
// ***********************************
173+
174+
return mctest_run_all (tc_core);
175+
}
176+
177+
/* --------------------------------------------------------------------------------------------- */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[skin]
2+
description = Dark skin
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[skin]
2+
description = Dark skin with calm colors and good contrast
3+
256colors = true

0 commit comments

Comments
 (0)