Sign in to follow this  

ncurses: problem with highlighting a line of characters

Recommended Posts

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.


#include <ncurses.h>


int main(){







    int maxX=0, maxY=0;

    getmaxyx(stdscr, maxY, maxX);


    init_pair(5, 15, 10);



    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? sad.png


    mvaddch(7, maxX-1, inch());

    mvaddch(7, maxX-2, 'c');        //works as expected







    return 0;


Edited by inanhour&

Share this post

Link to post
Share on other sites

I have not touched ncurses in a super long time and that was only bare basics.  Not many people use this library too much anymore because the days of full blown terminal applications have hit the wayside.  It is not all that common to make these types of applications anymore.


The library is indeed still in use as it can still be handy from time to time.  I did some searching around for you as I have been a Linux junky for years but have never had the chance to fully switch yet due to school related stuff requiring VS and crap.   I found the mailing list for ncurses.  It is technically a bug mailing list but looking through the archives people also ask use questions there so you should get a answer to your issue.


Here is a link for you the instructions are down towards the bottom of the page.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this