Code

colors: make color support optional at compile time
authorMax Kellermann <max@duempel.org>
Fri, 3 Oct 2008 12:25:00 +0000 (14:25 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 3 Oct 2008 12:25:00 +0000 (14:25 +0200)
Default is colors disabled.  Those who love colorful terminals have
the option to enable it with --enable-colors.

configure.ac
src/colors.c
src/colors.h
src/conf.c
src/ncu.c
src/options.c
src/options.h
src/screen.c

index 732b36f1e93647e1e9aa710b86611e17f0d10be4..83a47a7d11311d22917fa71630afb61bbd66df11 100644 (file)
@@ -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], 
index 68c5b600753998d821a4209683cb1f0e08e2d1c9..0bcf2782c8a76677122d32f3d6cfdd3af2bb426c 100644 (file)
@@ -18,7 +18,9 @@
 
 #include "colors.h"
 #include "i18n.h"
+#ifdef ENABLE_COLORS
 #include "options.h"
+#endif
 
 #include <assert.h>
 #include <stdio.h>
 #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;
 }
index b612a33ce0ba93a8b5a8ee4573a574ab899a5dd9..051aa9e26b76b6e050aabaf270d1f2ba690b534d 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef COLORS_H
 #define COLORS_H
 
+#include "config.h"
+
 #include <ncurses.h>
 
 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 */
index 5dff1ccdfd798e8555aca5abc672086ccef29307..4485cda5981660676f4de691d81bdf7a9cde96ff 100644 (file)
@@ -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);
index ed3c2273b021b7f76a7b9b9e610b87c24ba3ff66..936e78aa5b52e351be499add2a9015c9fb16afc5 100644 (file)
--- a/src/ncu.c
+++ b/src/ncu.c
  */
 
 #include "ncu.h"
+
+#ifdef ENABLE_COLORS
 #include "colors.h"
+#endif
+
+#ifdef HAVE_GETMOUSE
+#include "options.h"
+#endif
+
+#include <ncurses.h>
 
 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();
index 75f074a63a5e46c763774bd203c3a2caa89da9ba..1b592a567fa39e0035144255b081a7e96371ae2b 100644 (file)
@@ -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;
index 70853f4ff1f3180edc028710e02b9bff8d18f6e3..e7e9e8f4c358b03598d32a009d2500f24b6b41cb 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef OPTIONS_H
 #define OPTIONS_H
 
+#include "config.h"
+
 #include <stdbool.h>
 
 #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;
index 231d84adad1aab40a86884c312aaf3924de4cbf9..2fd4b571f3123324f410d27e0504399e0ff4a710 100644 (file)
@@ -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();