Discussion:
[PATCH] ui: add support for color attributes
meh.
2012-06-17 15:41:19 UTC
Permalink
I don't know if this patch is wanted, if it isn't it's not a problem,
I will just maintain a repo on github with my patches.

If it is wanted and not made properly I'll be glad to fix what's
wrong.

The main reason for this is to make my theme consistent with the rest
of my themes (Loading Image...).
meh
2012-06-17 14:28:00 UTC
Permalink
---
options.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
options.h | 15 +++++++++
ui_curses.c | 27 ++++++++++++++--
3 files changed, 141 insertions(+), 2 deletions(-)

diff --git a/options.c b/options.c
index 8325c05..e1c9344 100644
--- a/options.c
+++ b/options.c
@@ -104,6 +104,18 @@ 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;
@@ -899,6 +911,79 @@ 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) {
@@ -1021,6 +1106,19 @@ 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 {
@@ -1108,6 +1206,9 @@ 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
@@ -99,6 +99,20 @@ 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;
@@ -123,6 +137,7 @@ 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
@@ -211,6 +211,28 @@ 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];

@@ -1657,15 +1679,16 @@ 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


--FCuugMFkClbJLl1L--
Gregory Petrosyan
2012-06-18 11:02:13 UTC
Permalink
Post by meh.
I don't know if this patch is wanted, if it isn't it's not a problem,
I will just maintain a repo on github with my patches.
If it is wanted and not made properly I'll be glad to fix what's
wrong.
The main reason for this is to make my theme consistent with the rest
of my themes (http://i.imgur.com/b4t7U.png).
Thanks a lot for the patch!

Can you please explain (in the commit message and in cmus' documentation files)
what exactly this patch does, so that users can discover this functionality?

Gregory
Gregory Petrosyan
2012-06-18 11:13:39 UTC
Permalink
Post by Gregory Petrosyan
Can you please explain (in the commit message and in cmus' documentation files)
what exactly this patch does, so that users can discover this functionality?
Sure, is the doc file to edit Doc/cmus.txt?
Yeah, sure — manpage is generated from it.

Gregory
meh.
2012-06-18 13:18:19 UTC
Permalink
Anything else?
Gregory Petrosyan
2012-06-18 13:51:15 UTC
Permalink
Post by meh.
Anything else?
No, the patch looks great! Thanks a lot; I've pushed it to the pu branch.

Gregory
meh.
2012-06-18 13:52:48 UTC
Permalink
Post by Gregory Petrosyan
No, the patch looks great! Thanks a lot; I've pushed it to the pu branch.
Thank you for merging :)

meh.
2012-06-18 11:10:02 UTC
Permalink
Post by Gregory Petrosyan
Can you please explain (in the commit message and in cmus' documentation files)
what exactly this patch does, so that users can discover this functionality?
Sure, is the doc file to edit Doc/cmus.txt?
meh
2012-06-17 14:28:00 UTC
Permalink
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. <***@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
@@ -755,6 +755,9 @@ 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.

@@ -770,12 +773,18 @@ 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.

@@ -790,12 +799,19 @@ 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.
@@ -804,24 +820,37 @@ 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*

@@ -955,6 +984,23 @@ Fg, 8..15
darkgray, lightred, lightgreen, lightyellow, lightblue, lightmagenta,
lightcyan, white

+@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.
+
@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
@@ -104,6 +104,18 @@ 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;
@@ -899,6 +911,79 @@ 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) {
@@ -1021,6 +1106,19 @@ 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 {
@@ -1108,6 +1206,9 @@ 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
@@ -99,6 +99,20 @@ 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;
@@ -123,6 +137,7 @@ 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
@@ -211,6 +211,28 @@ 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];

@@ -1657,15 +1679,16 @@ 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


--pf9I7BMVVzbSWLtt--
Loading...