summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3e66cb6)
raw | patch | inline | side by side (parent: 3e66cb6)
author | Andy Spencer <andy753421@gmail.com> | |
Tue, 24 Nov 2009 19:57:06 +0000 (19:57 +0000) | ||
committer | Andy Spencer <andy753421@gmail.com> | |
Tue, 24 Nov 2009 19:57:06 +0000 (19:57 +0000) |
Colors can now be specified with a comma separated list of attributes,
for example: `blue,bold,underline'.
Putting multiple colors in the list is probably a bad idea..
Existing `bright' colors should be converted to bold colors.
e.g. brightblue => blue,bold
for example: `blue,bold,underline'.
Putting multiple colors in the list is probably a bad idea..
Existing `bright' colors should be converted to bold colors.
e.g. brightblue => blue,bold
NEWS | patch | blob | history | |
doc/config.sample | patch | blob | history | |
doc/ncmpc.1 | patch | blob | history | |
src/colors.c | patch | blob | history |
index c79ec7656b56e91aacd002fb73f479e0665c336a..588bf5e9440a32cce3e6f5c4956c263a9a7af839 100644 (file)
--- a/NEWS
+++ b/NEWS
* status_bar: fix display_remaining_time while seeking
* status_bar: display elapsed time event when total time is unknown
* charset: added support for zero-width characters
+* colors: added support for 256 colors and text attributes
ncmpc 0.15 - 2009-09-24
diff --git a/doc/config.sample b/doc/config.sample
index 7dcfaead68f4da03427642ee1e6faa7897a91e7b..75ab0f19209dccd667e30255f9da0f5f78f4b506 100644 (file)
--- a/doc/config.sample
+++ b/doc/config.sample
#second-column = yes
############## Colors #######################
+## colors: none, black, red, green, yellow, blue, magenta, cyan, white
+## attributes: standout, underline, reverse, blink, dim, bold
##
-## base colors: black, red, green, yellow, blue, magenta, cyan, white
-##
+## Colors can also be given as an integer representing a terminal specific
+## color code. The special color, none, represents the terminals default color.
## Enable/disable colors.
#enable-colors = no
-## Set the background color. If the background color is assigned
-## to the keyword none, ncmpc will not change the background color.
+## Set the background color.
#color background = black
-## text colors: black, red, green, yellow, blue, magenta, cyan, white,
-## brightblack, brightred, brightgreen, brightyellow, brightblue,
-## brightmagenta, brightcyan, brightwhite
-
## Set the text color for the title row.
#color title = yellow
## Set the text color for the title row (the bold part).
-#color title-bold = brightyellow
+#color title-bold = yellow,bold
## Set the color of the line on the second row.
#color line = white
## Set the text color used to indicate mpd flags on the second row.
-#color line-flags = brightwhite
+#color line-flags = white,bold
## Set the text color in the main area of ncmpc.
#color list = green
## Set the bold text color in the main area of ncmpc.
-#color list-bold = brightgreen
+#color list-bold = green,bold
## Sets the text color of directories in the browser
#color browser-directory = yellow
#color progressbar = white
## Set the text color used to display mpd status in the status window.
-#color status-state = brightyellow
+#color status-state = yellow,bold
## Set the text color used to display song names in the status window.
#color status-song = yellow
#color status-time = red
## Text color used to display alerts in the status window.
-#color alert = brightred
+#color alert = red,bold
## Redefine any of the base colors.
## The RGB values must be an integer value between 0 and 1000.
diff --git a/doc/ncmpc.1 b/doc/ncmpc.1
index e09a65c512499ba2c4a8eecb902ed2d18d1728ea..7c4e8df26ef731e016f9a75bc7690b884b632b1b 100644 (file)
--- a/doc/ncmpc.1
+++ b/doc/ncmpc.1
Enable/disable colors.
.TP
.B color background = COLOR
-Set the background color. If the background color is assigned to the keyword \fBnone\fR, ncmpc will not change the background color. Valid background colors are the base colors: black, red, green, yellow, blue, magenta, cyan and white.
+Set the background color. If the background color is assigned to the keyword \fBnone\fR, ncmpc will not change the background color. Standard colors are: black, red, green, yellow, blue, magenta, cyan and white. Terminal specific colors can also be given as integers.
.TP
-.B color title = TEXTCOLOR
-Set the text color for the title row. Possible text colors are the base colors plus grey, brightred, brightgreen, brightyellow, brightblue, brightmagenta, brightcyan and brightwhite.
+.B color title = COLOR[,ATTRIBUTE]...
+Set the text color and attributes for the title row. Text colors are the same as for the background. Valid attributes are: standout, underline, reverse, blink, dim, and bold.
.TP
-.B color title\-bold = TEXTCOLOR
+.B color title\-bold = COLOR[,ATTRIBUTE]...
Set the text color for the title row (the bold part).
.TP
-.B color line = TEXTCOLOR
+.B color line = COLOR
Set the color of the line on the second row.
.TP
-.B color line\-flags = TEXTCOLOR
+.B color line\-flags = COLOR[,ATTRIBUTE]...
Set the text color used to indicate mpd flags on the second row.
.TP
-.B color list = TEXTCOLOR
+.B color list = COLOR[,ATTRIBUTE]...
Set the text color in the main area of ncmpc.
.TP
-.B color list\-bold = TEXTCOLOR
+.B color list\-bold = COLOR[,ATTRIBUTE]...
Set the bold text color in the main area of ncmpc.
.TP
-.B color progressbar = TEXTCOLOR
+.B color progressbar = COLOR[,ATTRIBUTE]...
Set the color of the progress indicator.
.TP
-.B color status\-state = TEXTCOLOR
+.B color status\-state = COLOR[,ATTRIBUTE]...
Set the text color used to display mpd status in the status window.
.TP
-.B color status\-song = TEXTCOLOR
+.B color status\-song = COLOR[,ATTRIBUTE]...
Set the text color used to display song names in the status window.
.TP
-.B color status\-time = TEXTCOLOR
+.B color status\-time = COLOR[,ATTRIBUTE]...
Set the text color used to display time the status window.
.TP
-.B color alert = TEXTCOLOR
+.B color alert = COLOR[,ATTRIBUTE]...
Text color used to display alerts in the status window.
.TP
.B colordef COLOR = R, G, B
diff --git a/src/colors.c b/src/colors.c
index 2635329ec00ca40c6abc81dec7f34ea98993b2a9..dfaa84f1bdafce8ca8113ebde6994de66c1b7843 100644 (file)
--- a/src/colors.c
+++ b/src/colors.c
#include <string.h>
#include <glib.h>
-#define COLOR_NONE -1
+#define COLOR_NONE G_MININT /* left most bit only */
#define COLOR_ERROR -2
#ifdef ENABLE_COLORS
static int
colors_update_pair(enum color id)
{
- short fg, bg;
+ int fg, bg;
assert(id > 0 && id < COLOR_END);
fg = colors[id].color;
bg = colors[COLOR_BACKGROUND].color;
- /* COLOR_NONE is negative, which
- * results in a default colors */
- init_pair(id, fg, bg);
+ /* If color == COLOR_NONE (negative),
+ * pass -1 to avoid cast errors */
+ init_pair(id,
+ (fg < 0 ? -1 : fg),
+ (bg < 0 ? -1 : bg));
return 0;
}
int
colors_str2color(const char *str)
{
- int color;
- char *endptr;
-
- if (!strcasecmp(str, "black"))
- return COLOR_BLACK;
- else if (!strcasecmp(str, "red"))
- return COLOR_RED;
- else if (!strcasecmp(str, "green"))
- return COLOR_GREEN;
- else if (!strcasecmp(str, "yellow"))
- return COLOR_YELLOW;
- else if (!strcasecmp(str, "blue"))
- return COLOR_BLUE;
- else if (!strcasecmp(str, "magenta"))
- return COLOR_MAGENTA;
- else if (!strcasecmp(str, "cyan"))
- return COLOR_CYAN;
- else if (!strcasecmp(str, "white"))
- return COLOR_WHITE;
- else if (!strcasecmp(str, "brightred"))
- return COLOR_RED | A_BOLD;
- else if (!strcasecmp(str, "brightgreen"))
- return COLOR_GREEN | A_BOLD;
- else if (!strcasecmp(str, "brightyellow"))
- return COLOR_YELLOW | A_BOLD;
- else if (!strcasecmp(str, "brightblue"))
- return COLOR_BLUE | A_BOLD;
- else if (!strcasecmp(str, "brightmagenta"))
- return COLOR_MAGENTA | A_BOLD;
- else if (!strcasecmp(str, "brightcyan"))
- return COLOR_CYAN | A_BOLD;
- else if (!strcasecmp(str, "brightwhite"))
- return COLOR_WHITE | A_BOLD;
- else if (!strcasecmp(str, "grey") || !strcasecmp(str, "gray"))
- return COLOR_BLACK | A_BOLD;
- else if (!strcasecmp(str, "none"))
- return COLOR_NONE;
-
- color = strtol(str, &endptr, 10);
- if (str != endptr && endptr[0] == '\0')
- return color;
+ int i, color = 0;
+ char **parts = g_strsplit(str, ",", 0);
+ for (i = 0; parts[i]; i++) {
+ char *cur = parts[i];
+
+ /* Legacy colors (brightblue,etc) */
+ if (!strncasecmp(cur, "bright", 6)) {
+ color |= A_BOLD;
+ cur += 6;
+ }
- fprintf(stderr,_("Warning: Unknown color - %s\n"), str);
- return -2;
+ /* Colors */
+ if (!strcasecmp(cur, "none"))
+ color |= COLOR_NONE;
+ else if (!strcasecmp(cur, "black"))
+ color |= COLOR_BLACK;
+ else if (!strcasecmp(cur, "red"))
+ color |= COLOR_RED;
+ else if (!strcasecmp(cur, "green"))
+ color |= COLOR_GREEN;
+ else if (!strcasecmp(cur, "yellow"))
+ color |= COLOR_YELLOW;
+ else if (!strcasecmp(cur, "blue"))
+ color |= COLOR_BLUE;
+ else if (!strcasecmp(cur, "magenta"))
+ color |= COLOR_MAGENTA;
+ else if (!strcasecmp(cur, "cyan"))
+ color |= COLOR_CYAN;
+ else if (!strcasecmp(cur, "white"))
+ color |= COLOR_WHITE;
+ else if (!strcasecmp(cur, "grey") || !strcasecmp(cur, "gray"))
+ color |= COLOR_BLACK | A_BOLD;
+
+ /* Attributes */
+ else if (!strcasecmp(cur, "standout"))
+ color |= A_STANDOUT;
+ else if (!strcasecmp(cur, "underline"))
+ color |= A_UNDERLINE;
+ else if (!strcasecmp(cur, "reverse"))
+ color |= A_REVERSE;
+ else if (!strcasecmp(cur, "blink"))
+ color |= A_BLINK;
+ else if (!strcasecmp(cur, "dim"))
+ color |= A_DIM;
+ else if (!strcasecmp(cur, "bold"))
+ color |= A_BOLD;
+ else {
+ /* Numerical colors */
+ char *endptr;
+ int tmp = strtol(cur, &endptr, 10);
+ if (cur != endptr && endptr[0] == '\0') {
+ color |= tmp;
+ } else {
+ fprintf(stderr,_("Warning: Unknown color - %s\n"), str);
+ return COLOR_ERROR;
+ }
+ }
+
+ }
+ g_strfreev(parts);
+ return color;
}
/* This function is called from conf.c before curses have been started,
#ifdef ENABLE_COLORS
if (options.enable_colors) {
/* color mode */
- if ((int)attrs != entry->mono || (short)id != pair)
- wattr_set(w, entry->mono, id, NULL);
+ if ((int)attrs != entry->color || (short)id != pair)
+ wattr_set(w, entry->color, id, NULL);
} else {
#endif
/* mono mode */