Talk:Menucolors

From NetHackWiki
Jump to: navigation, search

What the heck is "globbing"? --ZeroOne 06:13, 20 August 2006 (UTC)

Globbing is what most shells support. You can use things like "*.txt" to match "schedule.txt", "fun_stuff.txt", and so on. * matches any number of characters (including 0), ? matches exactly one character. --Eidolos 06:15, 20 August 2006 (UTC)

If anyone is interested, I compiled a version of nethack-3.4.3 with both menucolors and autopick_exceptions for windows. The windows binary of menucolors doesn't have autopickup_exceptions which I can't live without anymore. Addps4cat 13:11, 7 September 2007 (UTC)

I'd be interested in that.... --Snicker 12:41, 11 September 2007 (UTC)
NetHack w/ Color and autopickup exceptions.Addps4cat 01:00, 13 September 2007 (UTC)
Thanks!!! --170.189.193.3 16:54, 14 September 2007 (UTC)

Weird menucolors problem on Ubuntu GNU/Linux

Is anyone else having an odd problem where some menucolors don't work? I simply copied Eidolos' file, and as far as I can tell, only the options with parentheses in them don't work, e.g.:

MENUCOLOR=" uncursed"=white

works fine, but

MENUCOLOR=" uncursed| UC?($| )"=white

doesn't.

--Nightpenguin 21:28, 11 May 2011 (UTC)

Guessing, off the top of my hat: Gnu and Posix regular expressions differ in whether parentheses need to be escaped, and NAO switched regexp libraries at some point. Did you check your linker options match your config? --Tjr 10:39, 12 May 2011 (UTC)
I'm not quite sure what you're saying, but escaping parentheses with \ doesn't work either. --Nightpenguin 21:12, 12 May 2011 (UTC)
It's a bit more complicated. 1. There are no different regexp libraries. Glibc provides both GNU and POSIX regexp so you can't really determine which is used by looking at the libraries a binary is using. 2. GNU and POSIX regular expressions don't differ in how they need escaping parentheses but basic and extended (GNU|POSIX) regexp do differ. See this page especially the table with "Quantifiers" and look at the differences between "POSIX BRE", "POSIX ERE", "GNU BRE", and "GNU ERE".
Now the real difference is that NAO has using of the POSIX extended regexps hardcoded while the standard menucolors patch uses GNU basic regexps by default (even though glibc provides support for GNU extended regexps). --Bhaak 21:55, 12 May 2011 (UTC)

recent menucolors changes on nao

There has been a flurry of updates to NAO recently, e.g. statuscolors, hitpointbar, menu_glpyhs.

Several players noticed some problems with their menucolors. Raisse reported that this line:

MENUCOLOR="[a-zA-Z] - [a-zA-Z ]+ [0-9]\*   [a-z]+ +[0-9]+%"=black

was no longer matching, leaving forgotten spells gray instead of turning them black. I noticed that some of my entries like this one:

MENUCOLOR:"[a-zA-Z] - (a|an|the|[0-9]{1,4}) uncursed"=cyan

similarly failed to match inventory items.

I have been able to track down the change to the sourcecode that I think is responsible for these problems.

Check out wintty.c, specfically the function tty_add_menu.

This is it in vanilla with the menucolors patch:

/*ARGSUSED*/
/*
 * Add a menu item to the beginning of the menu list.  This list is reversed
 * later.
 */
void
tty_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected)
    winid window;    /* window to use, must be of type NHW_MENU */
    int glyph;        /* glyph to display with item (unused) */
    const anything *identifier;    /* what to return if selected */
    char ch;        /* keyboard accelerator (0 = pick our own) */
    char gch;        /* group accelerator (0 = no group) */
    int attr;        /* attribute for string (like tty_putstr()) */
    const char *str;    /* menu string */
    boolean preselected; /* item is marked as selected */
{
    register struct WinDesc *cw = 0;
    tty_menu_item *item;
    const char *newstr;
    char buf[4+BUFSZ];
 
    if (str == (const char*) 0)
    return;
 
    if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0
        || cw->type != NHW_MENU)
    panic(winpanicstr,  window);
 
    cw->nitems++;
    if (identifier->a_void) {
    int len = strlen(str);
    if (len >= BUFSZ) {
        /* We *think* everything's coming in off at most BUFSZ bufs... */
        impossible("Menu item too long (%d).", len);
        len = BUFSZ - 1;
    }
    Sprintf(buf, "%c - ", ch ? ch : '?');
    (void) strncpy(buf+4, str, len);
    buf[4+len] = '\0';
    newstr = buf;
    } else
    newstr = str;
 
    item = (tty_menu_item *) alloc(sizeof(tty_menu_item));
    item->identifier = *identifier;
    item->count = -1L;
    item->selected = preselected;
    item->selector = ch;
    item->gselector = gch;
    item->attr = attr;
    item->str = copy_of(newstr);
 
    item->next = cw->mlist;
    cw->mlist = item;
}

