Esempio n. 1
0
/*
 * Display a temporary window listing the keystroke-commands we recognize.
 */
void
help_edit_field(void)
{
    int x0 = 4;
    int y0 = 2;
    int y1 = 0;
    int y2 = 0;
    int wide = COLS - ((x0 + 1) * 2);
    int high = LINES - ((y0 + 1) * 2);
    WINDOW *help = newwin(high, wide, y0, x0);
    WINDOW *data = newpad(2 + SIZEOF(commands), wide - 4);
    unsigned n;
    int ch = ERR;

    begin_popup();

    keypad(help, TRUE);
    keypad(data, TRUE);
    waddstr(data, "Defined form edit/traversal keys:\n");
    for (n = 0; n < SIZEOF(commands); ++n) {
	const char *name;
#ifdef NCURSES_VERSION
	if ((name = form_request_name(commands[n].result)) == 0)
#endif
	    name = commands[n].help;
	wprintw(data, "%s -- %s\n",
		keyname(commands[n].code),
		name != 0 ? name : commands[n].help);
    }
    waddstr(data, "Arrow keys move within a field as you would expect.");
    y2 = getcury(data);

    do {
	switch (ch) {
	case KEY_HOME:
	    y1 = 0;
	    break;
	case KEY_END:
	    y1 = y2;
	    break;
	case KEY_PREVIOUS:
	case KEY_PPAGE:
	    if (y1 > 0) {
		y1 -= high / 2;
		if (y1 < 0)
		    y1 = 0;
	    } else {
		beep();
	    }
	    break;
	case KEY_NEXT:
	case KEY_NPAGE:
	    if (y1 < y2) {
		y1 += high / 2;
		if (y1 >= y2)
		    y1 = y2;
	    } else {
		beep();
	    }
	    break;
	case CTRL('P'):
	case KEY_UP:
	    if (y1 > 0)
		--y1;
	    else
		beep();
	    break;
	case CTRL('N'):
	case KEY_DOWN:
	    if (y1 < y2)
		++y1;
	    else
		beep();
	    break;
	default:
	    beep();
	    break;
	case ERR:
	    break;
	}
	werase(help);
	box(help, 0, 0);
	wnoutrefresh(help);
	pnoutrefresh(data, y1, 0, y0 + 1, x0 + 1, high, wide);
	doupdate();
    } while ((ch = wgetch(data)) != ERR && ch != QUIT && ch != ESCAPE);
    werase(help);
    wrefresh(help);
    delwin(help);
    delwin(data);

    end_popup();
}
Esempio n. 2
0
/*
 * Display a temporary window, e.g., to display a help-message.
 */
void
popup_msg(WINDOW *parent, const char *const *msg)
{
    int x0 = 4;
    int y0 = 2;
    int y1 = 0;
    int y2 = 0;
    int wide = getmaxx(parent) - ((x0 + 1) * 2);
    int high = getmaxy(parent) - ((y0 + 1) * 2);
    WINDOW *help;
    WINDOW *data;
    int n;
    int width = 0;
    int length;
    int last_y;
    int ch = ERR;

    for (n = 0; msg[n] != 0; ++n) {
	int check = (int) strlen(msg[n]);
	if (width < check)
	    width = check;
    }
    length = n;

    if ((help = newwin(high, wide, y0, x0)) == 0)
	return;
    if ((data = newpad(length + 1, width)) == 0)
	return;

    begin_popup();

    keypad(data, TRUE);

    for (n = 0; n < length; ++n) {
	waddstr(data, msg[n]);
	if ((n + 1) < length) {
	    waddch(data, '\n');
	}
    }
    y2 = getcury(data);
    last_y = (y2 - (high - 3));

    do {
	switch (ch) {
	case KEY_HOME:
	    y1 = 0;
	    break;
	case KEY_END:
	    y1 = last_y;
	    break;
	case KEY_PREVIOUS:
	case KEY_PPAGE:
	    if (y1 > 0) {
		y1 -= high / 2;
		if (y1 < 0)
		    y1 = 0;
	    } else {
		beep();
	    }
	    break;
	case KEY_NEXT:
	case KEY_NPAGE:
	    if (y1 < last_y) {
		y1 += high / 2;
		if (y1 > last_y)
		    y1 = last_y;
	    } else {
		beep();
	    }
	    break;
	case CTRL('P'):
	case KEY_UP:
	    if (y1 > 0)
		--y1;
	    else
		beep();
	    break;
	case CTRL('N'):
	case KEY_DOWN:
	    if (y1 < last_y)
		++y1;
	    else
		beep();
	    break;
	default:
	    beep();
	    break;
	case ERR:
	    break;
	}
	werase(help);
	box(help, 0, 0);
	wnoutrefresh(help);
	pnoutrefresh(data, y1, 0, y0 + 1, x0 + 1, high, wide);
	doupdate();
    } while ((ch = wgetch(data)) != ERR && ch != QUIT && ch != ESCAPE);
    werase(help);
    wrefresh(help);
    delwin(help);
    delwin(data);

    end_popup();
}