PDA

View Full Version : Please help me test curses colors.



guesst
04-14-2008, 08:15 AM
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



#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:

heras
04-14-2008, 11:47 AM
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.

guesst
04-14-2008, 09:03 PM
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:

#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 ();
}

heras
04-15-2008, 10:17 AM
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.

dwks
04-15-2008, 01:31 PM
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.)

From my curses.h:

/* $Id: curses.h.in,v 1.184 2008/03/08 21:03:48 tom Exp $ */

You might want to look at these pages, too.
http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=use_default_colors
http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=has_colors#7

guesst
04-16-2008, 07:59 AM
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.

dwks
04-16-2008, 11:35 AM
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.

brewbuck
04-16-2008, 11:43 AM
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.

dwks
04-16-2008, 11:47 AM
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.

brewbuck
04-16-2008, 12:12 PM
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.

guesst
04-16-2008, 06:43 PM
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:

#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 ();
}

Vicious
04-16-2008, 08:20 PM
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.

brewbuck
04-16-2008, 09:22 PM
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

guesst
04-17-2008, 11:20 AM
You forgot to link with -lcurses

No, I forgot to #include <curses.h>

Sorry 'bout that. Fixed now.

dwks
04-17-2008, 12:05 PM
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.

Vicious
04-17-2008, 12:05 PM
It was my fault, I didn't remember to link -lcurses. I'll try it again when I get home!

I'll be using Mepis 7.0 64-bit.

Vicious
04-17-2008, 05:14 PM
Okay, the first picture is the one you posted first. The other picture is the last one you posted.

.. on Mepis 7

guesst
04-17-2008, 08:32 PM
I'm inclined to cus at this point. I mean, why is the other block not bold colors? I want to figure out how, with attrset, attron, etc to get bold colors, where white is white, not gray, and bright blue, and dark green. See my original screen cap. See those bright colors? Why can't I access them in linux? *sigh*

Nevermind. I know now I just need to take my tetris program and have it designate half the colors for the background/shadow and half of them for the blocks, regardless of what they happen to be. I'm gonna rewrite my tetirs program anyways with structs and a little cleaner.

Vicious
04-18-2008, 08:09 AM
If it matters at all, my default konsole background is the "transparent" you see behind some of the "#"

guesst
04-18-2008, 09:23 AM
If it matters at all, my default konsole background is the "transparent" you see behind some of the "#"

I'll bet that would make tetris look cool.