#include "view.h"
/* View constants */
+#define MATCHES 16
+#define RE_MFLAGS (REG_EXTENDED)
#define RE_FLAGS (REG_EXTENDED|REG_NOSUB)
/* Extra colors */
int pick;
int prow;
int pcol;
+ int mcnt;
+ int mstart[MATCHES];
+ int mstop[MATCHES];
} printer_t;
typedef enum {
static int theme;
static int abbrev;
static int draw;
+static char *watch;
static char cmd_buf[4096];
static int cmd_pos;
static int sts_lines;
static int cmd_lines;
+static regex_t regex;
+
static server_t sys_srv;
static channel_t sys_chan;
static window_t sys_win;
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[] = {
return color(x, -1);
}
+static int match_all(const char *str, regex_t *preg, int *mstart, int *mstop)
+{
+ int si = 0, mi = 0;
+ regmatch_t pmatch = {};
+ while (mi < MATCHES && str[si] && !regexec(preg, &str[si], 1, &pmatch, 0)) {
+ mstart[mi] = si + pmatch.rm_so;
+ mstop[mi] = si + pmatch.rm_eo - 1;
+ si += pmatch.rm_eo;
+ mi += 1;
+ }
+ return mi;
+}
+
/* Window functions */
static int in_window(message_t *msg, window_t *win)
{
static void print_string(printer_t *pr, const char *txt)
{
int i, n;
+ int mi = 0;
wchar_t wc;
const char *l = 0, *r = 0;
pr->prow = pr->row;
pr->pcol = pr->col;
}
+ if (mi < pr->mcnt && i >= pr->mstart[mi])
+ attron(color_watch | A_BOLD);
if (irc_color(txt, &i))
continue;
switch (txt[i]) {
pr->col += 1;
break;
}
+ if (mi < pr->mcnt && i >= pr->mstop[mi]) {
+ attroff(color_watch | A_BOLD);
+ mi++;
+ }
}
if (i <= pr->pick) {
pr->prow = pr->row;
print_format(pr, "*** ");
}
+ /* Set matches */
+ if (watch)
+ pr->mcnt = match_all(msg->text, ®ex, pr->mstart, pr->mstop);
+
/* Print message */
pr->indent = pr->col;
print_string(pr, msg->text);
pr->row++;
+
+ /* Clear matches */
+ if (watch)
+ pr->mcnt = 0;
}
static void print_status(printer_t *pr)
if (match(abbrevs[i], arg))
abbrev = i;
}
+ else if (prefix(text, "/watch", &arg)) {
+ strset(&watch, arg);
+ if (watch)
+ regcomp(®ex, watch, RE_MFLAGS);
+ }
else if (match(text, "/open")) {
win = find_window(focus->dest->name);
if (!win || win == focus) {
/* View init */
void view_init(void)
{
+ /* General setup */
+ if (watch)
+ regcomp(®ex, watch, RE_MFLAGS);
+
/* System windows */
sys_srv.name = strcopy("system");
sys_srv.protocol = -1;
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 */
abbrev = get_map(value, abbrevs);
else if (match(key, "defocus"))
defocus = get_number(value);
+ else if (match(key, "watch"))
+ watch = get_string(value);
}
if (match(group, "window")) {