📄 testcurs.c
字号:
/* * * This is a test program for the PDCurses screen package for IBM PC type * machines. * * This program was written by John Burnell (johnb@kea.am.dsir.govt.nz) * wrs(5/28/93) -- modified to be consistent (perform identically) with either * PDCurses or under Unix System V, R4 * * $Id: testcurs.c,v 1.34 2005/04/16 16:19:12 tom Exp $ */#include <test.priv.h>#if defined(XCURSES)char *XCursesProgramName = "testcurs";#endifstatic int initTest(WINDOW **);static void display_menu(int, int);static void inputTest(WINDOW *);static void introTest(WINDOW *);static void outputTest(WINDOW *);static void padTest(WINDOW *);static void scrollTest(WINDOW *);#if defined(PDCURSES) && !defined(XCURSES)static void resizeTest(WINDOW *);#endifstruct commands { NCURSES_CONST char *text; void (*function) (WINDOW *);};typedef struct commands COMMAND;static const COMMAND command[] ={ {"General Test", introTest}, {"Pad Test", padTest},#if defined(PDCURSES) && !defined(XCURSES) {"Resize Test", resizeTest},#endif {"Scroll Test", scrollTest}, {"Input Test", inputTest}, {"Output Test", outputTest}};#define MAX_OPTIONS SIZEOF(command)#if !HAVE_STRDUP#define strdup my_strdupstatic char *strdup(char *s){ char *p = (char *) malloc(strlen(s) + 1); if (p) strcpy(p, s); return (p);}#endif /* not HAVE_STRDUP */static int width, height;intmain( int argc GCC_UNUSED, char *argv[]GCC_UNUSED){ WINDOW *win; int key; int old_option = (-1); int new_option = 0; bool quit = FALSE; unsigned n; setlocale(LC_ALL, "");#ifdef PDCDEBUG PDC_debug("testcurs started\n");#endif if (!initTest(&win)) ExitProgram(EXIT_FAILURE); erase(); display_menu(old_option, new_option); for (;;) {#ifdef A_COLOR if (has_colors()) { init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgd(win, COLOR_PAIR(1)); } else wbkgd(win, A_REVERSE);#else wbkgd(win, A_REVERSE);#endif werase(win); noecho(); keypad(stdscr, TRUE); raw(); key = getch(); if (key < KEY_MIN && key > 0 && isalpha(key)) { if (islower(key)) key = toupper(key); for (n = 0; n < MAX_OPTIONS; ++n) { if (key == command[n].text[0]) { display_menu(old_option, new_option = n); key = ' '; break; } } } switch (key) { case 10: case 13: case KEY_ENTER: erase(); refresh(); (*command[new_option].function) (win); erase(); display_menu(old_option, new_option); break; case KEY_UP: new_option = (new_option == 0) ? new_option : new_option - 1; display_menu(old_option, new_option); break; case KEY_DOWN: new_option = (new_option == MAX_OPTIONS - 1) ? new_option : new_option + 1; display_menu(old_option, new_option); break; case 'Q': case 'q': quit = TRUE; break; default: beep(); break; case ' ': break; } if (quit == TRUE) break; } delwin(win); endwin();#ifdef XCURSES XCursesExit();#endif ExitProgram(EXIT_SUCCESS);}static voidContinue(WINDOW *win){ int y1 = getmaxy(win); int x1 = getmaxx(win); int y0 = y1 < 10 ? y1 : 10; int x0 = 1; chtype save; save = mvwinch(win, y0, x1 - 1); mvwaddstr(win, y0, x0, " Press any key to continue"); wclrtoeol(win); getyx(win, y0, x0); mvwaddch(win, y0, x1 - 1, save); wmove(win, y0, x0); raw(); wgetch(win);}static intinitTest(WINDOW **win){#ifdef PDCDEBUG PDC_debug("initTest called\n");#endif#ifdef TRACE trace(TRACE_MAXIMUM);#endif initscr();#ifdef PDCDEBUG PDC_debug("after initscr()\n");#endif#ifdef A_COLOR if (has_colors()) start_color();#endif width = 60; height = 13; /* Create a drawing window */ *win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); if (*win == NULL) { endwin(); return 0; } return 1;}static voidintroTest(WINDOW *win){ wmove(win, height / 2 - 5, width / 2); wvline(win, ACS_VLINE, 10); wmove(win, height / 2, width / 2 - 10); whline(win, ACS_HLINE, 20); Continue(win); beep(); werase(win); box(win, ACS_VLINE, ACS_HLINE); wrefresh(win); cbreak(); mvwaddstr(win, 1, 1, "You should have rectangle in the middle of the screen"); mvwaddstr(win, 2, 1, "You should have heard a beep"); Continue(win); return;}static voidscrollTest(WINDOW *win){ int i; int half; int OldY; NCURSES_CONST char *Message = "The window will now scroll slowly"; wclear(win); OldY = getmaxy(win); half = OldY / 2; mvwprintw(win, OldY - 2, 1, Message); wrefresh(win); scrollok(win, TRUE); for (i = 1; i <= OldY; i++) { napms(600); scroll(win); wrefresh(win); } werase(win); for (i = 1; i < OldY; i++) { mvwprintw(win, i, 1, "Line %d", i); } mvwprintw(win, OldY - 2, 1, "The top of the window will scroll"); wmove(win, 1, 1); wsetscrreg(win, 0, half - 1); box(win, ACS_VLINE, ACS_HLINE); wrefresh(win); for (i = 1; i <= half; i++) { napms(600); scroll(win); box(win, ACS_VLINE, ACS_HLINE); wrefresh(win); } werase(win); for (i = 1; i < OldY; i++) { mvwprintw(win, i, 1, "Line %d", i); } mvwprintw(win, 1, 1, "The bottom of the window will scroll"); wmove(win, OldY - 2, 1); wsetscrreg(win, half, --OldY); box(win, ACS_VLINE, ACS_HLINE); wrefresh(win); for (i = half; i <= OldY; i++) { napms(600); wscrl(win, -1); box(win, ACS_VLINE, ACS_HLINE); wrefresh(win); } wsetscrreg(win, 0, OldY);}static voidinputTest(WINDOW *win){ int answered; int repeat; int w, h, bx, by, sw, sh, i, c, num; char buffer[80]; WINDOW *subWin; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return;#ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); } else wbkgd(subWin, A_BOLD);#else wbkgd(subWin, A_BOLD);#endif box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { mvwprintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); noraw(); wgetch(win); flushinp(); wmove(win, 9, 10); wdelch(win); mvwaddstr(win, 4, 1, "The character should now have been deleted"); Continue(win); wclear(win); mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); typeahead(-1);#if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS);#endif for (;;) { wmove(win, 3, 5); c = wgetch(win); wclrtobot(win);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -