User Contributed Notes 16 notes

Not calling ncurses_end() can (will) cause issues with terminals. Although registering a shutdown function which includes ncurses_end() may help, sometimes things go awry and you're stuck with a terminal that is acting in strange ways.

This can be fixed! *NIX systems (FreeBSD, Linux, UNIX, et al.) usually support the 'reset' command which resets the terminal settings and allows you to get things back to normal.

Here is a function that takes an associative array, presents a menu in a new window, allows the user to make a choice using up and down arrows and the enter key, and returns the value of the menu item.

Limitations include:No way of scrolling a long list, either horiontally or vertically;No arguments for placement on screen, although this is easy to add;No multiple selection;Will produce all kinds of errors and warnings if the terminal is smaller than is necessary to create the window.

I'm very new at using the ncurses library; Comments and improvements would be greatly appreciated!

What if you want to draw a new window and after removing it, showing the pervious screen again? Unfortunately, there is no such a thing in php/ncurses as there is in original curses library (touchwin if I'm not mistaken - It has been a long time!). However, you can do this by a simple trick! You can dump the screen to a temp file and then restore it backagain!Take a look at this function:

# Function: show_a_win()# - Displays a small window and writes something in it.# - waits for a key# - shows the pervious screen againfunction show_a_win(){ # Dump the current screen into a temp file: $tmpfile = tempnam("/tmp", "dump."); # Create a new window. $newwin = ncurses_newwin(4, 60, 10, 10); # Write something and then refresh it ncurses_mvwaddstr($newwin, 1, 1, "This is a test."); ncurses_wrefresh($newwin); # Wait for a key ncurses_wgetch($newwin); ncurses_delwin($newwin); /* delete the window */ /* Restore the screen the same way it was before entering * into the function: */ ncurses_scr_restore($tmpfile); unlink($tmpfile); /* Remove temp file */}

Here is a function which would do the job for missingncurses_wclrtoeol() function:/* wclrtoeol() * Erases the current line to the right of the cursor*/function wclrtoeol($win){ # get current position ncurses_getyx($win, &$crow, &$ccol); # get maximum row and col for this window: ncurses_getmaxyx($win, &$max_row, &$max_col); for ($col = $ccol; $col < $max_col; $col ++){ ncurses_wmove($win, $crow, $col); ncurses_waddch($win, 32); }}

I had a small problem building php+ncurses support.ncurses include files were installed in:ncurses_installed_dir/include/ncursesThis caused problems when building php with ncurse support.php was looking for include files in:ncurses_installed_dir/include However, include files were located in include/ncurses

I had to make symbolic links of files in ncurses directory so php could see them:# cd ncurses_insalled_directory/include# ln -s ncurses/* .After that it worked.

See the documentation for ncurses_border and ncurses_wrefresh for some more examples of doing windowing and dynamic sizing.. I also posted some information to the zend.com code-gallery for doing ncurses under php.