This might be a problem with my understanding with Curses more than with Perl, but please help me out. I'm using Curses.pm which works quite well except when I try to create a curses "window". Example code:
use Curses;
initscr;
$w=newwin(1,1,40,40);
$w->addstr(20,20,"Hello");
$w->refresh;
refresh;
endwin;
outputs nothing. Not using a window works fine:
use Curses;
initscr;
$w=newwin(1,1,40,40);
addstr(20,20,"Hello");
refresh;
endwin;
You need to get your arguments in the right place, and it's not easy to remember what number is what. I always have to look it up after trying all the wrong permutations first. I just look at the man pages for the C interface and then change it to Perl syntax.
The newwin
function, documented in the curs_window man page, takes:
newwin( height, width, starty, startx )
You set up a window that was one row high and one column wide, starting at row 40 column 40. However, you then tell addstr
to put text at row 20 column 20 in that window. That's outside the 1x1 frame you set up, so you don't see anything.
Try this to see if it works for you. If that works, try adjusting the window values to get the frame that you want.
use Curses;
initscr;
$w = newwin(
1, # height (y)
COLS(), # width (x)
0, # start y
1 # start x
);
$w->addstr(
0, # relative y to window
0, # relative x to window
"Hello"
);
$w->refresh();
sleep 10;
endwin;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With