From 88af2c3ace0fa42dbb816cc9fe8c4b54ce89233a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Oct 2008 14:25:00 +0200 Subject: [PATCH] colors: make color support optional at compile time Default is colors disabled. Those who love colorful terminals have the option to enable it with --enable-colors. --- configure.ac | 12 ++++++++++++ src/colors.c | 12 ++++++++++++ src/colors.h | 5 +++++ src/conf.c | 14 ++++++++++++++ src/ncu.c | 11 +++++++++++ src/options.c | 9 +++++++++ src/options.h | 4 ++++ src/screen.c | 2 ++ 8 files changed, 69 insertions(+) diff --git a/configure.ac b/configure.ac index 732b36f..83a47a7 100644 --- a/configure.ac +++ b/configure.ac @@ -138,6 +138,18 @@ if test "x$use_raw" = "xyes" ; then AC_DEFINE([ENABLE_RAW_MODE], [1], [Place the terminal into raw mode]) fi +dnl enable colors +AC_MSG_CHECKING([color support]) +AC_ARG_ENABLE([colors], + AC_HELP_STRING([--enable-colors], + [Enable color support]), + [use_colors=$enableval], + [use_colors=no]) +AC_MSG_RESULT([$use_colors]) +if test "x$use_colors" = "xyes" ; then + AC_DEFINE([ENABLE_COLORS], [1], [Enable color support]) +fi + dnl Debugging AC_MSG_CHECKING([whether to build with debug support]) AC_ARG_ENABLE([debug], diff --git a/src/colors.c b/src/colors.c index 68c5b60..0bcf278 100644 --- a/src/colors.c +++ b/src/colors.c @@ -18,7 +18,9 @@ #include "colors.h" #include "i18n.h" +#ifdef ENABLE_COLORS #include "options.h" +#endif #include #include @@ -53,10 +55,12 @@ #define NAME_ALERT "alert" #define NAME_BGCOLOR "background" +#ifdef ENABLE_COLORS typedef struct { short color; short r,g,b; } color_definition_entry_t; +#endif typedef struct { const char *name; @@ -79,6 +83,8 @@ static color_entry_t colors[COLOR_END] = { [COLOR_STATUS_ALERT] = { NAME_ALERT, COLOR_BRIGHT_RED, A_BOLD }, }; +#ifdef ENABLE_COLORS + /* background color */ static short bg = COLOR_BLACK; @@ -208,6 +214,7 @@ colors_assign(const char *name, const char *value) return 0; } + int colors_start(void) { @@ -257,6 +264,7 @@ colors_start(void) return 0; } +#endif int colors_use(WINDOW *w, enum color id) @@ -269,15 +277,19 @@ colors_use(WINDOW *w, enum color id) wattr_get(w, &attrs, &pair, NULL); +#ifdef ENABLE_COLORS if (options.enable_colors) { /* color mode */ if (attrs != entry->attrs || (short)id != pair) wattr_set(w, entry->attrs, id, NULL); } else { +#endif /* mono mode */ if (attrs != entry->attrs) wattrset(w, entry->attrs); +#ifdef ENABLE_COLORS } +#endif return 0; } diff --git a/src/colors.h b/src/colors.h index b612a33..051aa9e 100644 --- a/src/colors.h +++ b/src/colors.h @@ -1,6 +1,8 @@ #ifndef COLORS_H #define COLORS_H +#include "config.h" + #include enum color { @@ -20,9 +22,12 @@ enum color { short colors_str2color(const char *str); +#ifdef ENABLE_COLORS int colors_assign(const char *name, const char *value); int colors_define(const char *name, short r, short g, short b); int colors_start(void); +#endif + int colors_use(WINDOW *w, enum color id); #endif /* COLORS_H */ diff --git a/src/conf.c b/src/conf.c index 5dff1cc..4485cda 100644 --- a/src/conf.c +++ b/src/conf.c @@ -225,6 +225,7 @@ parse_timedisplay_type(const char *str) } } +#ifdef ENABLE_COLORS static int parse_color(char *str) { @@ -312,6 +313,7 @@ parse_color_definition(char *str) g_free(name); return value; } +#endif static char * get_format(char *str) @@ -438,13 +440,21 @@ read_rc_file(char *filename, options_t *options) parse_key_definition(value); /* enable colors */ else if(!strcasecmp(CONF_ENABLE_COLORS, name)) +#ifdef ENABLE_COLORS options->enable_colors = str2bool(value); +#else + {} +#endif /* auto center */ else if (!strcasecmp(CONF_AUTO_CENTER, name)) options->auto_center = str2bool(value); /* color assignment */ else if (!strcasecmp(CONF_COLOR, name)) +#ifdef ENABLE_COLORS parse_color(value); +#else + {} +#endif /* wide cursor */ else if (!strcasecmp(CONF_WIDE_CURSOR, name)) options->wide_cursor = str2bool(value); @@ -460,7 +470,11 @@ read_rc_file(char *filename, options_t *options) options->timedisplay_type=g_strdup(parse_timedisplay_type(value)); /* color definition */ } else if (!strcasecmp(CONF_COLOR_DEFINITION, name)) +#ifdef ENABLE_COLORS parse_color_definition(value); +#else + {} +#endif /* list format string */ else if (!strcasecmp(CONF_LIST_FORMAT, name)) { g_free(options->list_format); diff --git a/src/ncu.c b/src/ncu.c index ed3c227..936e78a 100644 --- a/src/ncu.c +++ b/src/ncu.c @@ -17,7 +17,16 @@ */ #include "ncu.h" + +#ifdef ENABLE_COLORS #include "colors.h" +#endif + +#ifdef HAVE_GETMOUSE +#include "options.h" +#endif + +#include void ncu_init(void) @@ -26,7 +35,9 @@ ncu_init(void) initscr(); /* initialize color support */ +#ifdef ENABLE_COLORS colors_start(); +#endif /* tell curses not to do NL->CR/NL on output */ nonl(); diff --git a/src/options.c b/src/options.c index 75f074a..1b592a5 100644 --- a/src/options.c +++ b/src/options.c @@ -151,6 +151,11 @@ handle_option(int c, const char *arg) #ifdef ENABLE_NLS " nls" #endif +#ifdef ENABLE_COLORS + " colors" +#else + " no-colors" +#endif #ifdef HAVE_GETMOUSE " getmouse" #endif @@ -166,10 +171,14 @@ handle_option(int c, const char *arg) "\n"); exit(EXIT_SUCCESS); case 'c': /* --colors */ +#ifdef ENABLE_COLORS options.enable_colors = true; +#endif break; case 'C': /* --no-colors */ +#ifdef ENABLE_COLORS options.enable_colors = false; +#endif break; case 'm': /* --mouse */ options.enable_mouse = true; diff --git a/src/options.h b/src/options.h index 70853f4..e7e9e8f 100644 --- a/src/options.h +++ b/src/options.h @@ -1,6 +1,8 @@ #ifndef OPTIONS_H #define OPTIONS_H +#include "config.h" + #include #define MPD_HOST_ENV "MPD_HOST" @@ -31,7 +33,9 @@ typedef struct { bool list_wrap; bool auto_center; bool wide_cursor; +#ifdef ENABLE_COLORS bool enable_colors; +#endif bool audible_bell; bool visible_bell; bool enable_xterm_title; diff --git a/src/screen.c b/src/screen.c index 231d84a..2fd4b57 100644 --- a/src/screen.c +++ b/src/screen.c @@ -503,6 +503,7 @@ screen_init(mpdclient_t *c) leaveok(screen.status_window.w, FALSE); keypad(screen.status_window.w, TRUE); +#ifdef ENABLE_COLORS if (options.enable_colors) { /* set background attributes */ wbkgd(stdscr, COLOR_PAIR(COLOR_LIST)); @@ -512,6 +513,7 @@ screen_init(mpdclient_t *c) wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS)); colors_use(screen.progress_window.w, COLOR_PROGRESSBAR); } +#endif refresh(); -- 2.30.2