Search code examples
cterminalncurses

ncurses chgat function messes up line graphics/acs characters


My ncurses program uses addch to draw line graphics with ACS characters. For example, addch(ACS_VLINE). Then, I use chgat to change the attributes there (specifically, I make the character bold and change the color pair). However, when that happens, the line character that was on the screen is replaced with a letter. The vertical line is replaced with x, for example. Looking at this page, it seems like it's replacing the line character with the acsc char that it corresponds to. How do I make it not do that?


Solution

  • I did same bug. You lost an attribute A_ALTCHARSET. Special characters are some "normal" characters with attribute A_ALTCHARSET. When you masc this attribute (or if you do reset of this flag), then you see normal chars. You need to read original attribute, and if it uses A_ALTCHARSET you need it set again:

                    if (mvwinch(menu->shadow_window, i, j) & A_ALTCHARSET)
                        mvwchgat(menu->shadow_window, i, j, 1,
                                    shadow_attr | A_ALTCHARSET,
                                    config->menu_shadow_cpn,
                                    NULL);
                    else
                        mvwchgat(menu->shadow_window, i, j, 1,
                                    shadow_attr,
                                    config->menu_shadow_cpn,
                                    NULL);