int input_text(char *prompt, char *buf, int size, int (*valid)(char)) { /* Input a line of text. buf contains the initial text string, and is where the result will be stored. size is the maximum length of the string, and valid will be called to determine if a key should be inserted or not. input_text() will return the exit key */ int ret; char *b; int _x, _y, _w; _w = size + 8; b = prepare_popup(prompt, &_x, &_y, &_w); ret = do_input_text(buf, size, -1, valid, NULL, FALSE, NULL); end_popup(b, &_x, &_y, &_w); return ret; }
void alert_box(char *s) /* alert the user to an error */ { char *b; int x, y, w; w = strlen(s) + 20; b = prepare_popup("Error", &x, &y, &w); hide_c(); mywrite(s); clear_keybuf(); while (m_b) poll_mouse(); while ((!input_waiting()) && (!m_b)) poll_mouse(); if (input_waiting()) input_char(); else while (m_b) poll_mouse(); show_c(); end_popup(b, &x, &y, &w); }
/* * 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(); }
/* * 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(); }