Added "returnOptions" parameter that limits which keys will continue execution

once the src text is revealed.

	modified:   src/main.c
	modified:   src/nms.c
	modified:   src/nms.h
	modified:   src/sneakers.c
This commit is contained in:
Brian Barto 2016-04-20 14:52:37 -04:00
parent 1782f6d248
commit f91d5601c4
4 changed files with 18 additions and 7 deletions

View File

@ -15,7 +15,7 @@ int main(void) {
}
// Display characters
nmsexec(input);
nmsexec(input, NULL);
// Don't forget to free the allocated memory!
free(input);

View File

@ -44,10 +44,17 @@ char getMaskChar(void);
* void nmsexec(char *)
*
* DESCR:
* Displays the characters stored in the / char * / parameter
* Displays the characters stored in the / char * / parameter.
*
* ARGS:
* char *src - characters to display
* char *returnOptions - user must press key in one of the characters contained in this array
* before execution will continue after /char *src/ is revealed. All
* other keyboard selections will be ignored. Most commonly used when
* displaying a menu.
*
*/
char nmsexec(char *src) {
char nmsexec(char *src, char *returnOptions) {
struct winpos *list_pointer = NULL;
struct winpos *start; // Always points to start of list
struct winpos *temp; // Used for free()ing the list
@ -222,11 +229,15 @@ char nmsexec(char *src) {
flushinp();
// If stdin is set to the keyboard, user must press a key to continue
if (isatty(STDIN_FILENO))
if (isatty(STDIN_FILENO)) {
ret = getch();
else
if (returnOptions != NULL && strlen(returnOptions) > 0)
while (index(returnOptions, ret) == NULL)
ret = getch();
} else
sleep(2);
// End curses mode
endwin();

View File

@ -4,6 +4,6 @@
// Function prototypes
// Display the characters stored in the display queue
char nmsexec(char *);
char nmsexec(char *, char *);
#endif

View File

@ -154,7 +154,7 @@ int main(void) {
strcat(display, foot2Center);
// Display characters
input = nmsexec(display);
input = nmsexec(display, "123456");
switch (input) {
case '1':