18 Jun 2012 15:18
Re: [PATCH] ui: add support for color attributes
meh. <meh <at> paranoici.org>
2012-06-18 13:18:19 GMT
2012-06-18 13:18:19 GMT
Anything else?
>From dbba5210438ec81991e76026c703a088a1792a8d Mon Sep 17 00:00:00 2001
From: meh <meh <at> paranoici.org>
Date: Sun, 17 Jun 2012 16:28:00 +0200
Subject: [PATCH] ui: add support for color attributes
This commit adds text attribute support to UI elements.
This adds the following color settings:
- color_cmdline_attr
- color_cur_sel_attr
- color_statusline_attr
- color_titleline_attr
- color_win_attr
- color_win_cur_sel_attr
- color_win_inactive_cur_sel_attr
- color_win_inactive_sel_attr
- color_win_sel_attr
- color_win_title_attr
Every options supports a set of attributes which have to be
sperated by a '|' without spaces.
Example:
set color_cmdline_attr=underline|reverse
The possible attributes are:
- default
- standout
- bold
- reverse
- underline
- blink
Signed-off-by: meh. <meh <at> paranoici.org>
---
Doc/cmus.txt | 46 ++++++++++++++++++++++++++
options.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
options.h | 15 +++++++++
ui_curses.c | 27 ++++++++++++++--
4 files changed, 187 insertions(+), 2 deletions(-)
diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index c1b4654..2a39706 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
<at> <at> -755,6 +755,9 <at> <at> color_cmdline_bg (default) [`Color`]
color_cmdline_fg (default) [`Color`]
Command line foreground color.
+color_cmdline_attr (default) [`Attributes`]
+ Command line attributes.
+
color_error (lightred) [`Color`]
Color of error messages displayed on the command line.
<at> <at> -770,12 +773,18 <at> <at> color_statusline_bg (gray) [`Color`]
color_statusline_fg (black) [`Color`]
Status line foreground color.
+color_statusline_attr (default) [`Attributes`]
+ Status line attributes.
+
color_titleline_bg (blue) [`Color`]
Background color of the line displaying currently playing track.
color_titleline_fg (white) [`Color`]
Foreground color of the line displaying currently playing track.
+color_titleline_attr (default) [`Attributes`]
+ Attributes of the line displaying currently playing track.
+
color_win_bg (default) [`Color`]
Window background color.
<at> <at> -790,12 +799,19 <at> <at> color_win_cur_sel_fg (lightyellow) [`Color`]
Foreground color of the selected row which is also the currently
playing track in active window.
+color_win_cur_sel_attr (default) [`Attributes`]
+ Attributes of the selected row which is also the currently
+ playing track in active window.
+
color_win_dir (lightblue) [`Color`]
Color of directories in browser.
color_win_fg (default) [`Color`]
Window foreground color.
+color_win_attr (default) [`Attributes`]
+ Window attributes.
+
color_win_inactive_cur_sel_bg (gray) [`Color`]
Background color of the selected row which is also the currently
playing track in inactive window.
<at> <at> -804,24 +820,37 <at> <at> color_win_inactive_cur_sel_fg (lightyellow) [`Color`]
Foreground color of the selected row which is also the currently
playing track in inactive window.
+color_win_inactive_cur_sel_attr (default) [`Attributes`]
+ Attributes of the selected row which is also the currently
+ playing track in inactive window.
+
color_win_inactive_sel_bg (gray) [`Color`]
Background color of selected row in inactive window.
color_win_inactive_sel_fg (black) [`Color`]
Foreground color of selected row in inactive window.
+color_win_inactive_sel_attr (default) [`Attributes`]
+ Attributes of selected row in inactive window.
+
color_win_sel_bg (blue) [`Color`]
Background color of selected row in active window.
color_win_sel_fg (white) [`Color`]
Foreground color of selected row in active window.
+color_win_sel_attr (default) [`Attributes`]
+ Attributes of selected row in active window.
+
color_win_title_bg (blue) [`Color`]
Background color of window titles (topmost line of the screen).
color_win_title_fg (white) [`Color`]
Foreground color of window titles (topmost line of the screen).
+color_win_title_attr (default) [`Attributes`]
+ Attributes of window titles (topmost line of the screen).
+
confirm_run (true)
Ask for confirmation before executing *:run*
<at> <at> -955,6 +984,23 <at> <at> Fg, 8..15
darkgray, lightred, lightgreen, lightyellow, lightblue, lightmagenta,
lightcyan, white
+ <at> h2 Attributes
+
+Attributes is a set of names "standout|bold":
+
+`default` does nothing, if you put it with other attributes
+the other attributes will be used.
+
+`standout` makes the text standout.
+
+`bold` makes the text bold.
+
+`reverse` reverses the text colors.
+
+`underline` underlines the text.
+
+`blink` makes the text blink.
+
<at> h2 Format Strings
Format strings control display of tracks in library, playlist and play queue
diff --git a/options.c b/options.c
index 8325c05..e1c9344 100644
--- a/options.c
+++ b/options.c
<at> <at> -104,6 +104,18 <at> <at> int colors[NR_COLORS] = {
COLOR_WHITE | BRIGHT
};
+int attrs[NR_ATTRS] = {
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL,
+ A_NORMAL
+};
+
/* uninitialized option variables */
char *track_win_format = NULL;
char *track_win_format_va = NULL;
<at> <at> -899,6 +911,79 <at> <at> static void set_color(unsigned int id, const char *buf)
update_full();
}
+static const char * const attr_enum_names[6 + 1] = {
+ "default",
+ "standout", "underline", "reverse", "blink", "bold",
+ NULL
+};
+
+static void get_attr(unsigned int id, char *buf)
+{
+ int attr = attrs[id];
+
+ if (attr == 0) {
+ strcpy(buf, "default");
+ return;
+ }
+
+ if (attr & A_STANDOUT)
+ strcat(buf, "standout|");
+
+ if (attr & A_UNDERLINE)
+ strcat(buf, "underline|");
+
+ if (attr & A_REVERSE)
+ strcat(buf, "reverse|");
+
+ if (attr & A_BLINK)
+ strcat(buf, "blink|");
+
+ if (attr & A_BOLD)
+ strcat(buf, "bold|");
+
+ buf[strlen(buf) - 1] = '\0';
+}
+
+static void set_attr(unsigned int id, const char *buf)
+{
+ int attr = 0;
+ size_t i = 0;
+ size_t offset = 0;
+ size_t length = 0;
+ char* current;
+
+ do {
+ if (buf[i] == '|' || buf[i] == '\0') {
+ current = strndup(&buf[offset], length);
+
+ if (strcmp(current, "default") == 0)
+ attr |= A_NORMAL;
+ else if (strcmp(current, "standout") == 0)
+ attr |= A_STANDOUT;
+ else if (strcmp(current, "underline") == 0)
+ attr |= A_UNDERLINE;
+ else if (strcmp(current, "reverse") == 0)
+ attr |= A_REVERSE;
+ else if (strcmp(current, "blink") == 0)
+ attr |= A_BLINK;
+ else if (strcmp(current, "bold") == 0)
+ attr |= A_BOLD;
+
+ free(current);
+
+ offset = i;
+ length = -1;
+ }
+
+ i++;
+ length++;
+ } while (buf[i - 1] != '\0');
+
+ attrs[id] = attr;
+ update_colors();
+ update_full();
+}
+
static char **id_to_fmt(enum format_id id)
{
switch (id) {
<at> <at> -1021,6 +1106,19 <at> <at> static const char * const color_names[NR_COLORS] = {
"color_win_title_fg"
};
+static const char * const attr_names[NR_ATTRS] = {
+ "color_cmdline_attr",
+ "color_statusline_attr",
+ "color_titleline_attr",
+ "color_win_attr",
+ "color_win_cur_sel_attr",
+ "color_cur_sel_attr",
+ "color_win_inactive_cur_sel_attr",
+ "color_win_inactive_sel_attr",
+ "color_win_sel_attr",
+ "color_win_title_attr"
+};
+
/* default values for the variables which we must initialize but
* can't do it statically */
static const struct {
<at> <at> -1108,6 +1206,9 <at> <at> void options_add(void)
for (i = 0; i < NR_COLORS; i++)
option_add(color_names[i], i, get_color, set_color, NULL, 0);
+ for (i = 0; i < NR_ATTRS; i++)
+ option_add(attr_names[i], i, get_attr, set_attr, NULL, 0);
+
ip_add_options();
op_add_options();
}
diff --git a/options.h b/options.h
index 3fa6a6f..724636d 100644
--- a/options.h
+++ b/options.h
<at> <at> -99,6 +99,20 <at> <at> enum {
NR_COLORS
};
+enum {
+ COLOR_CMDLINE_ATTR,
+ COLOR_STATUSLINE_ATTR,
+ COLOR_TITLELINE_ATTR,
+ COLOR_WIN_ATTR,
+ COLOR_WIN_CUR_SEL_ATTR,
+ COLOR_CUR_SEL_ATTR,
+ COLOR_WIN_INACTIVE_CUR_SEL_ATTR,
+ COLOR_WIN_INACTIVE_SEL_ATTR,
+ COLOR_WIN_SEL_ATTR,
+ COLOR_WIN_TITLE_ATTR,
+ NR_ATTRS
+};
+
#define BRIGHT (1 << 3)
extern char *cdda_device;
<at> <at> -123,6 +137,7 <at> <at> extern const char * const aaa_mode_names[];
extern const char * const view_names[NR_VIEWS + 1];
extern int colors[NR_COLORS];
+extern int attrs[NR_ATTRS];
/* format string for track window (tree view) */
extern char *track_win_format;
diff --git a/ui_curses.c b/ui_curses.c
index 5b575f6..84502ca 100644
--- a/ui_curses.c
+++ b/ui_curses.c
<at> <at> -211,6 +211,28 <at> <at> static unsigned char cursed_to_fg_idx[NR_CURSED] = {
COLOR_INFO
};
+static unsigned char cursed_to_attr_idx[NR_CURSED] = {
+ COLOR_WIN_ATTR,
+ COLOR_WIN_ATTR,
+ COLOR_WIN_INACTIVE_SEL_ATTR,
+ COLOR_WIN_INACTIVE_CUR_SEL_ATTR,
+
+ COLOR_WIN_ATTR,
+ COLOR_WIN_ATTR,
+ COLOR_WIN_SEL_ATTR,
+ COLOR_WIN_CUR_SEL_ATTR,
+
+ COLOR_WIN_ATTR,
+ COLOR_WIN_TITLE_ATTR,
+ COLOR_CMDLINE_ATTR,
+ COLOR_STATUSLINE_ATTR,
+
+ COLOR_TITLELINE_ATTR,
+ COLOR_WIN_ATTR,
+ COLOR_CMDLINE_ATTR,
+ COLOR_CMDLINE_ATTR
+};
+
/* index is CURSED_*, value is fucking color pair */
static int pairs[NR_CURSED];
<at> <at> -1657,15 +1679,16 <at> <at> void update_colors(void)
for (i = 0; i < NR_CURSED; i++) {
int bg = colors[cursed_to_bg_idx[i]];
int fg = colors[cursed_to_fg_idx[i]];
+ int attr = attrs[cursed_to_attr_idx[i]];
int pair = i + 1;
if (fg >= 8 && fg <= 15) {
/* fg colors 8..15 are special (0..7 + bold) */
init_pair(pair, fg & 7, bg);
- pairs[i] = COLOR_PAIR(pair) | (fg & BRIGHT ? A_BOLD : 0);
+ pairs[i] = COLOR_PAIR(pair) | (fg & BRIGHT ? A_BOLD : 0) | attr;
} else {
init_pair(pair, fg, bg);
- pairs[i] = COLOR_PAIR(pair);
+ pairs[i] = COLOR_PAIR(pair) | attr;
}
}
}
--
--
1.7.10.4
------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
RSS Feed