aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c73
1 files changed, 65 insertions, 8 deletions
diff --git a/degesch.c b/degesch.c
index a3dd2b6..f6827ed 100644
--- a/degesch.c
+++ b/degesch.c
@@ -29,6 +29,7 @@
#define ATTR_EXTERNAL "attr_external"
#define ATTR_TIMESTAMP "attr_timestamp"
+#define ATTR_HIGHLIGHT "attr_highlight"
#define ATTR_ACTION "attr_action"
#define ATTR_JOIN "attr_join"
#define ATTR_PART "attr_part"
@@ -95,6 +96,7 @@ static struct config_item g_config_table[] =
{ ATTR_EXTERNAL, NULL, "Terminal attributes for external lines" },
{ ATTR_TIMESTAMP, NULL, "Terminal attributes for timestamps" },
+ { ATTR_HIGHLIGHT, NULL, "Terminal attributes for highlights" },
{ ATTR_ACTION, NULL, "Terminal attributes for user actions" },
{ ATTR_JOIN, NULL, "Terminal attributes for joins" },
{ ATTR_PART, NULL, "Terminal attributes for parts" },
@@ -789,6 +791,13 @@ init_colors (struct app_context *ctx)
INIT_ATTR (ATTR_JOIN, g_terminal.color_set_fg[2], "\x1b[32m");
INIT_ATTR (ATTR_PART, g_terminal.color_set_fg[1], "\x1b[31m");
+ char *highlight = xstrdup_printf ("%s%s%s",
+ g_terminal.color_set_fg[3],
+ g_terminal.color_set_bg[5],
+ enter_bold_mode);
+ INIT_ATTR (ATTR_HIGHLIGHT, highlight, "\x1b[33;37;1m");
+ free (highlight);
+
#undef INIT_ATTR
switch (ctx->color_mode)
@@ -1231,16 +1240,26 @@ buffer_line_display (struct app_context *ctx,
switch (line->type)
{
case BUFFER_LINE_PRIVMSG:
- formatter_add (&f, "<#c#s#r> #s", nick_color, nick, a->text);
+ if (line->flags & BUFFER_LINE_HIGHLIGHT)
+ formatter_add (&f, "#a<#s>#r #s", ATTR_HIGHLIGHT, nick, a->text);
+ else
+ formatter_add (&f, "<#c#s#r> #s", nick_color, nick, a->text);
break;
case BUFFER_LINE_ACTION:
- formatter_add (&f, " #a*#r ", ATTR_ACTION);
+ if (line->flags & BUFFER_LINE_HIGHLIGHT)
+ formatter_add (&f, " #a*#r ", ATTR_HIGHLIGHT);
+ else
+ formatter_add (&f, " #a*#r ", ATTR_ACTION);
formatter_add (&f, "#c#s#r #s", nick_color, nick, a->text);
break;
case BUFFER_LINE_NOTICE:
formatter_add (&f, " - ");
- formatter_add (&f, "#s(#c#s#r): #s",
- "Notice", nick_color, nick, a->text);
+ if (line->flags & BUFFER_LINE_HIGHLIGHT)
+ formatter_add (&f, "#a#s(#s)#r: #s",
+ ATTR_HIGHLIGHT, "Notice", nick, a->text);
+ else
+ formatter_add (&f, "#s(#c#s#r): #s",
+ "Notice", nick_color, nick, a->text);
break;
case BUFFER_LINE_JOIN:
formatter_add (&f, "#a-->#r ", ATTR_JOIN);
@@ -2441,6 +2460,38 @@ irc_get_buffer_for_message (struct app_context *ctx,
return buffer;
}
+static bool
+irc_is_highlight (struct app_context *ctx, const char *message)
+{
+ // Well, this is rather crude but it should make most users happy.
+ // Ideally we could do this at least in proper Unicode.
+ char *copy = xstrdup (message);
+ for (char *p = copy; *p; p++)
+ *p = irc_tolower (*p);
+
+ char *nick = xstrdup (ctx->irc_user->nickname);
+ for (char *p = nick; *p; p++)
+ *p = irc_tolower (*p);
+
+ // Special characters allowed in nicknames by RFC 2812: []\`_^{|} and -
+ // Also excluded from the ASCII: common user channel prefixes: +%@&~
+ const char *delimiters = ",.;:!?()<>/=#$* \t\r\n\v\f\"'";
+
+ bool result = false;
+ char *save = NULL;
+ for (char *token = strtok_r (copy, delimiters, &save);
+ token; token = strtok_r (NULL, delimiters, &save))
+ if (!strcmp (token, nick))
+ {
+ result = true;
+ break;
+ }
+
+ free (copy);
+ free (nick);
+ return result;
+}
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void
@@ -2651,8 +2702,11 @@ irc_handle_notice_text (struct app_context *ctx,
if (buffer)
{
- // TODO: highlights
- buffer_send (ctx, buffer, BUFFER_LINE_NOTICE, 0,
+ // TODO: some more obvious indication of highlights
+ int flags = irc_is_highlight (ctx, text->str)
+ ? BUFFER_LINE_HIGHLIGHT
+ : 0;
+ buffer_send (ctx, buffer, BUFFER_LINE_NOTICE, flags,
.who = irc_to_utf8 (ctx, msg->prefix),
.text = irc_to_utf8 (ctx, text->str));
}
@@ -2812,11 +2866,14 @@ irc_handle_privmsg_text (struct app_context *ctx,
if (buffer)
{
- // TODO: highlights
+ // TODO: some more obvious indication of highlights
+ int flags = irc_is_highlight (ctx, text->str)
+ ? BUFFER_LINE_HIGHLIGHT
+ : 0;
enum buffer_line_type type = is_action
? BUFFER_LINE_ACTION
: BUFFER_LINE_PRIVMSG;
- buffer_send (ctx, buffer, type, 0,
+ buffer_send (ctx, buffer, type, flags,
.who = irc_to_utf8 (ctx, msg->prefix),
.text = irc_to_utf8 (ctx, text->str));
}