Example #1
0
static void
draw_view_line_search_result(struct view *view, unsigned int lineno)
{
	size_t bufsize = view->width * 4;
	char *buf = malloc(bufsize);
	regmatch_t pmatch[1];
	regoff_t bufpos = 0;

	if (!buf || mvwinnstr(view->win, lineno, 0, buf, bufsize) == ERR) {
		free(buf);
		return;
	}

	while (bufpos < bufsize && !regexec(view->regex, buf + bufpos, ARRAY_SIZE(pmatch), pmatch, 0)) {
		regoff_t start = pmatch[0].rm_so;
		regoff_t end = pmatch[0].rm_eo;

		if (start == -1 || end <= 0 || end <= start)
			continue;

		mvwchgat(view->win, lineno,
			 utf8_width_of(buf, bufpos + start, -1),
			 utf8_width_of(buf + bufpos + start, end - start, -1),
			 get_view_attr(view, LINE_SEARCH_RESULT),
			 get_view_color(view, LINE_SEARCH_RESULT),
			 NULL);

		bufpos += end;
	}

	free(buf);
}
Example #2
0
static void
draw_view_line_search_result(struct view *view, unsigned int lineno)
{
	size_t bufsize = view->width * 4;
	char *buf = malloc(bufsize);
	regmatch_t pmatch[1];
	int i;

	if (!buf || mvwinnstr(view->win, lineno, 0, buf, bufsize) == ERR ||
	    regexec(view->regex, buf, ARRAY_SIZE(pmatch), pmatch, 0)) {
		free(buf);
		return;
	}

	for (i = 0; i < ARRAY_SIZE(pmatch); i++) {
		regoff_t start = pmatch[i].rm_so;

		if (start == -1)
			continue;

		mvwchgat(view->win, lineno,
			 utf8_width_of(buf, start, -1),
			 utf8_width_of(buf + start, pmatch[i].rm_eo - start, -1),
			 get_view_attr(view, LINE_SEARCH_RESULT),
			 get_view_color(view, LINE_SEARCH_RESULT),
			 NULL);
	}

	free(buf);
}
Example #3
0
static inline void
set_view_attr(struct view *view, enum line_type type)
{
	if (!view->curline->selected && view->curtype != type) {
		(void) wattrset(view->win, get_view_attr(view, type));
		wchgat(view->win, -1, 0, get_view_color(view, type), NULL);
		view->curtype = type;
	}
}