interactive key binding */
| 2288 | |
| 2289 | /* interactive key binding */ |
| 2290 | staticfn void |
| 2291 | handler_rebind_keys_add(boolean keyfirst) |
| 2292 | { |
| 2293 | struct ext_func_tab *ec; |
| 2294 | winid win; |
| 2295 | anything any; |
| 2296 | int i, npick; |
| 2297 | menu_item *picks = (menu_item *) 0; |
| 2298 | char buf[BUFSZ]; |
| 2299 | char buf2[QBUFSZ]; |
| 2300 | uchar key = '\0'; |
| 2301 | int clr = NO_COLOR; |
| 2302 | |
| 2303 | if (keyfirst) { |
| 2304 | pline("Bind which key? "); |
| 2305 | key = pgetchar(); |
| 2306 | |
| 2307 | if (!key || key == '\033') |
| 2308 | return; |
| 2309 | } |
| 2310 | |
| 2311 | win = create_nhwindow(NHW_MENU); |
| 2312 | start_menu(win, MENU_BEHAVE_STANDARD); |
| 2313 | any = cg.zeroany; |
| 2314 | |
| 2315 | if (key) { |
| 2316 | struct Cmd_bind *bind = cmdbind_get(key); |
| 2317 | |
| 2318 | if (bind && bind->cmd) { |
| 2319 | Sprintf(buf, "Key '%s' is currently bound to \"%s\".", |
| 2320 | key2txt(key, buf2), bind->cmd->ef_txt); |
| 2321 | } else { |
| 2322 | Sprintf(buf, "Key '%s' is not bound to anything.", |
| 2323 | key2txt(key, buf2)); |
| 2324 | } |
| 2325 | add_menu_str(win, buf); |
| 2326 | add_menu_str(win, ""); |
| 2327 | } |
| 2328 | |
| 2329 | any.a_int = -1; |
| 2330 | add_menu(win, &nul_glyphinfo, &any, '\0', 0, ATR_NONE, clr, |
| 2331 | "nothing: unbind the key", |
| 2332 | MENU_ITEMFLAGS_NONE); |
| 2333 | |
| 2334 | add_menu_str(win, ""); |
| 2335 | |
| 2336 | for (i = 0; i < extcmdlist_length; i++) { |
| 2337 | ec = &extcmdlist[i]; |
| 2338 | |
| 2339 | if ((ec->flags & (MOVEMENTCMD|INTERNALCMD|CMD_NOT_AVAILABLE)) != 0) |
| 2340 | continue; |
| 2341 | |
| 2342 | any.a_int = (i + 1); |
| 2343 | Sprintf(buf, "%s: %s", ec->ef_txt, ec->ef_desc); |
| 2344 | add_menu(win, &nul_glyphinfo, &any, '\0', 0, ATR_NONE, clr, buf, |
| 2345 | MENU_ITEMFLAGS_NONE); |
| 2346 | } |
| 2347 | if (key) |
no test coverage detected