/* Ask a simple Yes/No (and optionally All) question, specified in msg, * on the statusbar. Return 1 for Yes, 0 for No, 2 for All (if all is * TRUE when passed in), and -1 for Cancel. */ int do_yesno_prompt(bool all, const char *msg) { int ok = -2, width = 16; const char *yesstr; /* String of Yes characters accepted. */ const char *nostr; /* Same for No. */ const char *allstr; /* And All, surprise! */ int oldmenu = currmenu; assert(msg != NULL); /* yesstr, nostr, and allstr are strings of any length. Each string * consists of all single-byte characters accepted as valid * characters for that value. The first value will be the one * displayed in the shortcuts. */ /* TRANSLATORS: For the next three strings, if possible, specify * the single-byte shortcuts for both your language and English. * For example, in French: "OoYy" for "Oui". */ yesstr = _("Yy"); nostr = _("Nn"); allstr = _("Aa"); do { int kbinput; functionptrtype func; #ifndef DISABLE_MOUSE int mouse_x, mouse_y; #endif if (!ISSET(NO_HELP)) { char shortstr[3]; /* Temporary string for (translated) " Y", " N" and " A". */ if (COLS < 32) width = COLS / 2; /* Clear the shortcut list from the bottom of the screen. */ blank_bottombars(); /* Now show the ones for "Yes", "No", "Cancel" and maybe "All". */ sprintf(shortstr, " %c", yesstr[0]); wmove(bottomwin, 1, 0); onekey(shortstr, _("Yes"), width); if (all) { shortstr[1] = allstr[0]; wmove(bottomwin, 1, width); onekey(shortstr, _("All"), width); } shortstr[1] = nostr[0]; wmove(bottomwin, 2, 0); onekey(shortstr, _("No"), width); wmove(bottomwin, 2, width); onekey("^C", _("Cancel"), width); } if (interface_color_pair[TITLE_BAR].bright) wattron(bottomwin, A_BOLD); wattron(bottomwin, interface_color_pair[TITLE_BAR].pairnum); blank_statusbar(); mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); wattroff(bottomwin, A_BOLD); wattroff(bottomwin, interface_color_pair[TITLE_BAR].pairnum); /* Refresh edit window and statusbar before getting input. */ wnoutrefresh(edit); wnoutrefresh(bottomwin); currmenu = MYESNO; kbinput = get_kbinput(bottomwin); #ifndef NANO_TINY if (kbinput == KEY_WINCH) continue; #endif func = func_from_key(&kbinput); if (func == do_cancel) ok = -1; #ifndef DISABLE_MOUSE else if (kbinput == KEY_MOUSE) { /* We can click on the Yes/No/All shortcut list to * select an answer. */ if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 && wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE) && mouse_x < (width * 2) && mouse_y > 0) { int x = mouse_x / width; /* Calculate the x-coordinate relative to the * two columns of the Yes/No/All shortcuts in * bottomwin. */ int y = mouse_y - 1; /* Calculate the y-coordinate relative to the * beginning of the Yes/No/All shortcuts in * bottomwin, i.e. with the sizes of topwin, * edit, and the first line of bottomwin * subtracted out. */ assert(0 <= x && x <= 1 && 0 <= y && y <= 1); /* x == 0 means they clicked Yes or No. y == 0 * means Yes or All. */ ok = -2 * x * y + x - y + 1; if (ok == 2 && !all) ok = -2; } } #endif /* !DISABLE_MOUSE */ else if (func == total_refresh) { total_redraw(); continue; } else { /* Look for the kbinput in the Yes, No and (optionally) * All strings. */ if (strchr(yesstr, kbinput) != NULL) ok = 1; else if (strchr(nostr, kbinput) != NULL) ok = 0; else if (all && strchr(allstr, kbinput) != NULL) ok = 2; } } while (ok == -2); currmenu = oldmenu; return ok; }
int do_dictionary_prompt(bool all, const char *msg, char *str) { s_list l; s_node *p; int ok = -2, width = 16; const char *yesstr; /* String of Yes characters accepted. */ const char *nostr; /* Same for No. */ const char *allstr; /* And All, surprise! */ int u; char **thisarray = (char **)malloc(sizeof(char)*5); for(u = 0; u < 5; u++) thisarray[u] = (char *)malloc(sizeof(char)*16); thisarray = thisfunc(str); int oldmenu = currmenu; char but[16]; int i, j = 0; int count = 0; int t = 0; int bs = 0; char buf[16]; strcpy(buf, str); int tp; int we = 0, wc = 0; tp = typepos(); assert(msg != NULL); s_init(&l); u = 0; while(u < 5) { s_append(&l, thisarray[u]); u++; } /*Now partial matched list is prepared*/ p = l.head; if(str == NULL){ count = 0; while(p){ count++; p = p->next; } } //count=5; p = l.head; do { int kbinput; functionptrtype func; i = 0; #ifndef DISABLE_MOUSE int mouse_x, mouse_y; #endif if (!ISSET(NO_HELP)) { char shortstr[3]; /* Temporary string for (translated) " Y", " N" and " A". */ if (COLS < 32) width = COLS / 2; /* Clear the shortcut list from the bottom of the screen. */ blank_bottombars(); /* Now show the ones for "Yes", "No", "Cancel" and maybe "All". */ if (all) { shortstr[1] = allstr[0]; wmove(bottomwin, 1, width); onekey(shortstr, _("All"), width); } for(i = 0; i < count && i < 5; i++){ sprintf(but, "%d", i + 1); if(i == 0) wmove(bottomwin, 1, 0); else wmove(bottomwin, 1, i * width); if(p){ onekey(but, p->word, width); p = p->next; } j++; } wmove(bottomwin, 1, i * width); onekey("^C", _("Cancel"), width); } if (interface_color_pair[TITLE_BAR].bright) wattron(bottomwin, A_BOLD); wattron(bottomwin, interface_color_pair[TITLE_BAR].pairnum); blank_statusbar(); mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); wattroff(bottomwin, A_BOLD); wattroff(bottomwin, interface_color_pair[TITLE_BAR].pairnum); /* Refresh edit window and statusbar before getting input. */ wnoutrefresh(edit); wnoutrefresh(bottomwin); currmenu = MYESNO; kbinput = get_kbinput(bottomwin); #ifndef NANO_TINY if (kbinput == KEY_WINCH) continue; #endif /*49 is 1, 50 is 2 and so on*/ func = func_from_key(&kbinput); if (func == do_cancel){ ok = 0; return ok; } if(kbinput == 's'){ if(i == 5) { continue; } } if(kbinput <= '0' || kbinput > '0' + count) return -1; if(kbinput > '0' && kbinput <= '0' + count){ p = l.head; i = kbinput - '0' - 1; if(j > 5) t = j - 5 + i; else t = i; while(t--) if(p){ p = p->next; } if(tp == 1 || tp == 2){ bs = strlen(str); while(bs--) do_backspace(); } if(tp == 6 || tp == 7){ if(str != NULL){ we = openfile->current_x; while(openfile->current->data[we] != ' ' && openfile->current->data[we] != '\00'){ we++; wc++; do_right(); } we--; while(openfile->current->data[we] != ' ' && openfile->current->data[we] != '\00'){ do_backspace(); we--; } } } do_output(p->word, strlen(p->word), FALSE); return tp; } else if (func == total_refresh) { total_redraw(); continue; } else { /* Look for the kbinput in the Yes, No and (optionally) * All strings. */ if (strchr(yesstr, kbinput) != NULL) ok = 1; else if (strchr(nostr, kbinput) != NULL) ok = 0; else if (all && strchr(allstr, kbinput) != NULL) ok = 2; } i = 0; p = l.head; } while (ok == -2); currmenu = oldmenu; return ok; }
/* Display the shortcut list in s on the last two rows of the bottom * portion of the window. */ void bottombars(int menu) { size_t i = 0, colwidth, slen; const sc *s; /* Set the global variable to the given menu. */ currmenu = menu; if (ISSET(NO_HELP)) { return; } if (menu == MMAIN) { slen = MAIN_VISIBLE; assert(slen <= length_of_list(menu)); } else { slen = length_of_list(menu); /* Don't show any more shortcuts than the main list does. */ if (slen > MAIN_VISIBLE) { slen = MAIN_VISIBLE; } } /* There will be this many characters per column, except for the * last two, which will be longer by (COLS % colwidth) columns so as * to not waste space. We need at least three columns to display * anything properly. */ colwidth = COLS / ((slen / 2) + (slen % 2)); blank_bottombars(); DEBUG_LOG("In bottombars, and slen == " << slen); DEBUG_LOG("Checking menu items...."); for (auto f : allfuncs) { if ((f->menus & menu) == 0) { continue; } if (f->desc == "") { continue; } DEBUG_LOG("found one! f->menus = " << f->menus << ", desc = \"" << f->desc << '"'); s = first_sc_for(menu, f->scfunc); if (s == NULL) { DEBUG_LOG("Whoops, guess not, no shortcut key found for func!"); continue; } wmove(bottomwin, 1 + i % 2, (i / 2) * colwidth); DEBUG_LOG("Calling onekey with keystr \"" << s->keystr << "\" and desc \"" << f->desc << '"'); onekey(s->keystr, _(f->desc.c_str()), colwidth + (COLS % colwidth)); if (++i >= slen) { break; } } wnoutrefresh(bottomwin); reset_cursor(); wnoutrefresh(edit); }