MCPcopy Create free account
hub / github.com/NetHack/NetHack / gnome_yn_function

Function gnome_yn_function

outdated/win/gnome/gnbind.c:1022–1075  ·  view source on GitHub ↗

char yn_function(const char *ques, const char *choices, char default) -- Print a prompt made up of ques, choices and default. Read a single character response that is contained in choices or default. If choices is NULL, all possible inputs are accepted and returned. This overrides everything else. The ch

Source from the content-addressed store, hash-verified

1020 ports might use a popup.
1021*/
1022char
1023gnome_yn_function(const char *question, const char *choices, CHAR_P def)
1024{
1025 int ch;
1026 int result = -1;
1027 char message[BUFSZ];
1028 char yn_esc_map = '\033';
1029 GtkWidget *mainWnd = ghack_get_main_window();
1030
1031 if (choices) {
1032 char *cb, choicebuf[QBUFSZ];
1033 Strcpy(choicebuf, choices);
1034 if ((cb = strchr(choicebuf, '\033')) != 0) {
1035 /* anything beyond <esc> is hidden */
1036 *cb = '\0';
1037 }
1038 (void) strncpy(message, question, QBUFSZ - 1);
1039 message[QBUFSZ - 1] = '\0';
1040 sprintf(eos(message), " [%s]", choicebuf);
1041 if (def)
1042 sprintf(eos(message), " (%c)", def);
1043 Strcat(message, " ");
1044 /* escape maps to 'q' or 'n' or default, in that order */
1045 yn_esc_map =
1046 (strchr(choices, 'q') ? 'q' : (strchr(choices, 'n') ? 'n' : def));
1047 } else {
1048 Strcpy(message, question);
1049 }
1050
1051 gnome_putstr(WIN_MESSAGE, ATR_BOLD, message);
1052 if (mainWnd != NULL && choices && !strchr(choices, ch)) {
1053 return (ghack_yes_no_dialog(question, choices, def));
1054 }
1055
1056 /* Only here if main window is not present */
1057 while (result < 0) {
1058 ch = gnome_nhgetch();
1059 if (ch == '\033') {
1060 result = yn_esc_map;
1061 } else if (choices && !strchr(choices, ch)) {
1062 /* FYI: ch==-115 is for KP_ENTER */
1063 if (def
1064 && (ch == ' ' || ch == '\r' || ch == '\n' || ch == -115)) {
1065 result = def;
1066 } else {
1067 gnome_nhbell();
1068 /* and try again... */
1069 }
1070 } else {
1071 result = ch;
1072 }
1073 }
1074 return result;
1075}
1076
1077/*
1078getlin(const char *ques, char *input)

Callers

nothing calls this directly

Calls 6

ghack_get_main_windowFunction · 0.85
eosFunction · 0.85
gnome_putstrFunction · 0.85
ghack_yes_no_dialogFunction · 0.85
gnome_nhgetchFunction · 0.85
gnome_nhbellFunction · 0.85

Tested by

no test coverage detected