Ejemplo n.º 1
0
static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos)
{
	int i;
	int xpos, end_xpos;

	xpos = entry->xpos + entry->promptlen +
		pos2scrpos(entry, pos + entry->scrstart) -
		pos2scrpos(entry, entry->scrstart);
        end_xpos = entry->xpos + entry->width;

	if (xpos > end_xpos)
                return;

	term_set_color(root_window, ATTR_RESET);
	term_move(root_window, xpos, entry->ypos);

	for (i = entry->scrstart + pos; i < entry->text_len; i++) {
		unichar c = entry->text[i];

		if (entry->hidden)
			xpos++;
		else if (term_type == TERM_TYPE_BIG5)
			xpos += big5_width(c);
		else if (entry->utf8)
			xpos += unichar_isprint(c) ? mk_wcwidth(c) : 1;
		else
			xpos++;

		if (xpos > end_xpos)
			break;

		if (entry->hidden)
                        term_addch(root_window, ' ');
		else if (unichar_isprint(c))
			term_add_unichar(root_window, c);
		else {
			term_set_color(root_window, ATTR_RESET|ATTR_REVERSE);
			term_addch(root_window, (c & 127)+'A'-1);
			term_set_color(root_window, ATTR_RESET);
		}
	}

        /* clear the rest of the input line */
	if (xpos < end_xpos) {
		if (end_xpos == term_width)
			term_clrtoeol(root_window);
		else {
			while (xpos < end_xpos) {
				term_addch(root_window, ' ');
				xpos++;
			}
		}
	}
}
Ejemplo n.º 2
0
/* Return screen length of plain string */
static int scrlen_str(const char *str)
{
	int len = 0;
	char *stripped;
	g_return_val_if_fail(str != NULL, 0);

	str = stripped = strip_codes(str);
	if (is_utf8() && g_utf8_validate(str, -1, NULL)) {

		while (*str != '\0') {
			gunichar c;

			c = g_utf8_get_char(str);
			str = g_utf8_next_char(str);

			len += unichar_isprint(c) ? mk_wcwidth(c) : 1;
		}

	} else {
		len = strlen(str);
	}

	g_free(stripped);
	return len;
}
Ejemplo n.º 3
0
static inline unichar read_unichar(const unsigned char *data, const unsigned char **next, int *width)
{
	unichar chr = g_utf8_get_char_validated(data, -1);

	if (chr & 0x80000000) {
		chr = 0xfffd;
		*next = data + 1;
		*width = 1;
	} else {
		*next = g_utf8_next_char(data);
		*width = unichar_isprint(chr) ? mk_wcwidth(chr) : 1;
	}
	return chr;
}
Ejemplo n.º 4
0
static int pos2scrpos(GUI_ENTRY_REC *entry, int pos)
{
	int i;
	int xpos = 0;

	for (i = 0; i < pos; i++) {
		unichar c = entry->text[i];

		if (term_type == TERM_TYPE_BIG5)
			xpos += big5_width(c);
		else if (entry->utf8)
			xpos += unichar_isprint(c) ? mk_wcwidth(c) : 1;
		else
			xpos++;
	}
	return xpos;
}
Ejemplo n.º 5
0
void mp_token_show(const mp_token_t *tok) {
    printf("(%d:%d) kind:%d str:%p len:%d", tok->src_line, tok->src_column, tok->kind, tok->str, tok->len);
    if (tok->str != NULL && tok->len > 0) {
        const byte *i = (const byte *)tok->str;
        const byte *j = (const byte *)i + tok->len;
        printf(" ");
        while (i < j) {
            unichar c = utf8_get_char(i);
            i = utf8_next_char(i);
            if (unichar_isprint(c)) {
                printf("%c", c);
            } else {
                printf("?");
            }
        }
    }
    printf("\n");
}
Ejemplo n.º 6
0
void mp_lexer_show_token(const mp_lexer_t *lex) {
    printf("(" UINT_FMT ":" UINT_FMT ") kind:%u str:%p len:%zu", lex->tok_line, lex->tok_column, lex->tok_kind, lex->vstr.buf, lex->vstr.len);
    if (lex->vstr.len > 0) {
        const byte *i = (const byte *)lex->vstr.buf;
        const byte *j = (const byte *)i + lex->vstr.len;
        printf(" ");
        while (i < j) {
            unichar c = utf8_get_char(i);
            i = utf8_next_char(i);
            if (unichar_isprint(c)) {
                printf("%c", c);
            } else {
                printf("?");
            }
        }
    }
    printf("\n");
}
Ejemplo n.º 7
0
static int scrpos2pos(GUI_ENTRY_REC *entry, int pos)
{
	int i, width, xpos;

	for (i = 0, xpos = 0; i < entry->text_len; i++) {
		unichar c = entry->text[i];

		if (term_type == TERM_TYPE_BIG5)
			width = big5_width(c);
		else if (entry->utf8)
			width = unichar_isprint(c) ? mk_wcwidth(c) : 1;
		else
			width = 1;

		if (xpos + width > pos)
			break;
		xpos += width;
	}

	if (xpos == pos)
		return i;
	else
		return i-1;
}
Ejemplo n.º 8
0
static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
			  int subline, int ypos, int max)
{
        INDENT_FUNC indent_func;
	LINE_CACHE_REC *cache;
        const unsigned char *text, *end, *text_newline;
	unsigned char *tmp;
	unichar chr;
	int xpos, color, fg24, bg24, drawcount, first, need_move, need_clrtoeol, char_width;

	if (view->dirty) /* don't bother drawing anything - redraw is coming */
                return 0;

	cache = textbuffer_view_get_line_cache(view, line);
	if (subline >= cache->count)
                return 0;

        color = ATTR_RESET;
        need_move = TRUE; need_clrtoeol = FALSE;
	xpos = drawcount = 0; first = TRUE;
	text_newline = text =
		subline == 0 ? line->text : cache->lines[subline-1].start;
	for (;;) {
		if (text == text_newline) {
			if (need_clrtoeol && xpos < term_width) {
				term_set_color(view->window, ATTR_RESET);
				term_clrtoeol(view->window);
			}

			if (first)
				first = FALSE;
			else {
				ypos++;
                                if (--max == 0)
					break;
			}

			if (subline > 0) {
                                /* continuing previous line - indent it */
				indent_func = cache->lines[subline-1].indent_func;
				if (indent_func == NULL)
					xpos = cache->lines[subline-1].indent;
                                color = cache->lines[subline-1].color;
#ifdef TERM_TRUECOLOR
                                fg24 = cache->lines[subline-1].fg24;
                                bg24 = cache->lines[subline-1].bg24;
#endif
			} else {
				indent_func = NULL;
			}

			if (xpos == 0 && indent_func == NULL)
                                need_clrtoeol = TRUE;
			else {
				/* line was indented - need to clear the
                                   indented area first */
				term_set_color(view->window, ATTR_RESET);
				term_move(view->window, 0, ypos);
				term_clrtoeol(view->window);

				if (indent_func != NULL)
					xpos = indent_func(view, line, ypos);
			}

			if (need_move || xpos > 0)
				term_move(view->window, xpos, ypos);

			term_set_color2(view->window, color, fg24, bg24);

			if (subline == cache->count-1) {
				text_newline = NULL;
				need_move = FALSE;
			} else {
				/* get the beginning of the next subline */
				text_newline = cache->lines[subline].start;
				need_move = !cache->lines[subline].continues;
			}
                        drawcount++;
			subline++;
		}

		if (*text == '\0') {
			/* command */
			text++;
			if (*text == LINE_CMD_EOL)
                                break;

			if (*text == LINE_CMD_CONTINUE) {
                                /* jump to next block */
				memcpy(&tmp, text+1, sizeof(unsigned char *));
				text = tmp;
				continue;
			} else {
				if (*text == LINE_COLOR_EXT)
					color = (color & BGATTR & ~ATTR_FGCOLOR24) | *++text;
				else if (*text == LINE_COLOR_EXT_BG)
					color = (color & FGATTR & ~ATTR_BGCOLOR24) | (*++text << BG_SHIFT);
#ifdef TERM_TRUECOLOR
				else if (*text == LINE_COLOR_24)
					unformat_24bit_line_color(&text, 1, &color, &fg24, &bg24);
#endif
				else
					update_cmd_color(*text, &color);
				term_set_color2(view->window, color, fg24, bg24);
			}
			text++;
			continue;
		}

		if (view->utf8) {
			chr = read_unichar(text, &end, &char_width);
		} else {
			chr = *text;
			end = text;
			if (term_type == TERM_TYPE_BIG5 &&
			    is_big5(end[0], end[1]))
				char_width = 2;
			else
				char_width = 1;
			end += char_width;
		}

		xpos += char_width;
		if (xpos <= term_width) {
			if (unichar_isprint(chr)) {
				if (view->utf8)
				term_add_unichar(view->window, chr);
				else
				for (; text < end; text++)
					term_addch(view->window, *text);
			} else {
				/* low-ascii */
				term_set_color(view->window, ATTR_RESET|ATTR_REVERSE);
				term_addch(view->window, (chr & 127)+'A'-1);
				term_set_color2(view->window, color, fg24, bg24);
			}
		}
		text = end;
	}

	if (need_clrtoeol && xpos < term_width) {
		term_set_color(view->window, ATTR_RESET);
		term_clrtoeol(view->window);
	}

        return drawcount;
}