And this is it in the current incarnation of NAOhack:

/*ARGSUSED*/
/*
 * Add a menu item to the beginning of the menu list.  This list is reversed
 * later.
 */
void
tty_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected)
    winid window;    /* window to use, must be of type NHW_MENU */
    int glyph;        /* glyph to display with item */
    const anything *identifier;    /* what to return if selected */
    char ch;        /* keyboard accelerator (0 = pick our own) */
    char gch;        /* group accelerator (0 = no group) */
    int attr;        /* attribute for string (like tty_putstr()) */
    const char *str;    /* menu string */
    boolean preselected; /* item is marked as selected */
{
    register struct WinDesc *cw = 0;
    tty_menu_item *item;
 
    if (str == (const char*) 0)
    return;
 
    if (window == WIN_ERR || (cw = wins[window]) == (struct WinDesc *) 0
        || cw->type != NHW_MENU)
    panic(winpanicstr,  window);
 
    cw->nitems++;
 
    item = (tty_menu_item *) alloc(sizeof(tty_menu_item));
    item->identifier = *identifier;
    item->count = -1L;
    item->selected = preselected;
    item->selector = ch;
    item->gselector = gch;
    item->attr = attr;
    item->str = copy_of(str);
    item->glyph = glyph;
 
    item->next = cw->mlist;
    cw->mlist = item;
}

I generated this code by taking fresh copies of the source from the nethack website, applying the menucolors patch to one copy, and the NAO patch to the other.

item->str eventually makes its way to get_menu_coloring, where it is matched against by the regexes you use to define your menucolors. With just the menucolor patch item->str gets the inventory/spell letter and hyphen prepended to it (e.g. "q - a club" or "a - force bolt"), with the NAOhack patch it does not (e.g. "a club" or "force bolt"). This jives with my testing on NAO. Thus if any of your menucolors relied on being able to match against the inventory/spell letter and hyphen (as some of mine and Raisse's did), they will now fail to match.

I believe this change was introduced in the latest round of patches, possible while coding in menu_glyphs. Turning menu_glyphs on and off appears to have no effect on this, so it is not possible for players to individually reverse this change and restore their menucolors. (Though correcting the menucolors so they work again is very simple: just stop matching against the letter and hyphen.)

The same effect holds for every other menu in the game. Under options, the regex "autodig" matches the first option, but "a - autodig" matches nothing. Under the #name menu "Name a monster" matches, but not "a - Name a monster". Under the new generic item use menu (go to inventory, select an item), "Open this container" matches but not "a - Open this container". When you are looting a container "Put something into" matches but not "i - Put something into". Those are all the menus I tested but I'm confident this holds true for any menu in general.

Something else I've noticed while testing on NAO: if you turn menu_glyphs on, the little glyph that appears before each item in your inventory (but after the inventory letter and hyphen) is also not part of the string sent to the menucolors regex. That means you can't match against it. (If you could it would be a hackish but intuitive and easy way to make menucolors apply to only certain item classes.)

I was thinking about updating this page with some more information about exactly what the menucolors regex matches against. Not sure any of this is that important, but it was interesting enough for me to go digging to figure out what was going on.

Any thoughts? Anyone else look at this issue already? This is an area of the code I am not at all familiar with, and I can't compile nethack myself to do any real testing, all I can look at is correlations.

Blackcustard (talk) 00:47, 10 June 2012 (UTC)