Esempio n. 1
0
/* Setup colors - if force is set, use ANSI-style colors if
   terminal capabilities don't contain color codes */
void terminfo_setup_colors(TERM_REC *term, int force)
{
	static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
	const char *bold, *blink;
	int i;

	terminfo_colors_deinit(term);
        term->has_colors = term->TI_setf || term->TI_setaf;

	if (term->TI_setf) {
		for (i = 0; i < 8; i++)
                        term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0));
	} else if (term->TI_setaf) {
		for (i = 0; i < 8; i++)
                        term->TI_fg[i] = g_strdup(tparm(term->TI_setaf, ansitab[i], 0));
	} else if (force) {
		for (i = 0; i < 8; i++)
                        term->TI_fg[i] = g_strdup_printf("\033[%dm", 30+ansitab[i]);
	}

	if (term->TI_setb) {
		for (i = 0; i < 8; i++)
                        term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0));
	} else if (term->TI_setab) {
		for (i = 0; i < 8; i++)
                        term->TI_bg[i] = g_strdup(tparm(term->TI_setab, ansitab[i], 0));
	} else if (force) {
		for (i = 0; i < 8; i++)
                        term->TI_bg[i] = g_strdup_printf("\033[%dm", 40+ansitab[i]);
	}

	if (term->TI_setf || term->TI_setaf || force) {
                term->set_fg = _set_fg;
                term->set_bg = _set_bg;

		/* bold fg, blink bg */
		bold = term->TI_bold ? term->TI_bold : "";
		for (i = 0; i < 8; i++)
			term->TI_fg[i+8] = g_strconcat(bold, term->TI_fg[i], NULL);

		blink = term->TI_blink ? term->TI_blink : "";
		for (i = 0; i < 8; i++)
			term->TI_bg[i+8] = g_strconcat(blink, term->TI_bg[i], NULL);
	} else {
		/* no colors */
                term->set_fg = term->set_bg = _ignore_parm;
	}
}
Esempio n. 2
0
void terminfo_core_deinit(TERM_REC *term)
{
	TERM_REC *old_term;

	old_term = current_term;
        current_term = term;
	term->set_normal(term);
        current_term = old_term;

        terminfo_stop(term);

	g_free(term->TI_normal);
	terminfo_colors_deinit(term);

        g_free(term);
}
Esempio n. 3
0
/* Setup colors - if force is set, use ANSI-style colors if
   terminal capabilities don't contain color codes */
void terminfo_setup_colors(TERM_REC *term, int force)
{
	static const char ansitab[16] = {
		0, 4, 2, 6, 1, 5, 3, 7,
		8, 12, 10, 14, 9, 13, 11, 15
	};
	unsigned int i, color;

	terminfo_colors_deinit(term);

	if (force && term->TI_setf == NULL && term->TI_setaf == NULL)
		term->TI_colors = 8;

	if ((term->TI_setf || term->TI_setaf || force) &&
	     term->TI_colors > 0) {
		term->TI_fg = g_new0(char *, term->TI_colors);
		term->TI_bg = g_new0(char *, term->TI_colors);
		term->set_fg = _set_fg;
		term->set_bg = _set_bg;
	} else {