/* View types */
typedef struct window_t window_t;
+typedef struct watch_t watch_t;
typedef struct window_t {
char *name;
window_t *next;
} window_t;
+typedef struct watch_t {
+ char *name;
+ char desc[512];
+ reg_t regex;
+ short color;
+ watch_t *next;
+} watch_t;
+
typedef struct {
const char *value;
const char *desc;
static int date;
static int draw;
static int view;
-static reg_t watch;
static char cmd_buf[4096];
static int cmd_pos;
static window_t *focus;
static window_t *windows;
+static watch_t *watches;
+
static int ncolors = 1;
static short colors[256+1][256+1];
static short color_title;
static short color_date;
-static short color_watch;
static short color_error;
static const char *themes[][2] = {
};
static const char *abbrevs[][2] = {
- [ABBREV_NONE] { "none", "Do not abbreivate" },
+ [ABBREV_NONE] { "none", "Do not abbreviate" },
[ABBREV_FIRST] { "first", "First name only" },
[ABBREV_LAST] { "last", "Last name only" },
[ABBREV_FLAST] { "flast", "First initial last name" },
return 0;
if (win->channel && win->channel != msg->channel)
return 0;
- if (reg_match(&win->filter, msg->channel->name))
+ if (!reg_match(&win->filter, msg->channel->name))
return 0;
return 1;
}
return NULL;
}
+/* Watch functions */
+static watch_t *add_watch(const char *name)
+{
+ watch_t *watch = new0(watch_t);
+ strset(&watch->name, name);
+
+ watch_t **last = &watches;
+ while (*last)
+ last = &(*last)->next;
+ *last = watch;
+ return watch;
+}
+
+static watch_t *find_watch(const char *name)
+{
+ for (watch_t *watch = watches; watch; watch = watch->next)
+ if (match(watch->name, name))
+ return watch;
+ return NULL;
+}
+
+static void set_watch(const char *text)
+{
+ static char name[64];
+ static char regex[512];
+ static int color;
+ sscanf(text, "%s %d %[^\n]", name, &color, regex);
+
+ watch_t *watch = find_watch(name);
+ if (!watch)
+ watch = add_watch(name);
+ reg_set(&watch->regex, regex, MATCHES);
+ watch->color = color;
+}
+
+static void watch_run(const char *text)
+{
+ for (watch_t *watch = watches; watch; watch = watch->next)
+ reg_match(&watch->regex, text);
+}
+
+static void watch_end(void)
+{
+ for (watch_t *watch = watches; watch; watch = watch->next)
+ watch->regex.count = 0;
+}
+
+static void watch_on(int pos)
+{
+ for (watch_t *watch = watches; watch; watch = watch->next)
+ if (reg_check(&watch->regex, pos) & MATCH_START)
+ attron(color(watch->color, -1) | A_BOLD);
+}
+
+static void watch_off(int pos)
+{
+ for (watch_t *watch = watches; watch; watch = watch->next)
+ if (reg_check(&watch->regex, pos) & MATCH_STOP)
+ attroff(color(watch->color, -1) | A_BOLD);
+}
+
/* Print functions */
static int word_wrap(printer_t *pr, const char *txt,
const char **l, const char **r)
pr->prow = pr->row;
pr->pcol = pr->col;
}
- if (reg_check(&watch, i) & MATCH_START)
- attron(color_watch | A_BOLD);
+ watch_on(i);
if (irc_color(txt, &i))
continue;
switch (txt[i]) {
pr->col += 1;
break;
}
- if (reg_check(&watch, i) & MATCH_STOP)
- attroff(color_watch | A_BOLD);
+ watch_off(i);
}
if (i <= pr->pick) {
pr->prow = pr->row;
}
/* Set matches */
- reg_match(&watch, msg->text);
+ watch_run(msg->text);
/* Print message */
pr->indent = pr->col;
pr->row++;
/* Clear matches */
- watch.count = 0;
+ watch_end();
}
static void print_status(printer_t *pr)
else if (prefix(text, "/channel ", &arg)) {
complete_channel(arg);
}
+ else if (prefix(text, "/watch ", &arg)) {
+ complete_watch(arg);
+ }
else {
complete_args(text,
"/quit", "Quit the program",
if (match(abbrevs[i][0], arg))
abbrev = i;
}
- else if (prefix(text, "/watch", &arg)) {
- reg_set(&watch, arg, MATCHES);
+ else if (prefix(text, "/watch", &arg) && arg) {
+ set_watch(arg);
}
else if (prefix(text, "/open", &arg)) {
win = find_window(arg ?: focus->dest->name);
color_title = color(COLOR_WHITE, COLOR_BLUE);
color_date = color(COLOR_BROWN, -1);
- color_watch = color(COLOR_RED, -1);
color_error = color(COLOR_RED, -1);
/* Create signal FD */
void view_config(const char *group, const char *name, const char *key, const char *value)
{
window_t *win;
+ watch_t *watch;
if (match(group, "general")) {
if (match(key, "theme"))
abbrev = get_mapv(value, abbrevs);
else if (match(key, "defocus"))
defocus = get_number(value);
- else if (match(key, "watch"))
- reg_set(&watch, get_string(value), MATCHES);
}
if (match(group, "window")) {
reg_set(&win->filter, get_string(value), 0);
}
}
+
+ if (match(group, "watch")) {
+ watch = find_watch(name);
+ if (match(key, "")) {
+ watch = add_watch(get_name(name));
+ }
+ else if (match(key, "regex")) {
+ reg_set(&watch->regex, get_string(value), MATCHES);
+ }
+ else if (match(key, "color")) {
+ watch->color = get_number(value);
+ }
+ }
}
/* View event */
add_item(prefix, cur->name, NULL);
}
+void complete_watch(const char *prefix)
+{
+ for (watch_t *cur = watches; cur; cur = cur->next) {
+ if (starts(prefix, cur->name)) {
+ snprintf(cur->desc, sizeof(cur->desc),
+ "%s %hd %s",
+ cur->name,
+ cur->color,
+ cur->regex.pattern);
+ add_item(prefix, cur->desc, NULL);
+ }
+ }
+}
+
void complete_array(const char *prefix, const char *list[][2], int n)
{
for (int i = 0; i < n; i++)