Thread: Please help me test curses colors.

  1. #1
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179

    Please help me test curses colors.

    If you're not running windows will you please run this and then reply to this thread with:
    • A screen shot
    • What unix OS you're running


    Code:
    #include <curses.h>
    
    int main () {
      int x, y, c;
    
      initscr ();
      start_color ();
      c = 0;
      for (x = 0; x < 16; x++) for (y = 0; y < 16; y++) {
        init_pair (++c, x, y);
        attrset (COLOR_PAIR(c));
        mvaddch(y+2, x+5, (x > y) ? ACS_BOARD : ACS_BULLET);
      }
      refresh ();
      getch();
      endwin ();
    }
    I am running windows, so it looks like:
    Last edited by guesst; 04-14-2008 at 09:01 PM.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    The shell that is built into my editor has a white back ground (by default, before running your code), my terminal starts out black. Both get messed up afterwards.

  3. #3
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    Minor revision to above program.

    What are you running?

    Okay, if that first one craps out (I think ACS_BOARD doen't agree with everyone) run this instead:
    Code:
    #include <curses.h>
    
    int main () {
      int x, y, c;
    
      initscr ();
      start_color ();
      c = 0;
      for (x = 0; x < 16; x++) for (y = 0; y < 16; y++) {
        init_pair (++c, x, y);
        attrset (COLOR_PAIR(c));
        mvaddch(y+2, x+5, (x > y) ? '#' : '*');
      }
      refresh ();
      getch();
      endwin ();
    }
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    44
    Quote Originally Posted by guesst View Post
    What are you running?
    Forgot about that. Kubuntu 7.10, so that's:
    linux 2.6.22
    glibc 2.6.1
    gcc 4.1.3
    ncurses 5.6

    The new version behaves and behaves the same in both terminals.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I'm running AMD64 Debian GNU/Linux Lenny. For the second program, in a terminal emulator (gnome-terminal), I get exactly the same thing as heras did in post #4. In a full-screen terminal, the colours are the same, except that the asterisks turn into partially-filled blocks. Sorry, I can't really take a screenshot of this. They're sort of like guesst's original screenshot, except a little bit more of the centre is filled. (The first program is like heras's Konsole screenshot in gnome-terminal as well as in a fullscreen terminal.)

    [edit] From my curses.h:
    Code:
    /* $Id: curses.h.in,v 1.184 2008/03/08 21:03:48 tom Exp $ */
    [/edit]

    [edit=2] You might want to look at these pages, too.
    http://www.gsp.com/cgi-bin/man.cgi?s...default_colors
    http://www.gsp.com/cgi-bin/man.cgi?s...c=has_colors#7
    [/edit]
    Last edited by dwks; 04-15-2008 at 01:38 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    I wonder what would happen if I used the A_BOLD attribute. It doesn't do anything in windows, which is why I do it the way I do, but if in a linux environment that would work...

    I need to either commit to a dual boot or look into Cygwin.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You could even just get a Linux LiveCD, if you wanted to. If you have a fast internet connection, it wouldn't be too hard to download and burn one.

    Although I highly recommend Cygwin for other reasons, I'm not sure if its Linux emulation or whatever you want to call it is good enough that it would reproduce ncurses colours.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by guesst View Post
    I wonder what would happen if I used the A_BOLD attribute. It doesn't do anything in windows, which is why I do it the way I do, but if in a linux environment that would work...
    I would not have expected A_BOLD not to work on Windows, since the Windows standard terminal uses ANSI codes and ANSI definitely supports boldness. Weird. What do you see when you run your program in full-screen terminal mode?

    Also, what are you trying to learn through these tests? As far as I know, the default curses colors are mostly standardized.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by brewbuck View Post
    I would not have expected A_BOLD not to work on Windows, since the Windows standard terminal uses ANSI codes and ANSI definitely supports boldness.
    I'm pretty sure that my Windows 98 terminal (the only one I tested) did not use ANSI codes. It had ANSI.SYS somewhere, but it wasn't being used -- printing ANSI escape sequences had no effect besides some strange looking characters on the screen. Of course, this is for Windows 98.

    Also, what are you trying to learn through these tests? As far as I know, the default curses colors are mostly standardized.
    I think guesst is trying to write programs that people like me will be able to run. My Linux system displayed the colours of his Tetris program very strangely.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by dwks View Post
    I'm pretty sure that my Windows 98 terminal (the only one I tested) did not use ANSI codes. It had ANSI.SYS somewhere, but it wasn't being used -- printing ANSI escape sequences had no effect besides some strange looking characters on the screen. Of course, this is for Windows 98.
    That doesn't seem right, since the Windows terminal (especially the one pre-NT, like 95 and 98) were specifically meant to run DOS programs, and DOS programs use ANSI escapes extensively.

  11. #11
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    Quote Originally Posted by brewbuck View Post
    I would not have expected A_BOLD not to work on Windows, since the Windows standard terminal uses ANSI codes and ANSI definitely supports boldness. Weird. What do you see when you run your program in full-screen terminal mode?
    Yes, but notice that the "bold" colors are accessible through direct indexing, where as in Linux it appears not to be. So they're there, but like everything else Windows goes about it all wrong.

    Now, when I said that "A_BOLD" doesn't do anything I was mistaken. I've never gotten "setattr(A_BOLD);" to do anything, but if I attach it to a addch something like (I'm sure I'm screwing up the exact details) "addch('X'&COLOR_PAIR(1)&A_BOLD);" then it seems to work. Can't figure it out.

    Also, what are you trying to learn through these tests? As far as I know, the default curses colors are mostly standardized.
    Quote:
    Also, what are you trying to learn through these tests? As far as I know, the default curses colors are mostly standardized.
    I think guesst is trying to write programs that people like me will be able to run. My Linux system displayed the colours of his Tetris program very strangely.
    And BINGO was his name-o. I want my little project to be as cross-compatible friendly as possible, and when I see screen caps by DWKS, well it just makes me cry.

    But I think unless I get someone as crazy as I am dedicated to debugging my programs for their systems I'll need to load Linux up and buy myself "Linux for Dummies."

    However, if either of you two helpful people wouldn't mind, I have one more:
    Code:
    #include <curses.h>
    
    int main () {
      int x, y, c;
    
      initscr ();
      start_color ();
      c = 0;
      for (x = 0; x < COLORS; x++) for (y = 0; y < COLORS; y++) {
        init_pair (++c, x, y);
        attrset (COLOR_PAIR(c));
        mvaddch(y+2, x+5, (x > y) ? '#' : '/');
      }
      for (x = 0; x < COLORS; x++) for (y = 0; y < COLORS; y++) {
        init_pair (++c, x, y);
        attrset (COLOR_PAIR(c));
        attron (A_BOLD);
        mvaddch(8+y+2, 8+x+5, (x > y) ? '#' : '/');
      }
      refresh ();
      getch();
      endwin ();
    }
    Last edited by guesst; 04-17-2008 at 11:20 AM.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  12. #12
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Well, I was going to try it, but

    /home/sac/c/src/c.c:6: undefined reference to `initscr'
    /home/sac/c/src/c.c:7: undefined reference to `start_color'
    /home/sac/c/src/c.c:10: undefined reference to `init_pair'
    /home/sac/c/src/c.c:11: undefined reference to `stdscr'
    /home/sac/c/src/c.c:12: undefined reference to `stdscr'
    /home/sac/c/src/c.c:12: undefined reference to `wmove'
    /home/sac/c/src/c.c:12: undefined reference to `stdscr'
    /home/sac/c/src/c.c:12: undefined reference to `waddch'
    /home/sac/c/src/c.c:14: undefined reference to `stdscr'
    /home/sac/c/src/c.c:14: undefined reference to `wrefresh'
    /home/sac/c/src/c.c:15: undefined reference to `stdscr'
    /home/sac/c/src/c.c:15: undefined reference to `wgetch'
    /home/sac/c/src/c.c:16: undefined reference to `endwin'

    So not sure what that's about.
    What is C++?

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Vicious View Post
    Well, I was going to try it, but

    /home/sac/c/src/c.c:6: undefined reference to `initscr'
    /home/sac/c/src/c.c:7: undefined reference to `start_color'
    /home/sac/c/src/c.c:10: undefined reference to `init_pair'
    /home/sac/c/src/c.c:11: undefined reference to `stdscr'
    /home/sac/c/src/c.c:12: undefined reference to `stdscr'
    /home/sac/c/src/c.c:12: undefined reference to `wmove'
    /home/sac/c/src/c.c:12: undefined reference to `stdscr'
    /home/sac/c/src/c.c:12: undefined reference to `waddch'
    /home/sac/c/src/c.c:14: undefined reference to `stdscr'
    /home/sac/c/src/c.c:14: undefined reference to `wrefresh'
    /home/sac/c/src/c.c:15: undefined reference to `stdscr'
    /home/sac/c/src/c.c:15: undefined reference to `wgetch'
    /home/sac/c/src/c.c:16: undefined reference to `endwin'

    So not sure what that's about.
    You forgot to link with -lcurses

  14. #14
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    Quote Originally Posted by brewbuck View Post
    You forgot to link with -lcurses
    No, I forgot to #include <curses.h>

    Sorry 'bout that. Fixed now.
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Actually, they were really linker errors. But I'm sure it would be better to include curses.h anyway.

    Here's a screenshot from another Linux system, a 32-bit older Debian variant one. It looks quite nice.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 01:03 PM
  2. undefined reference
    By 3saul in forum Linux Programming
    Replies: 12
    Last Post: 08-23-2006, 05:28 PM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 12:55 PM
  4. MSVC Template Constructor/Assignment Errors
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:57 PM
  5. Fonts and colors in curses
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 02-26-2002, 06:22 AM