X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Ftest_getstr.c;h=227394b1ef92b9d6f0193920a63ac4f2b71ef570;hp=5710c1ab982bf7c61a388a09d1582d9df736613b;hb=aed072e27e60c2abc5ac0ab8113aacf9b4908d50;hpb=03a795bde58b3280a4e9d80029a3b7fec13c79ad diff --git a/test/test_getstr.c b/test/test_getstr.c index 5710c1ab..227394b1 100644 --- a/test/test_getstr.c +++ b/test/test_getstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2007 Free Software Foundation, Inc. * + * Copyright (c) 2007-2012,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: test_getstr.c,v 1.6 2007/07/28 19:46:43 tom Exp $ + * $Id: test_getstr.c,v 1.13 2017/09/28 23:11:12 tom Exp $ * * Author: Thomas E Dickey * @@ -43,6 +43,10 @@ */ #include +#include + +#if HAVE_CHGAT +/* Solaris SVr4 curses lacks wchgat, mvgetnstr, mvwgetnstr */ #define BASE_Y 6 #define MAX_COLS 1024 @@ -55,6 +59,15 @@ typedef enum { eMaxFlavor } Flavors; +/* + * Return-code is OK/ERR or a keyname. + */ +static const char * +ok_keyname(int code) +{ + return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code))); +} + static bool Quit(int ch) { @@ -74,20 +87,20 @@ Remainder(WINDOW *txtwin) static void ShowPrompt(WINDOW *txtwin, int limit) { - wchgat(txtwin, limit, A_REVERSE, 0, NULL); + wchgat(txtwin, limit, WA_REVERSE, 0, NULL); wnoutrefresh(txtwin); } static void MovePrompt(WINDOW *txtwin, int limit, int y, int x) { - wchgat(txtwin, Remainder(txtwin), A_NORMAL, 0, NULL); + wchgat(txtwin, Remainder(txtwin), WA_NORMAL, 0, NULL); wmove(txtwin, y, x); ShowPrompt(txtwin, limit); } static int -ShowFlavor(WINDOW *strwin, WINDOW *txtwin, Flavors flavor, int limit) +ShowFlavor(WINDOW *strwin, WINDOW *txtwin, int flavor, int limit) { const char *name = "?"; bool limited = FALSE; @@ -129,8 +142,30 @@ ShowFlavor(WINDOW *strwin, WINDOW *txtwin, Flavors flavor, int limit) } static int -test_getstr(int level, char **argv, WINDOW *strwin) +recursive_test(int level, char **argv, WINDOW *strwin) { + static const char *help[] = + { + "Commands:", + " q,^Q,ESC - quit this program", + " ^Q,ESC - quit help-screen", + "", + " p, - move beginning of prompt one up row", + " j, - move beginning of prompt one down row", + " h, - move beginning of prompt one left column", + " l, - move beginning of prompt one right column", + "", + " - - reduce getnstr buffer-size one column", + " + - increase getnstr buffer-size one column", + " : - prompt for input-text", + "", + " < - scroll \"left\" through getstr-functions", + " > - scroll \"right\" through getstr-functions", + "", + " w - recur to subwindow", + " ?, - show help-screen", + 0 + }; WINDOW *txtbox = 0; WINDOW *txtwin = 0; FILE *fp; @@ -221,7 +256,7 @@ test_getstr(int level, char **argv, WINDOW *strwin) break; case 'w': - test_getstr(level + 1, argv, strwin); + recursive_test(level + 1, argv, strwin); if (txtbox != 0) { touchwin(txtbox); wnoutrefresh(txtbox); @@ -268,7 +303,7 @@ test_getstr(int level, char **argv, WINDOW *strwin) *buffer = '\0'; rc = ERR; echo(); - wattrset(txtwin, A_REVERSE); + (void) wattrset(txtwin, A_REVERSE); switch (flavor) { case eGetStr: if (txtwin != stdscr) { @@ -306,10 +341,13 @@ test_getstr(int level, char **argv, WINDOW *strwin) break; } noecho(); - wattrset(txtwin, A_NORMAL); - wprintw(strwin, "%d:%s", rc, buffer); + (void) wattrset(txtwin, A_NORMAL); + wprintw(strwin, "%s:%s", ok_keyname(rc), buffer); wnoutrefresh(strwin); break; + case HELP_KEY_1: + popup_msg(stdscr, help); + break; default: beep(); break; @@ -344,8 +382,17 @@ main(int argc, char *argv[]) strwin = derwin(chrbox, 4, COLS - 2, 1, 1); - test_getstr(1, argv, strwin); + recursive_test(1, argv, strwin); endwin(); ExitProgram(EXIT_SUCCESS); } + +#else +int +main(void) +{ + printf("This program requires the curses chgat function\n"); + ExitProgram(EXIT_FAILURE); +} +#endif