char* gui_input_askstring ( const char *  question,
const char *  defstr,
int(*)(const char *str, char c)  validator 
)

Display a string input question at the bottom of the screen and return the user response.

Definition at line 695 of file gui_input.c.

00697 {
00698         GString *msg;
00699         unsigned int origlen, newlen;
00700         int c, clearfirst = 0;
00701         char *ret = NULL;
00702         const char *vstr;
00703 
00704         msg = g_string_new(question);
00705         g_string_append(msg, ": ");
00706         origlen = msg->len;
00707         if (defstr != NULL) {
00708                 g_string_append(msg, defstr);
00709                 clearfirst = 1;
00710         }
00711 
00712         for(;;) {
00713                 gui_msgbar_ask(msg->str);
00714 
00715                 switch (c = gui_input_getch()) {
00716                 case '\r':
00717                         goto done;
00718                 case KEY_BACKSPACE:
00719                         clearfirst = 0;
00720                         if (msg->len > origlen) {
00721                                 /* Prompt has contents */
00722                                 g_string_truncate(msg, msg->len - 1);
00723                         }
00724                         break;
00725                 case CTRL('C'):
00726                 case CTRL('['):
00727                         /* Just empty the return */
00728                         g_string_truncate(msg, origlen);
00729                         goto done;
00730                 case CTRL('U'):
00731                         g_string_truncate(msg, origlen);
00732                         break;
00733                 case CTRL('W'):
00734                         clearfirst = 0;
00735                         newlen = gui_input_trimword(msg);
00736                         g_string_truncate(msg, MAX(newlen, origlen));
00737                         break;
00738                 default:
00739                         /* Control characters are not allowed */
00740                         if (g_ascii_iscntrl(c))
00741                                 break;
00742 
00743                         if (validator != NULL) {
00744                                 vstr = clearfirst ? "" : msg->str + origlen;
00745                                 if (validator(vstr, c) != 0)
00746                                         break;
00747                         }
00748                         if (clearfirst) {
00749                                 g_string_truncate(msg, origlen);
00750                                 clearfirst = 0;
00751                         }
00752                         g_string_append_c(msg, c);
00753                 }
00754         }
00755 
00756 done:
00757         gui_msgbar_flush();
00758 
00759         /* Only return a string when there are contents */
00760         if (msg->len > origlen)
00761                 ret = g_strdup(msg->str + origlen);
00762 
00763         g_string_free(msg, TRUE);
00764         return ret;
00765 }

Here is the call graph for this function:

Here is the caller graph for this function:

 All Data Structures Files Functions Variables Defines
Generated on Mon Mar 15 04:45:23 2010 for herrie by  doxygen 1.6.3