summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--default.theme22
-rw-r--r--src/fe-common/core/themes.c255
-rw-r--r--src/fe-common/core/themes.h15
-rw-r--r--src/fe-text/mainwindows.h2
-rw-r--r--src/fe-text/screen.c10
-rw-r--r--src/fe-text/statusbar-items.c219
-rw-r--r--src/fe-text/statusbar.c35
-rw-r--r--src/fe-text/statusbar.h3
8 files changed, 317 insertions, 244 deletions
diff --git a/default.theme b/default.theme
index d6c5ae46..bc7f1fd2 100644
--- a/default.theme
+++ b/default.theme
@@ -229,4 +229,26 @@ abstracts = {
dccmsg = "[%G$1-%K(%g$0%K)%n] ";
dccquerynick = "%G$0-%n";
dccaction = "%W (*dcc*) $0-%n %|";
+
+ ##
+ ## statusbar
+ ##
+
+ # background of statusbar
+ sb_background = "%4";
+
+ # default statusbar item style
+ sb = "%c[%n$0-%c]%n";
+
+ sbmode = "(%c+%n$0-)";
+ sbaway = " (%GzZzZ%n)";
+ sbservertag = ":$0 (change with ^X)";
+ sbmore = "%_-- more --%_";
+ sblag = "{sb Lag: $0-}";
+ sbmail = "{sb Mail: $0-}";
+
+ # activity. Det is used for hilights when display doesn't support colors
+ sbact = "{sb {sbact_act $0}{sbact_det $1}}";
+ sbact_act = "Act: $0-";
+ sbact_det = " Det: $0-";
};
diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c
index 5646b7bc..997395a3 100644
--- a/src/fe-common/core/themes.c
+++ b/src/fe-common/core/themes.c
@@ -94,8 +94,6 @@ void theme_destroy(THEME_REC *rec)
g_hash_table_foreach(rec->modules, (GHFunc) theme_module_destroy, NULL);
g_hash_table_destroy(rec->modules);
- g_slist_foreach(rec->replace_keys, (GFunc) g_free, NULL);
- g_slist_free(rec->replace_keys);
g_slist_foreach(rec->replace_values, (GFunc) g_free, NULL);
g_slist_free(rec->replace_values);
@@ -104,30 +102,10 @@ void theme_destroy(THEME_REC *rec)
g_free(rec);
}
-#define EXPAND_FLAG_ROOT 0x01
-#define EXPAND_FLAG_LASTCOLOR_ARG 0x02
-static char *theme_format_expand_data(THEME_REC *theme,
- const char **format,
- char default_color,
- char *save_color, int flags);
-
-static int theme_replace_find(THEME_REC *theme, char chr)
-{
- GSList *tmp;
- int index = 0;
-
- for (tmp = theme->replace_keys; tmp != NULL; tmp = tmp->next) {
- if (strchr(tmp->data, chr) != NULL)
- return index;
- index++;
- }
-
- return -1;
-}
-
static char *theme_replace_expand(THEME_REC *theme, int index,
- char default_color, char *last_color,
- char chr)
+ char default_fg, char default_bg,
+ char *last_fg, char *last_bg,
+ char chr, int flags)
{
GSList *rec;
char *ret, *abstract, data[2];
@@ -139,16 +117,20 @@ static char *theme_replace_expand(THEME_REC *theme, int index,
abstract = rec->data;
abstract = theme_format_expand_data(theme, (const char **) &abstract,
- default_color, last_color, 0);
+ default_fg, default_bg,
+ last_fg, last_bg, flags);
ret = parse_special_string(abstract, NULL, NULL, data, NULL, 0);
g_free(abstract);
return ret;
}
-static const char *colorformats = "n01234567krgybmpcwKRGYBMPCW";
+static const char *fgcolorformats = "nkrgybmpcwKRGYBMPCW";
+static const char *bgcolorformats = "n01234567";
-#define IS_COLOR_FORMAT(c) \
- ((c) != '\0' && strchr(colorformats, c) != NULL)
+#define IS_FGCOLOR_FORMAT(c) \
+ ((c) != '\0' && strchr(fgcolorformats, c) != NULL)
+#define IS_BGCOLOR_FORMAT(c) \
+ ((c) != '\0' && strchr(bgcolorformats, c) != NULL)
/* append "variable" part in $variable, ie. not the contents of the variable */
static void theme_format_append_variable(GString *str, const char **format)
@@ -174,7 +156,9 @@ static void theme_format_append_variable(GString *str, const char **format)
/* append next "item", either a character, $variable or %format */
static void theme_format_append_next(THEME_REC *theme, GString *str,
const char **format,
- char default_color, char *last_color)
+ char default_fg, char default_bg,
+ char *last_fg, char *last_bg,
+ int flags)
{
int index;
char chr;
@@ -200,14 +184,32 @@ static void theme_format_append_next(THEME_REC *theme, GString *str,
(*format)++;
if (**format != '{' && **format != '}') {
chr = **format;
- if (**format == 'n')
- chr = default_color;
-
- if (IS_COLOR_FORMAT(chr))
- *last_color = chr;
-
- g_string_append_c(str, '%');
- g_string_append_c(str, chr);
+ if (**format == 'n') {
+ /* %n = change to default color */
+ if (default_fg == 'n' || default_bg == 'n') {
+ if (*last_fg != 'n')
+ g_string_append(str, "%n");
+ *last_bg = *last_fg = 'n';
+ }
+ if (default_bg != *last_bg) {
+ g_string_append_c(str, '%');
+ g_string_append_c(str, default_bg);
+ }
+ if (default_fg != *last_fg) {
+ g_string_append_c(str, '%');
+ g_string_append_c(str, default_fg);
+ }
+
+ *last_fg = default_fg;
+ *last_bg = default_bg;
+ } else {
+ if (IS_FGCOLOR_FORMAT(chr))
+ *last_fg = chr;
+ if (IS_BGCOLOR_FORMAT(chr))
+ *last_bg = chr;
+ g_string_append_c(str, '%');
+ g_string_append_c(str, chr);
+ }
(*format)++;
return;
}
@@ -216,14 +218,16 @@ static void theme_format_append_next(THEME_REC *theme, GString *str,
chr = **format;
}
- index = theme_replace_find(theme, chr);
+ index = (flags & EXPAND_FLAG_IGNORE_REPLACES) ? -1 :
+ theme->replace_keys[(int) chr];
if (index == -1)
g_string_append_c(str, chr);
else {
char *value;
- value = theme_replace_expand(theme, index, default_color,
- last_color, chr);
+ value = theme_replace_expand(theme, index,
+ default_fg, default_bg,
+ last_fg, last_bg, chr, flags);
g_string_append(str, value);
g_free(value);
}
@@ -234,7 +238,8 @@ static void theme_format_append_next(THEME_REC *theme, GString *str,
/* expand a single {abstract ...data... } */
static char *theme_format_expand_abstract(THEME_REC *theme,
const char **formatp,
- char default_color)
+ char default_fg, char default_bg,
+ int flags)
{
const char *p, *format;
char *abstract, *data, *ret;
@@ -252,9 +257,23 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
len = (int) (p-format);
abstract = g_strndup(format, len);
- /* skip the following space */
- if (*p == ' ') len++;
- *formatp = format + len;
+ /* skip the following space, if there's any more spaces they're
+ treated as arguments */
+ if (*p == ' ') {
+ len++;
+ if ((flags & EXPAND_FLAG_IGNORE_EMPTY)) {
+ /* if the data is empty, ignore the abstract */
+ p = format+len;
+ while (*p == ' ') p++;
+ if (*p == '}') {
+ *formatp = p+1;
+ g_free(abstract);
+ return NULL;
+ }
+ }
+
+ }
+ *formatp = format+len;
/* get the abstract data */
data = g_hash_table_lookup(theme->abstracts, abstract);
@@ -265,19 +284,12 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
}
abstract = g_strdup(data);
- /* abstract may itself contain abstracts or replaces :) */
- p = data = abstract;
- abstract = theme_format_expand_data(theme, &p, default_color,
- &default_color,
- EXPAND_FLAG_LASTCOLOR_ARG);
- g_free(data);
-
- /* now we'll need to get the data part. it may contain
+ /* we'll need to get the data part. it may contain
more abstracts, they are automatically expanded. */
- data = theme_format_expand_data(theme, formatp, default_color,
- NULL, 0);
-
+ data = theme_format_expand_data(theme, formatp, default_fg, default_bg,
+ NULL, NULL, flags);
len = strlen(data);
+
if (len > 1 && isdigit(data[len-1]) && data[len-2] == '$') {
/* ends with $<digit> .. this breaks things if next
character is digit or '-' */
@@ -293,23 +305,34 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
ret = parse_special_string(abstract, NULL, NULL, data, NULL, 0);
g_free(abstract);
- g_free(data);
+ g_free(data);
+ abstract = ret;
+
+ /* abstract may itself contain abstracts or replaces */
+ p = abstract;
+ ret = theme_format_expand_data(theme, &p, default_fg, default_bg,
+ &default_fg, &default_bg,
+ flags | EXPAND_FLAG_LASTCOLOR_ARG);
+ g_free(abstract);
return ret;
}
/* expand the data part in {abstract data} */
-static char *theme_format_expand_data(THEME_REC *theme,
- const char **format,
- char default_color,
- char *save_last_color,
- int flags)
+char *theme_format_expand_data(THEME_REC *theme, const char **format,
+ char default_fg, char default_bg,
+ char *save_last_fg, char *save_last_bg,
+ int flags)
{
GString *str;
char *ret, *abstract;
- char last_color = default_color;
+ char last_fg, last_bg;
+ int recurse_flags;
- str = g_string_new(NULL);
+ last_fg = default_fg;
+ last_bg = default_bg;
+ recurse_flags = flags & EXPAND_FLAG_RECURSIVE_MASK;
+ str = g_string_new(NULL);
while (**format != '\0') {
if ((flags & EXPAND_FLAG_ROOT) == 0 && **format == '}') {
/* ignore } if we're expanding original string */
@@ -318,17 +341,24 @@ static char *theme_format_expand_data(THEME_REC *theme,
}
if (**format != '{') {
- if (save_last_color != NULL &&
- (flags & EXPAND_FLAG_LASTCOLOR_ARG) &&
+ if ((flags & EXPAND_FLAG_LASTCOLOR_ARG) &&
**format == '$' && (*format)[1] == '0') {
/* save the color before $0 ..
this is for the %n replacing */
- *save_last_color = last_color;
- save_last_color = NULL;
+ if (save_last_fg != NULL) {
+ *save_last_fg = last_fg;
+ save_last_fg = NULL;
+ }
+ if (save_last_bg != NULL) {
+ *save_last_bg = last_bg;
+ save_last_bg = NULL;
+ }
}
theme_format_append_next(theme, str, format,
- default_color, &last_color);
+ default_fg, default_bg,
+ &last_fg, &last_bg,
+ recurse_flags);
continue;
}
@@ -338,17 +368,20 @@ static char *theme_format_expand_data(THEME_REC *theme,
/* get a single {...} */
abstract = theme_format_expand_abstract(theme, format,
- last_color);
+ last_fg, last_bg,
+ recurse_flags);
if (abstract != NULL) {
g_string_append(str, abstract);
g_free(abstract);
}
}
- if (save_last_color != NULL &&
- (flags & EXPAND_FLAG_LASTCOLOR_ARG) == 0) {
+ if ((flags & EXPAND_FLAG_LASTCOLOR_ARG) == 0) {
/* save the last color */
- *save_last_color = last_color;
+ if (save_last_fg != NULL)
+ *save_last_fg = last_fg;
+ if (save_last_bg != NULL)
+ *save_last_bg = last_bg;
}
ret = str->str;
@@ -356,18 +389,23 @@ static char *theme_format_expand_data(THEME_REC *theme,
return ret;
}
+#define IS_OLD_FORMAT(code, last_fg, last_bg) \
+ (((code) == 'n' && (last_fg) == 'n' && (last_bg) == 'n') || \
+ ((code) != 'n' && ((code) == (last_fg) || (code) == (last_bg))))
+
static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
{
GString *str;
- char *ret, last_color = 'n';
+ char *ret, last_fg, last_bg;
str = g_string_new(NULL);
+ last_fg = last_bg = 'n';
while (*format != '\0') {
if (*format == '$') {
/* $variable, skrip it entirely */
theme_format_append_variable(str, &format);
- last_color = '\0';
+ last_fg = last_bg = '\0';
} else if (*format != '%') {
/* a normal character */
g_string_append_c(str, *format);
@@ -375,19 +413,24 @@ static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
} else {
/* %format */
format++;
- if (*format == last_color) {
+ if (IS_OLD_FORMAT(*format, last_fg, last_bg)) {
/* active color set again */
- } else if (IS_COLOR_FORMAT(*format) &&
+ } else if (IS_FGCOLOR_FORMAT(*format) &&
+ (*format != 'n' || format[2] == 'n') &&
format[1] == '%' &&
- IS_COLOR_FORMAT(format[2])) {
- /* two colors in a row */
+ IS_FGCOLOR_FORMAT(format[2])) {
+ /* two fg colors in a row. bg colors are
+ so rare that we don't bother checking
+ them */
} else {
/* some format, add it */
g_string_append_c(str, '%');
g_string_append_c(str, *format);
- if (IS_COLOR_FORMAT(*format))
- last_color = *format;
+ if (IS_FGCOLOR_FORMAT(*format))
+ last_fg = *format;
+ if (IS_BGCOLOR_FORMAT(*format))
+ last_bg = *format;
}
format++;
}
@@ -398,16 +441,16 @@ static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
return ret;
}
-static char *theme_format_expand(THEME_REC *theme, const char *format)
+char *theme_format_expand(THEME_REC *theme, const char *format)
{
char *data, *ret;
g_return_val_if_fail(theme != NULL, NULL);
g_return_val_if_fail(format != NULL, NULL);
- data = theme_format_expand_data(theme, &format, 'n', NULL,
+ data = theme_format_expand_data(theme, &format, 'n', 'n', NULL, NULL,
EXPAND_FLAG_ROOT);
- ret = theme_format_compress_colors(theme, data);
+ ret = theme_format_compress_colors(theme, data);
g_free(data);
return ret;
}
@@ -438,20 +481,28 @@ static void theme_read_replaces(CONFIG_REC *config, THEME_REC *theme)
{
GSList *tmp;
CONFIG_NODE *node;
+ const char *p;
+ int index;
node = config_node_traverse(config, "replaces", FALSE);
if (node == NULL || node->type != NODE_TYPE_BLOCK) return;
+ /* reset replace keys */
+ for (index = 0; index < 256; index++)
+ theme->replace_keys[index] = -1;
+ index = 0;
+
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
node = tmp->data;
if (node->key != NULL && node->value != NULL) {
- theme->replace_keys =
- g_slist_append(theme->replace_keys,
- g_strdup(node->key));
+ for (p = node->key; *p != '\0'; p++)
+ theme->replace_keys[(int) *p] = index;
+
theme->replace_values =
g_slist_append(theme->replace_values,
g_strdup(node->value));
+ index++;
}
}
}
@@ -460,6 +511,7 @@ static void theme_read_abstracts(CONFIG_REC *config, THEME_REC *theme)
{
GSList *tmp;
CONFIG_NODE *node;
+ gpointer oldkey, oldvalue;
node = config_node_traverse(config, "abstracts", FALSE);
if (node == NULL || node->type != NODE_TYPE_BLOCK) return;
@@ -467,12 +519,19 @@ static void theme_read_abstracts(CONFIG_REC *config, THEME_REC *theme)
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
node = tmp->data;
- if (node->key != NULL && node->value != NULL &&
- g_hash_table_lookup(theme->abstracts, node->key) == NULL) {
- g_hash_table_insert(theme->abstracts,
- g_strdup(node->key),
- g_strdup(node->value));
+ if (node->key == NULL || node->value == NULL)
+ continue;
+
+ if (g_hash_table_lookup_extended(theme->abstracts, node->key,
+ &oldkey, &oldvalue)) {
+ /* new values override old ones */
+ g_hash_table_remove(theme->abstracts, oldkey);
+ g_free(oldkey);
+ g_free(oldvalue);
}
+
+ g_hash_table_insert(theme->abstracts, g_strdup(node->key),
+ g_strdup(node->value));
}
}
@@ -742,7 +801,17 @@ static int theme_read(THEME_REC *theme, const char *path, const char *data)
config_get_int(config, NULL, "default_color", 0);
theme->default_real_color =
config_get_int(config, NULL, "default_real_color", 7);
- theme_read_replaces(config, theme);
+ theme_read_replaces(config, theme);
+
+ if (data == NULL) {
+ /* get the default abstracts from default theme. */
+ CONFIG_REC *default_config;
+
+ default_config = config_open(NULL, -1);
+ config_parse_data(default_config, default_theme, "internal");
+ theme_read_abstracts(default_config, theme);
+ config_close(default_config);
+ }
theme_read_abstracts(config, theme);
rec.theme = theme;
diff --git a/src/fe-common/core/themes.h b/src/fe-common/core/themes.h
index d1e0283f..96f23400 100644
--- a/src/fe-common/core/themes.h
+++ b/src/fe-common/core/themes.h
@@ -23,7 +23,7 @@ typedef struct {
wanted. default is 7 (white). */
GHashTable *modules;
- GSList *replace_keys;
+ int replace_keys[256]; /* index to replace_values for each char */
GSList *replace_values;
GHashTable *abstracts;
@@ -46,6 +46,19 @@ THEME_REC *theme_load(const char *name);
void theme_register_module(const char *module, FORMAT_REC *formats);
void theme_unregister_module(const char *module);
+#define EXPAND_FLAG_IGNORE_REPLACES 0x01 /* don't use the character replaces when expanding */
+#define EXPAND_FLAG_IGNORE_EMPTY 0x02 /* if abstract's argument is empty, don't try to expand it (ie. {xx }, but not {xx}) */
+#define EXPAND_FLAG_RECURSIVE_MASK 0x0f
+/* private */
+#define EXPAND_FLAG_ROOT 0x10
+#define EXPAND_FLAG_LASTCOLOR_ARG 0x20
+
+char *theme_format_expand(THEME_REC *theme, const char *format);
+char *theme_format_expand_data(THEME_REC *theme, const char **format,
+ char default_fg, char default_bg,
+ char *save_last_fg, char *save_last_bg,
+ int flags);
+
void themes_init(void);
void themes_deinit(void);
diff --git a/src/fe-text/mainwindows.h b/src/fe-text/mainwindows.h
index 7eb4875b..88ff97e0 100644
--- a/src/fe-text/mainwindows.h
+++ b/src/fe-text/mainwindows.h
@@ -16,7 +16,7 @@ typedef struct {
int first_line, last_line, lines;
int statusbar_lines;
void *statusbar;
- void *statusbar_channel_item;
+ void *statusbar_window_item;
} MAIN_WINDOW_REC;
extern GSList *mainwindows;
diff --git a/src/fe-text/screen.c b/src/fe-text/screen.c
index 65f30bf9..86681d78 100644
--- a/src/fe-text/screen.c
+++ b/src/fe-text/screen.c
@@ -116,7 +116,11 @@ static void read_settings(void)
use_colors = settings_get_bool("colors");
read_signals();
- if (use_colors != old_colors) irssi_redraw();
+ if (use_colors && !has_colors())
+ use_colors = FALSE;
+
+ if (use_colors != old_colors)
+ irssi_redraw();
}
static int init_curses(void)
@@ -151,8 +155,8 @@ static int init_curses(void)
if (has_colors())
start_color();
- else
- use_colors = FALSE;
+ else if (use_colors)
+ use_colors = FALSE;
#ifdef HAVE_NCURSES_USE_DEFAULT_COLORS
/* this lets us to use the "default" background color for colors <= 7 so
diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c
index 2a91bb14..683ae81d 100644
--- a/src/fe-text/statusbar-items.c
+++ b/src/fe-text/statusbar-items.c
@@ -20,25 +20,14 @@
#include "module.h"
#include "signals.h"
-#include "servers.h"
#include "misc.h"
#include "settings.h"
#include "special-vars.h"
-#include "irc.h"
-#include "channels.h"
-#include "queries.h"
-#include "irc-servers.h"
-#include "nicklist.h"
-
-#include "fe-windows.h"
#include "window-items.h"
-#include "printtext.h"
#include "formats.h"
-#include "screen.h"
#include "statusbar.h"
-#include "gui-windows.h"
#include "gui-printtext.h"
/* how often to redraw lagging time (seconds) */
@@ -51,9 +40,6 @@
the lag */
#define MAX_LAG_UNKNOWN_TIME 30
-static int sbar_color_dim, sbar_color_normal, sbar_color_bold;
-static int sbar_color_background, sbar_color_away, sbar_color_act_highlight;
-
static STATUSBAR_REC *mainbar;
static MAIN_WINDOW_REC *mainbar_window;
static int use_colors;
@@ -67,7 +53,7 @@ static time_t clock_last;
static SBAR_ITEM_REC *nick_item;
/* channel */
-static SBAR_ITEM_REC *channel_item;
+static SBAR_ITEM_REC *window_item;
/* activity */
static SBAR_ITEM_REC *activity_item;
@@ -92,11 +78,11 @@ static SBAR_ITEM_REC *topic_item;
static STATUSBAR_REC *topic_bar;
static void item_default(SBAR_ITEM_REC *item, int get_size_only,
- const char *str)
+ const char *str, const char *data)
{
SERVER_REC *server;
- WI_ITEM_REC *wiitem;
- char *stripped, *parsed, *printstr;
+ WI_ITEM_REC *wiitem;
+ char *tmpstr, *tmpstr2;
int len;
if (active_win == NULL) {
@@ -107,31 +93,44 @@ static void item_default(SBAR_ITEM_REC *item, int get_size_only,
wiitem = active_win->active;
}
- parsed = parse_special_string(str, server, wiitem, "", NULL,
+ /* expand $variables */
+ tmpstr = parse_special_string(str, server, wiitem, data, NULL,
PARSE_FLAG_ESCAPE_VARS);
- stripped = strip_codes(parsed);
- g_free(parsed); parsed = stripped;
+
+ /* expand templates */
+ str = tmpstr;
+ tmpstr2 = theme_format_expand_data(current_theme, &str,
+ 'n', '0' + item->bar->color,
+ NULL, NULL,
+ EXPAND_FLAG_ROOT |
+ EXPAND_FLAG_IGNORE_REPLACES |
+ EXPAND_FLAG_IGNORE_EMPTY);
+ g_free(tmpstr);
+
+ /* remove color codes */
+ tmpstr = strip_codes(tmpstr2);
+ g_free(tmpstr2);
if (get_size_only) {
- item->min_size = item->max_size = format_get_length(parsed);
+ item->min_size = item->max_size = format_get_length(tmpstr);
} else {
if (item->size < item->min_size) {
/* they're forcing us smaller than minimum size.. */
- len = format_real_length(parsed, item->size);
- parsed[len] = '\0';
+ len = format_real_length(tmpstr, item->size);
+ tmpstr[len] = '\0';
}
- printstr = g_strconcat("%n%4", parsed, NULL);
- gui_printtext(item->xpos, item->bar->ypos, printstr);
- g_free(printstr);
+ tmpstr2 = g_strconcat(item->bar->color_string, tmpstr, NULL);
+ gui_printtext(item->xpos, item->bar->ypos, tmpstr2);
+ g_free(tmpstr2);
}
- g_free(parsed);
+ g_free(tmpstr);
}
/* redraw clock */
static void statusbar_clock(SBAR_ITEM_REC *item, int get_size_only)
{
- item_default(item, get_size_only, "%c[%w$Z%c]");
+ item_default(item, get_size_only, "{sb $Z}", "");
}
/* check if we need to redraw clock.. */
@@ -158,20 +157,8 @@ static int statusbar_clock_timeout(void)
/* redraw nick */
static void statusbar_nick(SBAR_ITEM_REC *item, int get_size_only)
{
- IRC_SERVER_REC *server;
- char *str, *usermode, *away;
-
- server = IRC_SERVER(active_win->active_server);
- usermode = server == NULL || server->usermode == NULL ||
- *server->usermode == '\0' ? "" :
- g_strdup_printf("(%%c+%%w%s)", server->usermode);
- away = server == NULL || !server->usermode_away ? "" :
- "(%GzZzZ%w)";
-
- str = g_strconcat("%c[%w$P$N", usermode, away, "%c]", NULL);
- item_default(item, get_size_only, str);
- g_free(str);
- if (*usermode != '\0') g_free(usermode);
+ item_default(item, get_size_only,
+ "{sb $P$N{sbmode $usermode}{sbaway $A}}", "");
}
static void sig_statusbar_nick_redraw(void)
@@ -179,52 +166,36 @@ static void sig_statusbar_nick_redraw(void)
statusbar_item_redraw(nick_item);
}
-/* redraw channel */
-static void statusbar_channel(SBAR_ITEM_REC *item, int get_size_only)
+/* redraw window */
+static void statusbar_window(SBAR_ITEM_REC *item, int get_size_only)
{
- SERVER_REC *server;
- CHANNEL_REC *channel;
- char *str, *tmp;
-
if (active_win->active != NULL) {
- /* channel/query */
- channel = CHANNEL(active_win->active);
- tmp = channel == NULL || channel->mode == NULL ||
- *channel->mode == '\0' ? "" :
- g_strdup_printf("(%%c+%%w%s)", channel->mode);
- str = g_strconcat("%c[%w$winref:$[.15]T", tmp, "%c]", NULL);
+ item_default(item, get_size_only,
+ "{sb $winref:$T{sbmode $M}}", "");
} else {
- /* empty window */
- server = active_win->active_server;
- tmp = server == NULL ? "" :
- g_strdup_printf(":%s (change with ^X)", server->tag);
- str = g_strconcat("%c[%w$winref", tmp, "%c]", NULL);
+ item_default(item, get_size_only,
+ "{sb $winref{sbservertag $tag}}", "");
}
-
- item_default(item, get_size_only, str);
-
- g_free(str);
- if (*tmp != '\0') g_free(tmp);
}
-static void sig_statusbar_channel_redraw(void)
+static void sig_statusbar_window_redraw(void)
{
- statusbar_item_redraw(channel_item);
+ statusbar_item_redraw(window_item);
}
-static void sig_statusbar_channel_redraw_window(WINDOW_REC *window)
+static void sig_statusbar_window_redraw_window(WINDOW_REC *window)
{
if (is_window_visible(window))
- statusbar_item_redraw(channel_item);
+ statusbar_item_redraw(window_item);
}
-static void sig_statusbar_channel_redraw_window_item(WI_ITEM_REC *item)
+static void sig_statusbar_window_redraw_window_item(WI_ITEM_REC *item)
{
WINDOW_REC *window;
window = window_item_window(item);
if (window->active == item && is_window_visible(window))
- statusbar_item_redraw(channel_item);
+ statusbar_item_redraw(window_item);
}
static char *get_activity_list(int normal, int hilight)
@@ -281,8 +252,7 @@ static char *get_activity_list(int normal, int hilight)
act list so that the highest priority items comes first. */
static void statusbar_activity(SBAR_ITEM_REC *item, int get_size_only)
{
- GString *str;
- char *actlist, *detlist;
+ char *actlist, *detlist, *data;
if (use_colors) {
actlist = get_activity_list(TRUE, TRUE);
@@ -298,24 +268,13 @@ static void statusbar_activity(SBAR_ITEM_REC *item, int get_size_only)
return;
}
- str = g_string_new("%c[%w");
+ data = g_strconcat("{sbact ", actlist != NULL ? actlist : "",
+ " ", detlist != NULL ? detlist : "", "}", NULL);
+ item_default(item, get_size_only, data, "");
+ g_free(data);
- if (actlist != NULL) {
- g_string_append(str, "Act: ");
- g_string_append(str, actlist);
- g_free(actlist);
- }
- if (detlist != NULL) {
- if (actlist != NULL)
- g_string_append(str, " ");
- g_string_append(str, "Det: ");
- g_string_append(str, detlist);
- g_free(detlist);
- }
-
- g_string_append(str, "%c]");
- item_default(item, get_size_only, str->str);
- g_string_free(str, TRUE);
+ g_free_not_null(actlist);
+ g_free_not_null(detlist);
}
static void sig_statusbar_activity_hilight(WINDOW_REC *window, gpointer oldlevel)
@@ -387,7 +346,7 @@ static void sig_statusbar_activity_updated(void)
/* redraw -- more -- */
static void statusbar_more(SBAR_ITEM_REC *item, int get_size_only)
{
- item_default(item, get_size_only, "%_-- more --%_");
+ item_default(item, get_size_only, "{sbmore}", "");
}
static void sig_statusbar_more_check_remove(WINDOW_REC *window)
@@ -435,7 +394,7 @@ static void statusbar_lag(SBAR_ITEM_REC *item, int get_size_only)
}
now = time(NULL);
- str = g_string_new("%c[%wLag: %_");
+ str = g_string_new(NULL);
/* FIXME: ugly ugly.. */
if (server->lag_sent == 0 || now-server->lag_sent < 5) {
@@ -443,8 +402,7 @@ static void statusbar_lag(SBAR_ITEM_REC *item, int get_size_only)
MAX_LAG_UNKNOWN_TIME+settings_get_int("lag_check_time");
if (lag_min_show < 0 || (server->lag < lag_min_show && !lag_unknown)) {
- /* small, lag, don't display */
- g_string_truncate(str, 0);
+ /* small lag, don't display */
} else {
g_string_sprintfa(str, "%d.%02d", server->lag/1000,
(server->lag % 1000)/10);
@@ -457,10 +415,7 @@ static void statusbar_lag(SBAR_ITEM_REC *item, int get_size_only)
(long) (now-server->lag_sent));
}
- if (str->len > 0)
- g_string_append(str, "%c]");
-
- item_default(item, get_size_only, str->str);
+ item_default(item, get_size_only, "{sblag $0-}", str->str);
g_string_free(str, TRUE);
}
@@ -531,7 +486,7 @@ static int get_mail_count(void)
static void statusbar_mail(SBAR_ITEM_REC *item, int get_size_only)
{
- char countstr[MAX_INT_STRLEN], *str;
+ char countstr[MAX_INT_STRLEN];
int mail_count;
mail_count = settings_get_bool("mail_counter") ? get_mail_count() : 0;
@@ -543,10 +498,7 @@ static void statusbar_mail(SBAR_ITEM_REC *item, int get_size_only)
}
ltoa(countstr, mail_count);
- str = g_strconcat("%c[%wMail: %_", countstr, "%_%c]", NULL);
-
- item_default(item, get_size_only, str);
- g_free(str);
+ item_default(item, get_size_only, "{sbmail $0-}", countstr);
}
static int statusbar_mail_timeout(void)
@@ -557,7 +509,7 @@ static int statusbar_mail_timeout(void)
static void statusbar_topic(SBAR_ITEM_REC *item, int get_size_only)
{
- item_default(item, get_size_only, "$topic");
+ item_default(item, get_size_only, "$topic", "");
}
static void sig_statusbar_topic_redraw(void)
@@ -572,8 +524,8 @@ static void sig_sidebars_redraw(void)
for (tmp = mainwindows; tmp != NULL; tmp = tmp->next) {
MAIN_WINDOW_REC *rec = tmp->data;
- if (rec->statusbar_channel_item != NULL)
- statusbar_item_redraw(rec->statusbar_channel_item);
+ if (rec->statusbar_window_item != NULL)
+ statusbar_item_redraw(rec->statusbar_window_item);
}
}
@@ -612,7 +564,7 @@ static void mainbar_remove_items(void)
{
statusbar_item_remove(clock_item);
statusbar_item_remove(nick_item);
- statusbar_item_remove(channel_item);
+ statusbar_item_remove(window_item);
statusbar_item_remove(mail_item);
statusbar_item_remove(lag_item);
statusbar_item_remove(activity_item);
@@ -625,7 +577,7 @@ static void mainbar_add_items(MAIN_WINDOW_REC *window)
clock_item = statusbar_item_create(mainbar, SBAR_PRIORITY_HIGH, FALSE, statusbar_clock);
nick_item = statusbar_item_create(mainbar, SBAR_PRIORITY_NORMAL, FALSE, statusbar_nick);
- channel_item = statusbar_item_create(mainbar, SBAR_PRIORITY_NORMAL, FALSE, statusbar_channel);
+ window_item = statusbar_item_create(mainbar, SBAR_PRIORITY_NORMAL, FALSE, statusbar_window);
mail_item = statusbar_item_create(mainbar, SBAR_PRIORITY_LOW, FALSE, statusbar_mail);
lag_item = statusbar_item_create(mainbar, SBAR_PRIORITY_LOW, FALSE, statusbar_lag);
activity_item = statusbar_item_create(mainbar, SBAR_PRIORITY_HIGH, FALSE, statusbar_activity);
@@ -633,15 +585,15 @@ static void mainbar_add_items(MAIN_WINDOW_REC *window)
static void sidebar_add_items(MAIN_WINDOW_REC *window)
{
- window->statusbar_channel_item =
- statusbar_item_create(window->statusbar, SBAR_PRIORITY_NORMAL, FALSE, statusbar_channel);
+ window->statusbar_window_item =
+ statusbar_item_create(window->statusbar, SBAR_PRIORITY_NORMAL, FALSE, statusbar_window);
}
static void sidebar_remove_items(MAIN_WINDOW_REC *window)
{
- if (window->statusbar_channel_item != NULL) {
- statusbar_item_remove(window->statusbar_channel_item);
- window->statusbar_channel_item = NULL;
+ if (window->statusbar_window_item != NULL) {
+ statusbar_item_remove(window->statusbar_window_item);
+ window->statusbar_window_item = NULL;
}
}
@@ -683,25 +635,13 @@ static void sig_main_statusbar_changed(WINDOW_REC *window)
static void read_settings(void)
{
- use_colors = settings_get_bool("colors");
+ use_colors = settings_get_bool("colors") && has_colors();
if (settings_get_bool("topicbar"))
topicbar_create();
else if (!settings_get_bool("topicbar"))
topicbar_destroy();
lag_min_show = settings_get_int("lag_min_show")*10;
-
- sbar_color_background = settings_get_int("statusbar_background") << 4;
- sbar_color_dim = sbar_color_background |
- settings_get_int("statusbar_dim");
- sbar_color_normal = sbar_color_background |
- settings_get_int("statusbar_normal");
- sbar_color_bold = sbar_color_background |
- settings_get_int("statusbar_bold");
- sbar_color_away = sbar_color_background |
- settings_get_int("statusbar_away");
- sbar_color_act_highlight = sbar_color_background |
- settings_get_int("statusbar_act_highlight");
statusbar_redraw(NULL);
}
@@ -714,13 +654,6 @@ void statusbar_items_init(void)
settings_add_bool("lookandfeel", "actlist_moves", FALSE);
settings_add_bool("misc", "mail_counter", TRUE);
- settings_add_int("colors", "statusbar_background", 1);
- settings_add_int("colors", "statusbar_dim", 3);
- settings_add_int("colors", "statusbar_normal", 7);
- settings_add_int("colors", "statusbar_bold", 15);
- settings_add_int("colors", "statusbar_away", 10);
- settings_add_int("colors", "statusbar_act_highlight", 13);
-
/* clock */
clock_timetag = g_timeout_add(1000, (GSourceFunc) statusbar_clock_timeout, NULL);
@@ -736,11 +669,11 @@ void statusbar_items_init(void)
signal_add("away mode changed", (SIGNAL_FUNC) sig_statusbar_nick_redraw);
/* channel */
- signal_add("window changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw);
- signal_add("window item changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window);
- signal_add("channel mode changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window_item);
- signal_add("window server changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window);
- signal_add("window refnum changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window);
+ signal_add("window changed", (SIGNAL_FUNC) sig_statusbar_window_redraw);
+ signal_add("window item changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window);
+ signal_add("channel mode changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window_item);
+ signal_add("window server changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window);
+ signal_add("window refnum changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window);
/* activity */
activity_list = NULL;
@@ -798,11 +731,11 @@ void statusbar_items_deinit(void)
signal_remove("away mode changed", (SIGNAL_FUNC) sig_statusbar_nick_redraw);
/* channel */
- signal_remove("window changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw);
- signal_remove("window item changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window);
- signal_remove("channel mode changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window_item);
- signal_remove("window server changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window);
- signal_remove("window refnum changed", (SIGNAL_FUNC) sig_statusbar_channel_redraw_window);
+ signal_remove("window changed", (SIGNAL_FUNC) sig_statusbar_window_redraw);
+ signal_remove("window item changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window);
+ signal_remove("channel mode changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window_item);
+ signal_remove("window server changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window);
+ signal_remove("window refnum changed", (SIGNAL_FUNC) sig_statusbar_window_redraw_window);
/* activity */
signal_remove("window activity", (SIGNAL_FUNC) sig_statusbar_activity_hilight);
diff --git a/src/fe-text/statusbar.c b/src/fe-text/statusbar.c
index ca019e97..4299835a 100644
--- a/src/fe-text/statusbar.c
+++ b/src/fe-text/statusbar.c
@@ -21,14 +21,16 @@
#include "module.h"
#include "signals.h"
#include "servers.h"
-#include "settings.h"
#include "fe-windows.h"
+#include "themes.h"
#include "screen.h"
#include "statusbar.h"
#include "gui-windows.h"
+static int backs[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; /* FIXME: should be in some more generic place.. */
+
void statusbar_items_init(void);
void statusbar_items_deinit(void);
@@ -190,7 +192,7 @@ void statusbar_redraw(STATUSBAR_REC *bar)
return;
}
- set_bg(stdscr, settings_get_int("statusbar_background") << 4);
+ set_bg(stdscr, backs[bar->color] << 4);
move(bar->ypos, 0); clrtoeol();
set_bg(stdscr, 0);
@@ -212,10 +214,27 @@ void statusbar_item_redraw(SBAR_ITEM_REC *item)
}
}
+static int get_last_bg(const char *str)
+{
+ int last = -1;
+
+ while (*str != '\0') {
+ if (*str == '%' && str[1] != '\0') {
+ str++;
+ if (*str >= '0' && *str <= '7')
+ last = *str-'0';
+ }
+ str++;
+ }
+
+ return last;
+}
+
/* ypos is used only when pos == STATUSBAR_POS_MIDDLE */
STATUSBAR_REC *statusbar_create(int pos, int ypos)
{
STATUSBAR_REC *rec;
+ char *str;
rec = g_new0(STATUSBAR_REC, 1);
statusbars = g_slist_append(statusbars, rec);
@@ -226,6 +245,15 @@ STATUSBAR_REC *statusbar_create(int pos, int ypos)
rec->ypos = pos == STATUSBAR_POS_MIDDLE ? ypos :
pos == STATUSBAR_POS_UP ? rec->line : LINES-1-rec->line;
+ /* get background color from sb_background abstract */
+ str = theme_format_expand(current_theme, "{sb_background}");
+ if (str == NULL) str = g_strdup("%n%8");
+ rec->color_string = g_strconcat("%n", str, NULL);
+ g_free(str);
+
+ rec->color = get_last_bg(rec->color_string);
+ if (rec->color < 0) rec->color = current_theme->default_real_color;
+
if (pos == STATUSBAR_POS_UP) {
if (sbars_up == 0) sbar_uppest = rec->line;
sbars_up++;
@@ -236,7 +264,7 @@ STATUSBAR_REC *statusbar_create(int pos, int ypos)
rec->line -= sbar_lowest;
}
- set_bg(stdscr, settings_get_int("statusbar_background") << 4);
+ set_bg(stdscr, backs[rec->color] << 4);
move(rec->ypos, 0); clrtoeol();
set_bg(stdscr, 0);
@@ -273,6 +301,7 @@ void statusbar_destroy(STATUSBAR_REC *bar)
if (bar->pos != STATUSBAR_POS_MIDDLE)
statusbars_pack(bar->pos, bar->pos);
+ g_free(bar->color_string);
g_free(bar);
if (!quitting) statusbar_redraw_all();
diff --git a/src/fe-text/statusbar.h b/src/fe-text/statusbar.h
index 5aa4da31..5a00eaa7 100644
--- a/src/fe-text/statusbar.h
+++ b/src/fe-text/statusbar.h
@@ -18,6 +18,9 @@ typedef struct {
int pos;
int line;
+ char *color_string;
+ int color;
+
int ypos; /* real position in screen at the moment */
GSList *items;
} STATUSBAR_REC;