ncurses: problem with highlighting a line of characters

This is quite a specific question, but I couldn't find a forum on ncurses so I thought I might as well ask it here.
I am writing a program using ncurses that needs a function to highlight a line of characters on the screen. I started writing this function that took the x & y coordinates of a character on the screen and the length of characters after that to highlight. Whilst doing this I noticed that if I highlighted the last character in a row (maxX-1 in my example) it highlighted that character (as expected), and if I highlighted just the character before that (maxX-2) it also works. But if I do both, it highlights the whole row/line. Also, if there are characters in those spaces other than the 'space' character it works too, but for my program I need to be able to highlight empty spaces as well.

To highlight I am using inch() to get the character and addch() to print it because I am using some alternate characters that chgat() replaces with normal characters.

If anyone has any ideas why it could be doing this, that would be a great help, since this makes no sense to me and there must be something i'm missing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <ncurses.h>
 
int main(){
    initscr();
    start_color();
    use_default_colors();
    curs_set(0);
    noecho();
    
    int maxX=0, maxY=0;
    getmaxyx(stdscr, maxY, maxX);
    
    init_pair(5, 15, 10);
    
    attron(COLOR_PAIR(5)|A_BLINK);
    mvaddch(5, maxX-1, inch());     //works as expected
    
    mvaddch(6, maxX-1, inch());
    mvaddch(6, maxX-2, inch());     //highlights whole line for some reason? whyyy? :(
    
    mvaddch(7, maxX-1, inch());
    mvaddch(7, maxX-2, 'c');        //works as expected
    attroff(COLOR_PAIR(5)|A_BLINK);
    
    refresh();
    getch();
    endwin();
    
    return 0;
}
Works fine here.
Last edited on
Odd indeed. I'm on Slackware. Did you try setting attroff between mvaddch for curiosity?
Topic archived. No new replies allowed.