Ejemplo n.º 1
0
static void color_line(const char *line, RStrpool *p, RList *ml){
	int m_len, offset = 0;
	char *m_addr;
	RListIter *it;
	RRegexMatch *m;
	char *inv[2] = {
		R_CONS_INVERT (true, true),
		R_CONS_INVERT (false, true)
	};
	int linv[2] = {
		strlen (inv[0]),
		strlen(inv[1])
	};
	r_strpool_empty (p);
	r_list_foreach (ml, it, m) {
		/* highlight a match */
		r_strpool_memcat (p, line + offset, m->rm_so - offset);
		r_strpool_memcat (p, inv[0], linv[0]);
		m_len = m->rm_eo - m->rm_so;
		if (m_len<0) m_len = 0;
		m_addr = r_str_ndup (line + m->rm_so, m_len);
		if (m_addr) {
			/* in case there's a CSI in the middle of this match*/
			m_len = r_str_ansi_filter (m_addr, NULL, NULL, m_len);
			if (m_len<0) m_len = 0;
			r_strpool_memcat (p, m_addr, m_len);
			r_strpool_memcat (p, inv[1], linv[1]);
			offset = m->rm_eo;
			free(m_addr);
		}

	}
Ejemplo n.º 2
0
R_API void r_print_cursor(RPrint *p, int cur, int set) {
	if (!p || !p->cur_enabled)
		return;
	if (p->ocur != -1) {
		int from = p->ocur;
		int to = p->cur;
		r_num_minmax_swap_i (&from, &to);
		if (cur>=from && cur<=to)
			p->printf ("%s", R_CONS_INVERT (set, 1));
	} else
	if (cur==p->cur)
		p->printf ("%s", R_CONS_INVERT (set, 1));
}
Ejemplo n.º 3
0
R_API void r_print_cursor(RPrint *p, int cur, int set) {
	if (!p->cur_enabled)
		return;
	if (p->ocur != -1) {
		int from = p->ocur;
		int to = p->cur;
		r_num_minmax_swap_i (&from, &to);
		if (cur>=from && cur<=to)
			p->printf ("%s", R_CONS_INVERT (set, 1)); //r_cons_invert (set, 1); //p->flags&R_PRINT_FLAGS_COLOR);
	} else
	if (cur==p->cur)
		p->printf ("%s", R_CONS_INVERT (set, 1)); //r_cons_invert (set, 1); //p->flags&R_PRINT_FLAGS_COLOR);
}
Ejemplo n.º 4
0
R_API void r_cons_highlight (const char *word) {
	int l, *cpos;
	char *rword, *res, *clean;
	char *inv[2] = {
		R_CONS_INVERT (true, true),
		R_CONS_INVERT (false, true)
	};
	int linv[2] = {
		strlen (inv[0]),
		strlen (inv[1])
	};

	if (word && *word && I.buffer) {
		int word_len = strlen (word);
		char *orig;
		clean = I.buffer;
		l = r_str_ansi_filter (clean, &orig, &cpos, 0);
		I.buffer = orig;
		if (I.highlight) {
			if (strcmp (word, I.highlight)) {
				free (I.highlight);
				I.highlight = strdup (word);
			}
		} else {
			I.highlight = strdup (word);
		}
		rword = malloc (word_len + linv[0] + linv[1] + 1);
		if (!rword) {
			free (cpos);
			return;
		}
		strcpy (rword, inv[0]);
		strcpy (rword + linv[0], word);
		strcpy (rword + linv[0] + word_len, inv[1]);
		res = r_str_replace_thunked (I.buffer, clean, cpos,
					     l, word, rword, 1);
		if (res) {
			I.buffer = res;
			I.buffer_len = I.buffer_sz = strlen (res);
		}
		free (rword);
		free (clean);
		free (cpos);
		/* don't free orig - it's assigned
		 * to I.buffer and possibly realloc'd */
	} else {
		free (I.highlight);
		I.highlight = NULL;
	}
}
Ejemplo n.º 5
0
static void color_line(const char *line, RStrpool *p, RRegexMatch *ms){
	int i, m_len;
	int offset = 0;
	char *m_addr;
	char *inv[2] = {R_CONS_INVERT(R_TRUE, R_TRUE),
			R_CONS_INVERT(R_FALSE, R_TRUE)};
	int linv[2] = {strlen(inv[0]), strlen(inv[1])};

	r_strpool_empty(p);
	for (i = 0; i < NMATCHES; i++) {
		if (ms[i].rm_eo && (i < NMATCHES - 1)) {
			/* highlight a match */
			r_strpool_memcat (p, line + offset,
					  ms[i].rm_so - offset);
			r_strpool_memcat (p, inv[0], linv[0]);

			m_len = ms[i].rm_eo - ms[i].rm_so;
			m_addr = r_str_ndup (line + ms[i].rm_so, m_len);
			if (m_addr) {
				if(r_str_ansi_chrn (m_addr, m_len) - m_addr < m_len ){
					/* there's a CSI in the middle of this match*/
					m_len = r_str_ansi_filter(m_addr,
							NULL, NULL, m_len);
				}
				r_strpool_memcat (p, m_addr, m_len);
				r_strpool_memcat (p, inv[1], linv[1]);
				offset = ms[i].rm_eo;
				free(m_addr);
			}
		} else {
			/* append final part of string w/o matches */
			r_strpool_append(p, line + offset);
			break;
		}
	}
}
Ejemplo n.º 6
0
R_API void r_cons_invert(int set, int color) {
	r_cons_strcat (R_CONS_INVERT (set, color));
}
Ejemplo n.º 7
0
R_API void r_print_cursor(RPrint *p, int cur, int len, int set) {
	if (r_print_have_cursor (p, cur, len)) {
		p->cb_printf ("%s", R_CONS_INVERT (set, 1));
	}
}