Skip to content

Commit 24ae55a

Browse files
author
Manuel Einfalt
committed
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>
1 parent dc2dbc8 commit 24ae55a

8 files changed

Lines changed: 227 additions & 21 deletions

File tree

.github/workflows/ci-ubuntu.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
--enable-werror
4444
4545
make -j$(nproc)
46-
make check
46+
make V=1 check
4747
make install
4848
4949
- name: Build ncurses configuration
@@ -57,7 +57,7 @@ jobs:
5757
--enable-werror
5858
5959
make -j$(nproc)
60-
make check
60+
make V=1 check
6161
6262
- name: Build minimal configuration
6363
run: |
@@ -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 \
@@ -86,7 +85,7 @@ jobs:
8685
--enable-werror
8786
8887
make -j$(nproc)
89-
make check
88+
make V=1 check
9089
9190
- uses: actions/upload-artifact@v7
9291
if: failure()

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PACKAGE_STRING = "/lib/skin"
2+
3+
AM_CPPFLAGS = \
4+
-DTEST_SHARE_DIR=\"$(abs_builddir)\" \
5+
$(GLIB_CFLAGS) \
6+
-I$(top_srcdir) \
7+
-fno-lto \
8+
@CHECK_CFLAGS@
9+
10+
LIBS = @CHECK_LIBS@ \
11+
$(top_builddir)/lib/libmc.la \
12+
$(top_builddir)/src/libinternal.la
13+
14+
if ENABLE_MCLIB
15+
LIBS += $(GLIB_LIBS) \
16+
@E2P_LIBS@
17+
endif
18+
19+
TESTS = \
20+
common__mc_skin_init
21+
22+
check_PROGRAMS = $(TESTS)
23+
24+
common__mc_skin_init_SOURCES = \
25+
common__mc_skin_init.c
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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+
#include "lib/util.h"
30+
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[] = { { "xterm", FALSE, "dark", FALSE, TRUE },
46+
{ "xterm", FALSE, "julia256", TRUE, FALSE },
47+
{ "xterm", FALSE, "seasons-summer16M", TRUE, FALSE },
48+
{ "xterm", TRUE, "dark", FALSE, TRUE },
49+
{ "xterm", TRUE, "julia256", TRUE, FALSE },
50+
{ "xterm", TRUE, "seasons-summer16M", TRUE, FALSE },
51+
52+
{ "xterm-256color", FALSE, "dark", FALSE, TRUE },
53+
{ "xterm-256color", FALSE, "julia256", FALSE, TRUE },
54+
{ "xterm-256color", FALSE, "seasons-summer16M", TRUE, FALSE },
55+
{ "xterm-256color", TRUE, "dark", FALSE, TRUE },
56+
{ "xterm-256color", TRUE, "julia256", FALSE, TRUE },
57+
{ "xterm-256color", TRUE, "seasons-summer16M", TRUE, FALSE },
58+
59+
{ "xterm-256direct", FALSE, "dark", FALSE, TRUE },
60+
{ "xterm-256direct", FALSE, "julia256", FALSE, TRUE },
61+
{ "xterm-256direct", FALSE, "seasons-summer16M", FALSE, TRUE },
62+
{ "xterm-256direct", TRUE, "dark", FALSE, TRUE },
63+
{ "xterm-256direct", TRUE, "julia256", FALSE, TRUE },
64+
{ "xterm-256direct", TRUE, "seasons-summer16M", FALSE, TRUE } };
65+
66+
extern GHashTable *mc_tty_color__hashtable;
67+
static char inipath[PATH_MAX];
68+
69+
/* --------------------------------------------------------------------------------------------- */
70+
71+
// Mock
72+
gboolean
73+
tty_use_truecolors (GError **error)
74+
{
75+
char *termname = getenv ("TERM");
76+
77+
printf("tty_use_truecolors ()\n");
78+
if (termname == NULL)
79+
{
80+
mc_propagate_error (error, 0, _ ("foobar"));
81+
return FALSE;
82+
}
83+
84+
if (strcmp (termname, "xterm-256direct") == 0)
85+
return TRUE;
86+
87+
mc_propagate_error (error, 0, _ ("foobar"));
88+
return FALSE;
89+
}
90+
91+
// Mock
92+
gboolean
93+
tty_use_256colors (GError **error)
94+
{
95+
char *termname = getenv ("TERM");
96+
97+
printf("tty_use_256colors ()\n");
98+
if (termname == NULL)
99+
{
100+
mc_propagate_error (error, 0, _ ("foobar"));
101+
return FALSE;
102+
}
103+
104+
if (strcmp (termname, "xterm-256color") == 0 || tty_use_truecolors (NULL))
105+
return TRUE;
106+
107+
mc_propagate_error (error, 0, _ ("foobar"));
108+
return FALSE;
109+
}
110+
111+
/* --------------------------------------------------------------------------------------------- */
112+
113+
static void
114+
setup (void)
115+
{
116+
char *path = getcwd (inipath, PATH_MAX);
117+
118+
strcpy (path + strlen (path), "/../../../misc/");
119+
120+
mc_global.share_data_dir = path;
121+
mc_global.sysconfig_dir = path;
122+
123+
str_init_strings (NULL);
124+
vfs_init ();
125+
vfs_init_localfs ();
126+
tty_color_role_to_pair = g_new (int, COLOR_MAP_SIZE);
127+
mc_tty_color__hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
128+
}
129+
130+
static void
131+
teardown (void)
132+
{
133+
vfs_shut ();
134+
str_uninit_strings ();
135+
}
136+
137+
/* --------------------------------------------------------------------------------------------- */
138+
139+
START_PARAMETRIZED_TEST (skin_test, skin_tests)
140+
{
141+
GError *mcerror = NULL;
142+
143+
mc_global.tty.disable_colors = data->nocolor;
144+
setenv ("TERM", data->term, 1);
145+
146+
if (data->ret)
147+
{
148+
mctest_assert_true (mc_skin_init (data->skin_name, &mcerror));
149+
} else {
150+
mctest_assert_false (mc_skin_init (data->skin_name, &mcerror));
151+
}
152+
153+
if (data->has_error)
154+
{
155+
mctest_assert_not_null (mcerror);
156+
g_error_free (mcerror);
157+
}
158+
else
159+
mctest_assert_null (mcerror);
160+
}
161+
END_PARAMETRIZED_TEST
162+
163+
/* --------------------------------------------------------------------------------------------- */
164+
165+
int
166+
main (void)
167+
{
168+
TCase *tc_core;
169+
170+
tc_core = tcase_create ("Core");
171+
tcase_add_checked_fixture (tc_core, setup, teardown);
172+
173+
// Add new tests here: ***************
174+
mctest_add_parameterized_test (tc_core, skin_test, skin_tests);
175+
// ***********************************
176+
177+
return mctest_run_all (tc_core);
178+
}
179+
180+
/* --------------------------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)