| 472 | } |
| 473 | |
| 474 | int |
| 475 | query_color(const char *prompt, int dflt_color) |
| 476 | { |
| 477 | winid tmpwin; |
| 478 | anything any; |
| 479 | int i, pick_cnt; |
| 480 | menu_item *picks = (menu_item *) 0; |
| 481 | |
| 482 | /* replace user patterns with color name ones and force 'menucolors' On */ |
| 483 | basic_menu_colors(TRUE); |
| 484 | |
| 485 | tmpwin = create_nhwindow(NHW_MENU); |
| 486 | start_menu(tmpwin, MENU_BEHAVE_STANDARD); |
| 487 | any = cg.zeroany; |
| 488 | for (i = 0; i < SIZE(colornames); i++) { |
| 489 | if (!colornames[i].name) |
| 490 | break; |
| 491 | any.a_int = i + 1; |
| 492 | add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, |
| 493 | ATR_NONE, NO_COLOR, colornames[i].name, |
| 494 | (colornames[i].color == dflt_color) ? MENU_ITEMFLAGS_SELECTED |
| 495 | : MENU_ITEMFLAGS_NONE); |
| 496 | } |
| 497 | end_menu(tmpwin, (prompt && *prompt) ? prompt : "Pick a color"); |
| 498 | pick_cnt = select_menu(tmpwin, PICK_ONE, &picks); |
| 499 | destroy_nhwindow(tmpwin); |
| 500 | |
| 501 | /* remove temporary color name patterns and restore user-specified ones; |
| 502 | reset 'menucolors' option to its previous value */ |
| 503 | basic_menu_colors(FALSE); |
| 504 | |
| 505 | if (pick_cnt > 0) { |
| 506 | i = colornames[picks[0].item.a_int - 1].color; |
| 507 | /* pick_cnt==2: explicitly picked something other than the |
| 508 | preselected entry */ |
| 509 | if (pick_cnt == 2 && i == NO_COLOR) |
| 510 | i = colornames[picks[1].item.a_int - 1].color; |
| 511 | free((genericptr_t) picks); |
| 512 | return i; |
| 513 | } else if (pick_cnt == 0) { |
| 514 | /* pick_cnt==0: explicitly picking preselected entry toggled it off */ |
| 515 | return dflt_color; |
| 516 | } |
| 517 | return -1; |
| 518 | } |
| 519 | |
| 520 | DISABLE_WARNING_FORMAT_NONLITERAL |
| 521 |
no test coverage detected