MCPcopy Index your code
hub / github.com/NetHack/NetHack / query_attr

Function query_attr

src/coloratt.c:395–472  ·  view source on GitHub ↗

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...] */

Source from the content-addressed store, hash-verified

393 for status highlighting, multiple attributes are allowed [overkill;
394 life would be much simpler if that were restricted to one also...] */
395int
396query_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 }

Callers 4

handler_petattrFunction · 0.85
handler_menu_colorsFunction · 0.85
query_color_attrFunction · 0.85
status_hilite_menu_addFunction · 0.85

Calls 3

add_menuFunction · 0.85
select_menuFunction · 0.85
strncmpiFunction · 0.70

Tested by

no test coverage detected