Why is my Perl curses window not working?

This may be a problem with my understanding with Curses more than with Perl, but please help me. I use Curses.pm, which works pretty well, except when I try to create a window curse. Code example:

use Curses; initscr; $w=newwin(1,1,40,40); $w->addstr(20,20,"Hello"); $w->refresh; refresh; endwin; 

nothing output. Not using a window works fine:

 use Curses; initscr; $w=newwin(1,1,40,40); addstr(20,20,"Hello"); refresh; endwin; 
+4
source share
1 answer

You need your arguments in the right place, and it’s not easy to remember what a number is. I always need to look for this by first trying all the wrong permutations. I just look at the manual pages for the C interface, and then change it to Perl syntax.

The newwin function registered on the curs_window page accepts:

 newwin( height, width, starty, startx ) 

You set up a window with one row high and one column width starting from column 40 of row 40. However, then you addstr to put text in row 20 of column 20 in this window. This is outside the 1x1 frame that you configured, so you don’t see anything.

Try this to see if it works for you. If this works, try adjusting the window values ​​to get the frame 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; 
+8
source

All Articles