degesch: distinguish lines from other buffers

This commit is contained in:
Přemysl Eric Janouch 2015-04-26 18:39:38 +02:00
parent 950d64d229
commit 224073d3b2

View File

@ -27,6 +27,7 @@
#define ATTR_WARNING "attr_warning"
#define ATTR_ERROR "attr_error"
#define ATTR_EXTERNAL "attr_external"
#define ATTR_TIMESTAMP "attr_timestamp"
#define ATTR_ACTION "attr_action"
#define ATTR_JOIN "attr_join"
@ -91,6 +92,7 @@ static struct config_item g_config_table[] =
{ ATTR_WARNING, NULL, "Terminal attributes for warnings" },
{ ATTR_ERROR, NULL, "Terminal attributes for errors" },
{ ATTR_EXTERNAL, NULL, "Terminal attributes for external lines" },
{ ATTR_TIMESTAMP, NULL, "Terminal attributes for timestamps" },
{ ATTR_ACTION, NULL, "Terminal attributes for user actions" },
{ ATTR_JOIN, NULL, "Terminal attributes for joins" },
@ -768,6 +770,7 @@ init_colors (struct app_context *ctx)
INIT_ATTR (ATTR_WARNING, g_terminal.color_set_fg[3], "\x1b[33m");
INIT_ATTR (ATTR_ERROR, g_terminal.color_set_fg[1], "\x1b[31m");
INIT_ATTR (ATTR_EXTERNAL, g_terminal.color_set_fg[7], "\x1b[37m");
INIT_ATTR (ATTR_TIMESTAMP, g_terminal.color_set_fg[7], "\x1b[37m");
INIT_ATTR (ATTR_ACTION, g_terminal.color_set_fg[1], "\x1b[31m");
INIT_ATTR (ATTR_JOIN, g_terminal.color_set_fg[2], "\x1b[32m");
@ -910,6 +913,7 @@ formatter_item_destroy (struct formatter_item *self)
struct formatter
{
struct app_context *ctx; ///< Application context
bool ignore_new_attributes; ///< Whether to ignore new attributes
struct formatter_item *items; ///< Items
struct formatter_item *items_tail; ///< Tail of items
@ -937,22 +941,6 @@ formatter_add_blank (struct formatter *self)
return item;
}
static void
formatter_add_attr (struct formatter *self, const char *attr_name)
{
struct formatter_item *item = formatter_add_blank (self);
item->type = FORMATTER_ITEM_ATTR;
item->data = xstrdup (str_map_find (&self->ctx->config, attr_name));
}
static void
formatter_add_reset (struct formatter *self)
{
struct formatter_item *item = formatter_add_blank (self);
item->type = FORMATTER_ITEM_ATTR;
item->data = NULL;
}
static void
formatter_add_text (struct formatter *self, const char *text)
{
@ -961,9 +949,34 @@ formatter_add_text (struct formatter *self, const char *text)
item->data = xstrdup (text);
}
static void
formatter_add_reset (struct formatter *self)
{
if (self->ignore_new_attributes)
return;
struct formatter_item *item = formatter_add_blank (self);
item->type = FORMATTER_ITEM_ATTR;
item->data = NULL;
}
static void
formatter_add_attr (struct formatter *self, const char *attr_name)
{
if (self->ignore_new_attributes)
return;
struct formatter_item *item = formatter_add_blank (self);
item->type = FORMATTER_ITEM_ATTR;
item->data = xstrdup (str_map_find (&self->ctx->config, attr_name));
}
static void
formatter_add_fg_color (struct formatter *self, int color)
{
if (self->ignore_new_attributes)
return;
struct formatter_item *item = formatter_add_blank (self);
item->type = FORMATTER_ITEM_FG_COLOR;
item->color = color;
@ -972,6 +985,9 @@ formatter_add_fg_color (struct formatter *self, int color)
static void
formatter_add_bg_color (struct formatter *self, int color)
{
if (self->ignore_new_attributes)
return;
struct formatter_item *item = formatter_add_blank (self);
item->type = FORMATTER_ITEM_BG_COLOR;
item->color = color;
@ -1187,8 +1203,13 @@ buffer_line_display (struct app_context *ctx,
formatter_add (&f, "#a#02d:#02d:#02d#r ",
ATTR_TIMESTAMP, current.tm_hour, current.tm_min, current.tm_sec);
// TODO: when this comes from a different buffer (is_external),
// ignore all attributes and instead print it with ATTR_OTHER
// Ignore all formatting for messages coming from other buffers, that is
// either from the global or server buffer. Instead print them in grey.
if (is_external)
{
formatter_add (&f, "#a", ATTR_EXTERNAL);
f.ignore_new_attributes = true;
}
// TODO: try to decode as much as possible using mIRC formatting;
// could either add a #m format specifier, or write a separate function