static void scrollTest(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; MvWAddStr(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 void show_help(WINDOW *win) { static const char *table[] = { "Basic commands:" ,"Use h/j/k/l or arrow keys to move the cursor." ,"Set the count parameter for insert/delete by entering digits 0-9." ,"" ,"Other commands:" ,"space toggles through the set of video attributes and colors." ,"t touches (forces repaint) of the current line." ,"i calls insertln at the current position with the given count." ,"d calls deleteln at the window beginning with the given count." ,"I calls insdelln at the window beginning with the given count." ,"D calls insdelln at the window beginning with the given -count." ,"f refills the window with test-pattern using current attributes." ,"w recur to test windows other than stdscr" ,"q quit" ,"= resets count to zero." ,"? shows this help-window" ,"" ,"" }; int y_max, x_max; int row; getmaxyx(win, y_max, x_max); for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) { MvWPrintw(win, row, 0, "%.*s", x_max, table[row]); } while (wgetch(win) != 'q') beep(); }
static void show_help(WINDOW *win) { static const char *table[] = { "Basic commands:" ,"Use h/j/k/l or arrow keys to move the cursor." ,"Set the count parameter for chgat by entering digits 0-9." ,"" ,"Other commands:" ,"space toggles through the set of video attributes and colors." ,"t touches (forces repaint) of the current line." ,". calls *chgat at the current position with the given count." ,", calls *chgat at the window beginning with the given count." ,"= resets count to zero." ,"- negates count." ,"? shows this help-window" ,"" ,"" }; int y_max, x_max; int row; getmaxyx(win, y_max, x_max); for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) { MvWPrintw(win, row, 0, "%.*s", x_max, table[row]); } while (wgetch(win) != 'q') beep(); }
static void show_panels(PANEL * px[MAX_PANELS + 1]) { static const char *help[] = { "", "Commands are letter/digit pairs. Digits are the panel number.", "", " b - put the panel on the bottom of the stack", " c - create the panel", " d - delete the panel", " h - hide the panel", " m - move the panel (M for continuous move)", " r - resize the panel", " s - show the panel", " b - put the panel on the top of the stack" }; struct { bool valid; bool hidden; PANEL *above; PANEL *below; } table[MAX_PANELS + 1]; WINDOW *win; PANEL *pan; int j; memset(table, 0, sizeof(table)); for (j = 1; j <= MAX_PANELS; ++j) { table[j].valid = (px[j] != 0); if (table[j].valid) { table[j].hidden = panel_hidden(px[j]); table[j].above = panel_above(px[j]); table[j].below = panel_below(px[j]); } } if ((win = newwin(LINES - 1, COLS, 0, 0)) != 0) { keypad(win, TRUE); if ((pan = new_panel(win)) != 0) { werase(win); MvWPrintw(win, 0, 0, "Panels:\n"); for (j = 1; j <= MAX_PANELS; ++j) { if (table[j].valid) { wprintw(win, " %d:", j); if (table[j].hidden) { waddstr(win, " hidden"); } else { if (table[j].above) { wprintw(win, " above %d", which_panel(px, table[j].above)); } if (table[j].below) { wprintw(win, "%s below %d", table[j].above ? "," : "", which_panel(px, table[j].below)); } } waddch(win, '\n'); } } for (j = 0; j < (int) SIZEOF(help); ++j) { if (wprintw(win, "%s\n", help[j]) == ERR) break; } wgetch(win); del_panel(pan); pflush(); } delwin(win); } }
static int test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin) { WINDOW *txtbox = 0; WINDOW *txtwin = 0; FILE *fp; int j; int txt_x = 0, txt_y = 0; int base_y; int limit; cchar_t ch; cchar_t text[MAX_COLS]; if (argv[level] == 0) { beep(); return FALSE; } if (level > 1) { txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level); box(txtbox, 0, 0); wnoutrefresh(txtbox); txtwin = derwin(txtbox, getmaxy(txtbox) - 2, getmaxx(txtbox) - 2, 1, 1); base_y = 0; } else { txtwin = stdscr; base_y = BASE_Y; } keypad(txtwin, TRUE); /* enable keyboard mapping */ (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ txt_y = base_y; txt_x = 0; wmove(txtwin, txt_y, txt_x); if ((fp = fopen(argv[level], "r")) != 0) { while ((j = fgetc(fp)) != EOF) { if (waddch(txtwin, UChar(j)) != OK) { break; } } fclose(fp); } else { wprintw(txtwin, "Cannot open:\n%s", argv[1]); } while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) { switch (j) { case KEY_DOWN: case 'j': if (txt_y < getmaxy(txtwin) - 1) txt_y++; else beep(); break; case KEY_UP: case 'k': if (txt_y > base_y) txt_y--; else beep(); break; case KEY_LEFT: case 'h': if (txt_x > 0) txt_x--; else beep(); break; case KEY_RIGHT: case 'l': if (txt_x < getmaxx(txtwin) - 1) txt_x++; else beep(); break; case 'w': test_inchs(level + 1, argv, chrwin, strwin); if (txtbox != 0) { touchwin(txtbox); wnoutrefresh(txtbox); } else { touchwin(txtwin); wnoutrefresh(txtwin); } break; default: beep(); break; } MvWPrintw(chrwin, 0, 0, "char:"); wclrtoeol(chrwin); if (txtwin != stdscr) { wmove(txtwin, txt_y, txt_x); if (win_wch(txtwin, &ch) != ERR) { if (wadd_wch(chrwin, &ch) != ERR) { for (j = txt_x + 1; j < getmaxx(txtwin); ++j) { if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) { if (wadd_wch(chrwin, &ch) == ERR) { break; } } else { break; } } } } } else { move(txt_y, txt_x); if (in_wch(&ch) != ERR) { if (wadd_wch(chrwin, &ch) != ERR) { for (j = txt_x + 1; j < getmaxx(txtwin); ++j) { if (mvin_wch(txt_y, j, &ch) != ERR) { if (wadd_wch(chrwin, &ch) == ERR) { break; } } else { break; } } } } } wnoutrefresh(chrwin); MvWPrintw(strwin, 0, 0, "text:"); wclrtobot(strwin); limit = getmaxx(strwin) - 5; if (txtwin != stdscr) { wmove(txtwin, txt_y, txt_x); if (win_wchstr(txtwin, text) != ERR) { (void) mvwadd_wchstr(strwin, 0, 5, text); } wmove(txtwin, txt_y, txt_x); if (win_wchnstr(txtwin, text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 1, 5, text); } if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) { (void) mvwadd_wchstr(strwin, 2, 5, text); } if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 3, 5, text); } } else { move(txt_y, txt_x); if (in_wchstr(text) != ERR) { (void) mvwadd_wchstr(strwin, 0, 5, text); } move(txt_y, txt_x); if (in_wchnstr(text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 1, 5, text); } if (mvin_wchstr(txt_y, txt_x, text) != ERR) { (void) mvwadd_wchstr(strwin, 2, 5, text); } if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 3, 5, text); } } wnoutrefresh(strwin); } if (level > 1) { delwin(txtwin); delwin(txtbox); } return TRUE; }
static void inputTest(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, (chtype) 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(); #if HAVE_TYPEAHEAD typeahead(-1); #endif #ifdef NCURSES_MOUSE_VERSION mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); #endif #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif for (;;) { wmove(win, 3, 5); c = wgetch(win); wclrtobot(win); if (c >= KEY_MIN) wprintw(win, "Key Pressed: %s", keyname(c)); else if (isprint(c)) wprintw(win, "Key Pressed: %c", c); else wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); #ifdef KEY_MOUSE if (c == KEY_MOUSE) { #if defined(NCURSES_MOUSE_VERSION) #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037)) #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)) #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)) #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)) #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)) MEVENT event; int button = 0; getmouse(&event); if (ButtonChanged(1)) button = 1; else if (ButtonChanged(2)) button = 2; else if (ButtonChanged(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (ButtonPressed(button)) wprintw(win, "pressed: "); else if (ButtonDouble(button)) wprintw(win, "double: "); else if (ButtonTriple(button)) wprintw(win, "triple: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", event.y, event.x); #elif defined(PDCURSES) int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) wprintw(win, "moved: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) wprintw(win, "pressed: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) wprintw(win, "double: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); #endif /* NCURSES_VERSION vs PDCURSES */ } #endif /* KEY_MOUSE */ wrefresh(win); if (c == ' ') break; } #if 0 nodelay(win, TRUE); wgetch(win); nodelay(win, FALSE); #endif #if defined(PDCURSES) mouse_set(0L); #endif refresh(); repeat = 0; do { static const char *fmt[] = { "%d %10s", "%d %[a-zA-Z]s", "%d %[][a-zA-Z]s", "%d %[^0-9]" }; char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]); wclear(win); MvWAddStr(win, 3, 2, "The window should have moved"); MvWAddStr(win, 4, 2, "This text should have appeared without you pressing a key"); MvWPrintw(win, 6, 2, "Scanning with format \"%s\"", format); mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4)); erase(); refresh(); wrefresh(win); echo(); noraw(); num = 0; *buffer = 0; answered = mvwscanw(win, 7, 6, format, &num, buffer); MvWPrintw(win, 8, 6, "String: %s Number: %d (%d values read)", buffer, num, answered); Continue(win); ++repeat; free(format); } while (answered > 0); }