ask about highlighting attribute; for menu headers and menu coloring patterns, only one attribute at a time is allowed; for status highlighting, multiple attributes are allowed [overkill; life would be much simpler if that were restricted to one also...] */
| 393 | for status highlighting, multiple attributes are allowed [overkill; |
| 394 | life would be much simpler if that were restricted to one also...] */ |
| 395 | int |
| 396 | query_attr(const char *prompt, int dflt_attr) |
| 397 | { |
| 398 | winid tmpwin; |
| 399 | anything any; |
| 400 | int i, pick_cnt; |
| 401 | menu_item *picks = (menu_item *) 0; |
| 402 | boolean allow_many = (prompt && !strncmpi(prompt, "Choose", 6)); |
| 403 | int clr = NO_COLOR; |
| 404 | |
| 405 | tmpwin = create_nhwindow(NHW_MENU); |
| 406 | start_menu(tmpwin, MENU_BEHAVE_STANDARD); |
| 407 | any = cg.zeroany; |
| 408 | for (i = 0; i < SIZE(attrnames); i++) { |
| 409 | if (!attrnames[i].name) |
| 410 | break; |
| 411 | any.a_int = i + 1; |
| 412 | add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, |
| 413 | attrnames[i].attr, clr, attrnames[i].name, |
| 414 | (attrnames[i].attr == dflt_attr) ? MENU_ITEMFLAGS_SELECTED |
| 415 | : MENU_ITEMFLAGS_NONE); |
| 416 | } |
| 417 | end_menu(tmpwin, (prompt && *prompt) ? prompt : "Pick an attribute"); |
| 418 | pick_cnt = select_menu(tmpwin, allow_many ? PICK_ANY : PICK_ONE, &picks); |
| 419 | destroy_nhwindow(tmpwin); |
| 420 | if (pick_cnt > 0) { |
| 421 | int j, k = 0; |
| 422 | |
| 423 | if (allow_many) { |
| 424 | /* PICK_ANY, with one preselected entry (ATR_NONE) which |
| 425 | should be excluded if any other choices were picked */ |
| 426 | for (i = 0; i < pick_cnt; ++i) { |
| 427 | j = picks[i].item.a_int - 1; |
| 428 | if (attrnames[j].attr != ATR_NONE || pick_cnt == 1) { |
| 429 | switch (attrnames[j].attr) { |
| 430 | case ATR_NONE: |
| 431 | k = HL_NONE; |
| 432 | break; |
| 433 | case ATR_BOLD: |
| 434 | k |= HL_BOLD; |
| 435 | break; |
| 436 | case ATR_DIM: |
| 437 | k |= HL_DIM; |
| 438 | break; |
| 439 | case ATR_ITALIC: |
| 440 | k |= HL_ITALIC; |
| 441 | break; |
| 442 | case ATR_ULINE: |
| 443 | k |= HL_ULINE; |
| 444 | break; |
| 445 | case ATR_BLINK: |
| 446 | k |= HL_BLINK; |
| 447 | break; |
| 448 | case ATR_INVERSE: |
| 449 | k |= HL_INVERSE; |
| 450 | break; |
| 451 | } |
| 452 | } |
no test coverage detected