mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
TTY: modified color initialization.
Set color mode via tty_init_colors() function. Made disable_colors and force_colors variables static in main.h. Removed tty_disable_colors() function. Some code optimization. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
aadc438c20
commit
508c20c92d
16
src/main.c
16
src/main.c
@ -273,6 +273,11 @@ static char *last_wd_string = NULL;
|
||||
/* Set to 1 to suppress printing the last directory */
|
||||
static int print_last_revert = 0;
|
||||
|
||||
/* Set to force black and white display at program startup */
|
||||
static gboolean disable_colors = FALSE;
|
||||
/* Force colors, only used by Slang */
|
||||
static gboolean force_colors = FALSE;
|
||||
|
||||
/* colors specified on the command line: they override any other setting */
|
||||
char *command_line_colors = NULL;
|
||||
|
||||
@ -2057,12 +2062,9 @@ process_args (poptContext ctx, int c, const char *option_arg)
|
||||
tty_set_ugly_line_drawing (TRUE);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
tty_disable_colors (TRUE, FALSE);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
tty_disable_colors (FALSE, TRUE);
|
||||
disable_colors = FALSE;
|
||||
force_colors = TRUE; /* for S-Lang only */
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
@ -2130,7 +2132,7 @@ static const struct poptOption argument_table[] = {
|
||||
N_("Use stickchars to draw"), NULL},
|
||||
|
||||
/* color options */
|
||||
{"nocolor", 'b', POPT_ARG_NONE, {NULL}, 'b',
|
||||
{"nocolor", 'b', POPT_ARG_NONE, {&disable_colors}, 0,
|
||||
N_("Requests to run in black and white"), NULL},
|
||||
{"color", 'c', POPT_ARG_NONE, {NULL}, 'c',
|
||||
N_("Request to run in color mode"), NULL},
|
||||
@ -2328,7 +2330,7 @@ main (int argc, char *argv[])
|
||||
|
||||
tty_init_curses ();
|
||||
|
||||
tty_init_colors ();
|
||||
tty_init_colors (disable_colors, force_colors);
|
||||
|
||||
dlg_set_default_colors ();
|
||||
|
||||
|
@ -30,9 +30,6 @@
|
||||
#include "../../src/tty/color.h" /* colors and attributes */
|
||||
#include "../../src/tty/color-internal.h"
|
||||
|
||||
gboolean disable_colors = FALSE;
|
||||
gboolean force_colors = FALSE; /* unused with NCurses */
|
||||
|
||||
struct color_table_s const color_table [] = {
|
||||
{ "black", COLOR_BLACK },
|
||||
{ "gray", COLOR_BLACK | A_BOLD },
|
||||
|
@ -16,8 +16,6 @@
|
||||
# include "../../src/tty/tty-ncurses.h"
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
extern gboolean disable_colors;
|
||||
extern gboolean force_colors; /* for S-Lang only */
|
||||
extern gboolean use_colors;
|
||||
|
||||
struct color_table_s {
|
||||
|
@ -39,15 +39,16 @@
|
||||
int attr_pairs [MAX_PAIRS];
|
||||
|
||||
void
|
||||
tty_init_colors (void)
|
||||
tty_init_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
if (has_colors () && !disable_colors)
|
||||
use_colors = TRUE;
|
||||
(void) force;
|
||||
|
||||
if (use_colors) {
|
||||
if (has_colors () && !disable) {
|
||||
const size_t map_len = color_map_len ();
|
||||
size_t i;
|
||||
|
||||
use_colors = TRUE;
|
||||
|
||||
start_color ();
|
||||
use_default_colors ();
|
||||
|
||||
@ -67,21 +68,14 @@ tty_init_colors (void)
|
||||
if (color_map [i].name != NULL) {
|
||||
mc_init_pair (i + 1, color_map_fg (i), color_map_bg (i));
|
||||
/*
|
||||
* ncurses doesn't remember bold attribute in the color pairs,
|
||||
* so we should keep track of it in a separate array.
|
||||
*/
|
||||
* ncurses doesn't remember bold attribute in the color pairs,
|
||||
* so we should keep track of it in a separate array.
|
||||
*/
|
||||
attr_pairs [i + 1] = color_map [i].fg & A_BOLD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tty_disable_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
disable_colors = disable;
|
||||
(void) force_colors;
|
||||
}
|
||||
|
||||
/* Functions necessary to implement syntax highlighting */
|
||||
void
|
||||
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
||||
|
@ -39,20 +39,20 @@
|
||||
#include "../../src/setup.h" /* color_terminal_string */
|
||||
|
||||
static int
|
||||
has_colors (void)
|
||||
has_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
const char *terminal = getenv ("TERM");
|
||||
char *cts = color_terminal_string;
|
||||
char *s;
|
||||
size_t i;
|
||||
|
||||
if (force_colors)
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
if (getenv ("COLORTERM") != NULL)
|
||||
if (force || (getenv ("COLORTERM") != NULL))
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
|
||||
/* We want to allow overwriding */
|
||||
if (!disable_colors) {
|
||||
if (!disable) {
|
||||
const char *terminal = getenv ("TERM");
|
||||
const size_t len = strlen (terminal);
|
||||
|
||||
char *cts = color_terminal_string;
|
||||
char *s;
|
||||
size_t i;
|
||||
|
||||
/* check color_terminal_string */
|
||||
while (*cts != '\0') {
|
||||
while (*cts == ' ' || *cts == '\t')
|
||||
@ -65,7 +65,7 @@ has_colors (void)
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i != 0 && i == strlen (terminal) && strncmp (s, terminal, i) == 0)
|
||||
if ((i != 0) && (i == len) && (strncmp (s, terminal, i) == 0))
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
|
||||
if (*cts == ',')
|
||||
@ -74,8 +74,8 @@ has_colors (void)
|
||||
}
|
||||
|
||||
/* Setup emulated colors */
|
||||
if (SLtt_Use_Ansi_Colors) {
|
||||
if (tty_use_colors ()) {
|
||||
if (SLtt_Use_Ansi_Colors != 0) {
|
||||
if (!disable) {
|
||||
mc_init_pair (A_REVERSE, "black", "white");
|
||||
mc_init_pair (A_BOLD, "white", "black");
|
||||
} else {
|
||||
@ -86,24 +86,23 @@ has_colors (void)
|
||||
} else {
|
||||
SLtt_set_mono (A_BOLD, NULL, SLTT_BOLD_MASK);
|
||||
SLtt_set_mono (A_REVERSE, NULL, SLTT_REV_MASK);
|
||||
SLtt_set_mono (A_BOLD|A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
|
||||
SLtt_set_mono (A_BOLD | A_REVERSE, NULL, SLTT_BOLD_MASK | SLTT_REV_MASK);
|
||||
}
|
||||
|
||||
return SLtt_Use_Ansi_Colors;
|
||||
}
|
||||
|
||||
void
|
||||
tty_init_colors (void)
|
||||
tty_init_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
/* FIXME: if S-Lang is used, has_colors() must be called regardless
|
||||
of whether we are interested in its result */
|
||||
if (has_colors () && !disable_colors)
|
||||
use_colors = TRUE;
|
||||
|
||||
if (use_colors) {
|
||||
if (has_colors (disable, force) && !disable) {
|
||||
const size_t map_len = color_map_len ();
|
||||
size_t i;
|
||||
|
||||
use_colors = TRUE;
|
||||
|
||||
configure_colors ();
|
||||
|
||||
/*
|
||||
@ -121,13 +120,6 @@ tty_init_colors (void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tty_disable_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
disable_colors = disable;
|
||||
force_colors = force;
|
||||
}
|
||||
|
||||
/* Functions necessary to implement syntax highlighting */
|
||||
void
|
||||
mc_init_pair (int index, CTYPE foreground, CTYPE background)
|
||||
|
@ -80,10 +80,9 @@
|
||||
#define ERROR_HOT_NORMAL IF_COLOR (39, 0)
|
||||
#define ERROR_HOT_FOCUS IF_COLOR (40, 0)
|
||||
|
||||
void tty_init_colors (void);
|
||||
void tty_init_colors (gboolean disable, gboolean force);
|
||||
void tty_colors_done (void);
|
||||
gboolean tty_use_colors (void);
|
||||
void tty_disable_colors (gboolean disable, gboolean force);
|
||||
int tty_try_alloc_color_pair (const char *fg, const char *bg);
|
||||
void tty_setcolor (int color);
|
||||
void tty_lowlevel_setcolor (int color);
|
||||
|
Loading…
Reference in New Issue
Block a user