Unix Programming - Problems with ncurses

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2004 > Problems with ncurses





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Problems with ncurses
Calle

2004-06-26, 10:11 am

I have some problems with ncurses.
Could someone tell me why it doesn't print anything out?

#include <ncurses.h>

int main()
{
initscr();
cbreak();
noecho();
start_color();

int lines, cols;
WINDOW *win;

getmaxyx(stdscr, lines, cols);

win = newwin(lines, cols, 0, 0);
init_pair(1, COLOR_RED, COLOR_BLACK);
attrset(COLOR_PAIR(1) | A_BOLD);
wattrset(win, COLOR_PAIR(1));

wrefresh(win);

mvwprintw(win, (lines + 0), (cols), "Line 1");
mvwprintw(win, (lines + 1), (cols), "Line 2");
mvwprintw(win, (lines + 2), (cols), "Line 3");
mvwprintw(win, (lines + 3), (cols), "Line 4");

wrefresh(win);

getch();

endwin();
return 0;
}

Thank you for your help!
Eric Enright

2004-06-26, 10:11 am

Calle wrote:
>I have some problems with ncurses.
>Could someone tell me why it doesn't print anything out?
>
>#include <ncurses.h>
>
>int main()
>{
> initscr();
> cbreak();
> noecho();
> start_color();
>
> int lines, cols;
> WINDOW *win;
>
> getmaxyx(stdscr, lines, cols);
>
> win = newwin(lines, cols, 0, 0);
> init_pair(1, COLOR_RED, COLOR_BLACK);
> attrset(COLOR_PAIR(1) | A_BOLD);
> wattrset(win, COLOR_PAIR(1));
>
> wrefresh(win);


Adding:

refresh();

here makes it work almost how you want,

> mvwprintw(win, (lines + 0), (cols), "Line 1");
> mvwprintw(win, (lines + 1), (cols), "Line 2");
> mvwprintw(win, (lines + 2), (cols), "Line 3");
> mvwprintw(win, (lines + 3), (cols), "Line 4");


On my 80x24 terminal this tries to print the four lines at:
80x24, 80x25, 80x26 and 80x27, which are all out of bounds.
Valid coordinates are
y = 0 to (lines - 1), and
x = 0 to (cols - 1)

>
> wrefresh(win);
>
> getch();
>
> endwin();
> return 0;
>}
>
>Thank you for your help!


Hope that helps!

--
Eric Enright /"\
ericAtiptsoftDcom \ / ASCII Ribbon Campaign
X Against HTML E-Mail
Public Key: 0xBEDF636F / \
Thomas Dickey

2004-06-26, 10:11 am

Calle <calle8787@hotmail.com> wrote:
> I have some problems with ncurses.
> Could someone tell me why it doesn't print anything out?


The getch() refreshes stdscr, which overwrites the other windows.
See the discussion of doupdate() and wnoutrefresh().

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Wayne C. Morris

2004-06-26, 10:11 am

In article <f81f4cdc.0406231436.2e202dad@posting.google.com>,
calle8787@hotmail.com (Calle) wrote:

> I have some problems with ncurses.
> Could someone tell me why it doesn't print anything out?

[snip]
> win = newwin(lines, cols, 0, 0);

[snip]
> mvwprintw(win, (lines + 0), (cols), "Line 1");
> mvwprintw(win, (lines + 1), (cols), "Line 2");
> mvwprintw(win, (lines + 2), (cols), "Line 3");
> mvwprintw(win, (lines + 3), (cols), "Line 4");


Window coordinates start at (0, 0). You're trying to write starting at
(lines, cols), which is outside the window you created.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com