Exemplo n.º 1
0
void tui_view_text(int width, int height, const char *title, const char *text)
{
    const char *p;
    int x, y, i;
    int need_update = 1;
    tui_area_t backing_store = NULL;

    x = CENTER_X(width);
    y = CENTER_Y(height);

    tui_display_window(x, y, width, height, MESSAGE_BORDER, MESSAGE_BACK,
		       title, &backing_store);
    
    tui_set_attr(MESSAGE_BORDER, MESSAGE_BACK, 0);
    tui_put_char(x + width - 1, y + 1, 0x1e); /* Up arrow */
    tui_put_char(x + width - 1, y + height - 2, 0x1f); /* Down arrow */
    for (i = y + 2; i < y + height - 2; i++)
	tui_put_char(x + width - 1, i, 0xb1);

    tui_set_attr(MESSAGE_FORE, MESSAGE_BACK, 0);
    p = text;
    while (1) {
	int key;

	if (need_update) {
	    tui_display_text(x + 2, y + 1, width - 4, height - 2, p);
	    need_update = 0;
	}
	
	key = getkey();

	switch (key) {
	  case K_Escape:
	  case K_Return:
	    tui_area_put(backing_store, x, y);
	    tui_area_free(backing_store);
	    return;
	  case K_Up:
	  case K_Left:
	    p = util_find_prev_line(text, p);
	    need_update = 1;
	    break;
	  case K_Down:
	  case K_Right:
	    p = util_find_next_line(p);
	    need_update = 1;
	    break;
	  case K_PageDown:
	    for (i = 0; i < height - 3; i++)
		p = util_find_next_line(p);
	    need_update = 1;
	    break;
	  case K_PageUp:
	    for (i = 0; i < height - 3; i++)
		p = util_find_prev_line(text, p);	
	    need_update = 1;
	    break;
	}
    }
}
Exemplo n.º 2
0
void tui_display_text(int x, int y, int width, int height, const char *text)
{
    const char *p = text;
    int i, j;

    for (j = 0; j < height; j++) {
        for (i = 0; i < width; i++) {
            if (*p != '\n' && *p != '\0') {
                tui_put_char(x + i, y + j, *p);
                p++;
            } else {
                tui_put_char(x + i, y + j, ' ');
            }
        }
        if (*p == '\n')
            p++;
    }
}
Exemplo n.º 3
0
void tui_display_window(int x, int y, int width, int height,
                        int foreground_color, int background_color,
                        const char *title, tui_area_t *backing_store)
{
    int i;

    if (backing_store != NULL) {
        /* 2 more chars on right, 1 more on bottom because of the "shadow".  */
        tui_area_get(backing_store, x, y, width + 2, height + 1);
    }

    tui_make_shadow(x + 2, y + 1, width, height);

    tui_set_attr(foreground_color, background_color, 0);
    tui_put_char(x, y, 0xc9);
    tui_hline(x + 1, y, 0xcd, width - 2);
    tui_put_char(x + width - 1, y, 0xbb);
    tui_put_char(x, y + height - 1, 0xc8);
    tui_hline(x + 1, y + height - 1, 0xcd, width - 2);
    tui_put_char(x + width - 1, y + height - 1, 0xbc);
    for (i = 0; i < height - 2; i++) {
        tui_put_char(x, y + i + 1, 0xba);
        tui_hline(x + 1, y + i + 1, ' ', width - 2);
        tui_put_char(x + width - 1, y + i + 1, 0xba);
    }

    if (!util_check_null_string(title)) {
        int title_x, title_length;

        title_length = strlen(title);
        title_x = x + (width - title_length - 4) / 2;
        tui_display(title_x, y, 0, "\x10 %s \x11", title);
    }
}
Exemplo n.º 4
0
static void file_selector_display_path(const char *path, int x, int y, int width)
{
    int i, xx;

    tui_set_attr(MENU_BORDER, MENU_BACK, 0);
    tui_hline(x, y, 0xcd, width);

    tui_set_attr(MENU_FORE, MENU_BACK, 0);

    for (i = strlen(path) - 1, xx = MIN(x + width - 1, x + i); i >= 0 && xx >= x; i--, xx--) {
        char c;

        /* Display ellipsis on the left if longer than the line.  */
        if (xx <= x + 1 && i > 1) {
            c = '.';
        } else {
            c = path[i] == '/' ? '\\' : path[i];
        }
        tui_put_char(xx, y, c);
    }
}