Jump to content
  • Advertisement
Sign in to follow this  
inanhour&

ncurses: problem with highlighting a line of characters

This topic is 1722 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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(){

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

    

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

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

    attroff(COLOR_PAIR(5)|A_BLINK);

    

    refresh();

    getch();

    endwin();

    

    return 0;

}

Edited by inanhour&

Share this post


Link to post
Share on other sites
Advertisement

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.  http://www.gnu.org/software/ncurses/ncurses.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!