/* * Author: Thomas E. Dickey 1999 * * $Id: cardfile.c,v 1.11 2002/04/06 23:12:50 tom Exp $ * * File format: text beginning in column 1 is a title; other text forms the content. */ #include #include #include #if HAVE_UNISTD_H #include #endif #include /* include before curses.h to work around glibc bug */ #include #include #include #include #include #ifndef CTRL #define CTRL(x) ((x) & 0x1f) #endif #define FIELD_WIDTH 20 #define FIELD_HEIGHT 3 FORM *my_form; PANEL *my_panel; /*******************************************************************************/ static int form_virtualize(WINDOW *w) { int c = wgetch(w); switch (c) { case 033: return MAX_FORM_COMMAND + 1; case CTRL('J'): case CTRL('M'): case KEY_ENTER: return REQ_NEW_LINE; default: return c; } } /*******************************************************************************/ void create_form() { WINDOW *win; FIELD **fields; fields = (FIELD **) calloc(2, sizeof(FIELD *)); win = newwin(FIELD_HEIGHT + 2, FIELD_WIDTH + 2, 0, 0); keypad(win, TRUE); my_panel = new_panel(win); box(win, 0, 0); fields[0] = new_field(FIELD_HEIGHT, FIELD_WIDTH, 0, 0, 0, 0); set_field_back(fields[0], A_REVERSE); set_field_just(fields[0], JUSTIFY_LEFT); fields[1] = 0; my_form = new_form(fields); set_form_win(my_form, win); set_form_sub(my_form, derwin(win, FIELD_HEIGHT, FIELD_WIDTH, 1, 1)); post_form(my_form); top_panel(my_panel); } void process_input() { int finished = FALSE; while (!finished) { int ch; update_panels(); doupdate(); switch (form_driver(my_form, ch = form_virtualize(panel_window(my_panel)))) { case E_OK: break; case E_UNKNOWN_COMMAND: switch (ch) { case MAX_FORM_COMMAND + 1: finished = TRUE; break; default: beep(); break; } break; default: flash(); break; } } } /*******************************************************************************/ int main(int argc, char *argv[]) { initscr(); cbreak(); noecho(); create_form(); process_input(); endwin(); exit(0); }