|
|
LXVII. Ncurses terminal screen control functionsIntroductie
ncurses (new curses) is a free software emulation of curses in
System V Rel 4.0 (and above). It uses terminfo format, supports pads,
colors, multiple highlights, form characters and function key mapping.
Because of the interactive nature of this library, it will be of little
use for writing Web applications, but may be useful when writing scripts meant
using PHP from the command line.
Waarschuwing | Deze module is
EXPERIMENTEEL. Dat betekent, dat het gedrag van deze
functies, deze functienamen, in concreto ALLES dat hier gedocumenteerd is in
een toekomstige uitgave van PHP ZONDER WAARSCHUWING kan veranderen. Wees
gewaarschuwd, en gebruik deze module op eigen risico. |
Ncurses is available for the following platforms:
AIX BeOS Cygwin Digital Unix (aka OSF1) FreeBSD GNU/Linux HPUX IRIX OS/2 SCO OpenServer Solaris SunOS
Afhankelijkheden
You need the ncurses libraries and headerfiles. Download the
latest version from the
or from an other GNU-Mirror.
Installatie
To get these functions to work, you have to compile the CGI or CLI
version of PHP with --with-ncurses[=DIR].
Configuratie tijdens scriptuitvoer
Het gedrag van deze functies wordt be�nvloed vanuit php.ini.
Tabel 1. Ncurses configuration options Name | Default | Changeable |
---|
ncurses.value | "42" | PHP_INI_ALL | ncurses.string | "foobar" | PHP_INI_ALL |
For further details and definition of the PHP_INI_* constants see
ini_set().
Resource typesDeze extensie maakt geen gebruik van resources. Voorgedefineerde constanten
Deze constanten worden gedefineerd door deze extensie, en
zullen alleen beschikbaar zijn als de extensie met PHP is
meegecompileerd, of als deze dynamisch is geladen vanuit een script.
Error codes
On error ncurses functions return NCURSES_ERR.
ColorsTabel 2. ncurses color constants constant | meaning |
---|
NCURSES_COLOR_BLACK | no color (black) | NCURSES_COLOR_WHITE | white | NCURSES_COLOR_RED | red - supported when terminal is in color mode | NCURSES_COLOR_GREEN | green - supported when terminal is in color mod | NCURSES_COLOR_YELLOW | yellow - supported when terminal is in color mod | NCURSES_COLOR_BLUE | blue - supported when terminal is in color mod | NCURSES_COLOR_CYAN | cyan - supported when terminal is in color mod | NCURSES_COLOR_MAGENTA | magenta - supported when terminal is in color mod |
KeysTabel 3. ncurses key constants constant | meaning |
---|
NCURSES_KEY_F0 - NCURSES_KEY_F64 | function keys F1 - F64 | NCURSES_KEY_DOWN | down arrow | NCURSES_KEY_UP | up arrow | NCURSES_KEY_LEFT | left arrow | NCURSES_KEY_RIGHT | right arrow | NCURSES_KEY_HOME | home key (upward+left arrow) | NCURSES_KEY_BACKSPACE | backspace | NCURSES_KEY_DL | delete line | NCURSES_KEY_IL | insert line | NCURSES_KEY_DC | delete character | NCURSES_KEY_IC | insert char or enter insert mode | NCURSES_KEY_EIC | exit insert char mode | NCURSES_KEY_CLEAR | clear screen | NCURSES_KEY_EOS | clear to end of screen | NCURSES_KEY_EOL | clear to end of line | NCURSES_KEY_SF | scroll one line forward | NCURSES_KEY_SR | scroll one line backward | NCURSES_KEY_NPAGE | next page | NCURSES_KEY_PPAGE | previous page | NCURSES_KEY_STAB | set tab | NCURSES_KEY_CTAB | clear tab | NCURSES_KEY_CATAB | clear all tabs | NCURSES_KEY_SRESET | soft (partial) reset | NCURSES_KEY_RESET | reset or hard reset | NCURSES_KEY_PRINT | print | NCURSES_KEY_LL | lower left | NCURSES_KEY_A1 | upper left of keypad | NCURSES_KEY_A3 | upper right of keypad | NCURSES_KEY_B2 | center of keypad | NCURSES_KEY_C1 | lower left of keypad | NCURSES_KEY_C3 | lower right of keypad | NCURSES_KEY_BTAB | back tab | NCURSES_KEY_BEG | beginning | NCURSES_KEY_CANCEL | cancel | NCURSES_KEY_CLOSE | close | NCURSES_KEY_COMMAND | cmd (command) | NCURSES_KEY_COPY | copy | NCURSES_KEY_CREATE | create | NCURSES_KEY_END | end | NCURSES_KEY_EXIT | exit | NCURSES_KEY_FIND | find | NCURSES_KEY_HELP | help | NCURSES_KEY_MARK | mark | NCURSES_KEY_MESSAGE | message | NCURSES_KEY_MOVE | move | NCURSES_KEY_NEXT | next | NCURSES_KEY_OPEN | open | NCURSES_KEY_OPTIONS | options | NCURSES_KEY_PREVIOUS | previous | NCURSES_KEY_REDO | redo | NCURSES_KEY_REFERENCE | ref (reference) | NCURSES_KEY_REFRESH | refresh | NCURSES_KEY_REPLACE | replace | NCURSES_KEY_RESTART | restart | NCURSES_KEY_RESUME | resume | NCURSES_KEY_SAVE | save | NCURSES_KEY_SBEG | shiftet beg (beginning) | NCURSES_KEY_SCANCEL | shifted cancel | NCURSES_KEY_SCOMMAND | shifted command | NCURSES_KEY_SCOPY | shifted copy | NCURSES_KEY_SCREATE | shifted create | NCURSES_KEY_SDC | shifted delete char | NCURSES_KEY_SDL | shifted delete line | NCURSES_KEY_SELECT | select | NCURSES_KEY_SEND | shifted end | NCURSES_KEY_SEOL | shifted end of line | NCURSES_KEY_SEXIT | shifted exit | NCURSES_KEY_SFIND | shifted find | NCURSES_KEY_SHELP | shifted help | NCURSES_KEY_SHOME | shifted home | NCURSES_KEY_SIC | shifted input | NCURSES_KEY_SLEFT | shifted left arrow | NCURSES_KEY_SMESSAGE | shifted message | NCURSES_KEY_SMOVE | shifted move | NCURSES_KEY_SNEXT | shifted next | NCURSES_KEY_SOPTIONS | shifted options | NCURSES_KEY_SPREVIOUS | shifted previous | NCURSES_KEY_SPRINT | shifted print | NCURSES_KEY_SREDO | shifted redo | NCURSES_KEY_SREPLACE | shifted replace | NCURSES_KEY_SRIGHT | shifted right arrow | NCURSES_KEY_SRSUME | shifted resume | NCURSES_KEY_SSAVE | shifted save | NCURSES_KEY_SSUSPEND | shifted suspend | NCURSES_KEY_UNDO | undo | NCURSES_KEY_MOUSE | mouse event has occured | NCURSES_KEY_MAX | maximum key value |
MouseTabel 4. mouse constants Constant | meaning |
---|
NCURSES_BUTTON1_RELEASED - NCURSES_BUTTON4_RELEASED | button (1-4) released | NCURSES_BUTTON1_PRESSED - NCURSES_BUTTON4_PRESSED | button (1-4) pressed | NCURSES_BUTTON1_CLICKED - NCURSES_BUTTON4_CLICKED | button (1-4) clicked | NCURSES_BUTTON1_DOUBLE_CLICKED -
NCURSES_BUTTON4_DOUBLE_CLICKED | button (1-4) double clicked | NCURSES_BUTTON1_TRIPLE_CLICKED -
NCURSES_BUTTON4_TRIPLE_CLICKED | button (1-4) triple clicked | NCURSES_BUTTON_CTRL | ctrl pressed during click | NCURSES_BUTTON_SHIFT | shift pressed during click | NCURSES_BUTTON_ALT | alt pressed during click | NCURSES_ALL_MOUSE_EVENTS | report all mouse events | NCURSES_REPORT_MOUSE_POSITION | report mouse position |
User Contributed Notes Ncurses terminal screen control functions |
add a note |
zak at php dot net
30-May-2002 11:34 |
|
There is a simple ncurses application in the PHP source tree. See
|
|
john at weider dot cc
18-Oct-2002 05:28 |
|
In addition to the above constants the following are also defined:
A_NORMAL A_STANDOUT A_UNDERLINE A_REVERSE
A_BLINK A_DIM A_BOLD A_PROTECT A_INVIS
A_ALTCHARSET A_CHARTEXT
|
|
nweeks at utas dot edu dot au
07-Nov-2002 11:43 |
|
With your CGI version of PHP compiled with ncurses support, console apps
are amazingly easy!
For example: whack the following into a
file, chmod +x it, and run it.
#!/usr/local/bin/php
-q <?php ncurses_init(); ncurses_border(25,25,18,18,24,24,23,23);
// Do a lovely border ncurses_move(1,1); // Start top left(inside
border) ncurses_addstr("Welcome to
NCurses"); ncurses_addstr(" with
PHP!"); ncurses_refresh(); // Send buffer to
screen ncurses_end(); // Clean up, and quit ?>
You'll
notice the second addstr simply tacks onto the first.
|
|
joeldegan AT yahoo.com
14-Dec-2002 05:56 |
|
actually *that* example does not work... here is one that I took and
trimmed down from the ncurses examples. I will do some more and post
them
here..
<? ncurses_init(); ############################################## ncurses_noecho();
$large = ncurses_newwin(20, 60, 2, 10); $small =
ncurses_newwin(10, 30, 7, 25); ncurses_refresh();
ncurses_wrefresh($large); ncurses_wrefresh($small);
ncurses_mvwaddstr($small, 5, 5, " Test String ");
ncurses_wrefresh($small);
ncurses_getch();
############################################## ncurses_end();
// Clean up, and quit ?>
This is from PHP 4.3.0RC0 compiled
with the following flags.. ./configure --prefix=/wwwroot/php
--with-config-file-path=/wwwroot/php --with-mysql --enable-pcntl
--with-tsrm-pthreads --enable-sysvsem --enable-sysvshm --with-curl
--enable-bcmath --enable-sigchild --enable-sockets --with-ncurses
|
|
joeldegan AT yahoo.com
14-Dec-2002 09:37 |
|
This is from the examples that come with the latest
release.
From: php-4.3.0RC3/ext/ncurses/example1.php
I
found this
useful...
<?php $n=0; ncurses_init(); if(ncurses_has_colors()){ ncurses_start_color();
ncurses_init_pair(1,NCURSES_COLOR_RED,NCURSES_COLOR_BLACK);
ncurses_init_pair(2,NCURSES_COLOR_GREEN,NCURSES_COLOR_BLACK);
ncurses_init_pair(3,NCURSES_COLOR_YELLOW,NCURSES_COLOR_BLACK);
ncurses_init_pair(4,NCURSES_COLOR_BLUE,NCURSES_COLOR_BLACK);
ncurses_init_pair(5,NCURSES_COLOR_MAGENTA,NCURSES_COLOR_BLACK);
ncurses_init_pair(6,NCURSES_COLOR_CYAN,NCURSES_COLOR_BLACK);
ncurses_init_pair(7,NCURSES_COLOR_WHITE,NCURSES_COLOR_BLACK); } while(1){ for
($x=0; $x<80; $x++) { for ($y=0; $y<24; $y++) { $n++;
ncurses_move($y,$x); ncurses_addch($n+64);
ncurses_color_set($n%8); ncurses_refresh();
if($n>26)$n=0; } } ncurses_getch(); } ?>
|
|
joeldegan AT yahoo.com
14-Dec-2002 10:10 |
|
I noticed a lack of a getxy() function so I wrote one. You may need to
change the path for your resize cmd.
<? function
getxy(){ $rez = `/usr/X11R6/bin/resize`; $rez =
explode("\n",$rez); while(list($key,$val)=each($rez)){ $a=explode("=",$val); if(trim($a[0])=="COLUMNS"){
$COLUMNS = $a[1]; } if(trim($a[0])=="LINES"){ $LINES =
$a[1]; } }// $retval[0]=$COLUMNS; $retval[1]=$LINES;
return $retval; }
print_r(getxy()); ?>
|
|
joeldegan AT yahoo.com
15-Dec-2002 07:26 |
|
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.
|
|
25-Mar-2003 02:18 |
|
In the example above, if you run resize from a C shell it will output the
sizes in C shell syntax, run resize with -u to force Bourne syntax: The
$win parameter is just for future compatibility.
function
ncurses_getmaxyx($win, &$y, &$x) {
exec("/usr/X11R6/bin/resize -u", $output); $cols =
explode("=", $output[0]); $rows =
explode("=", $output[1]); $x = intval($cols[1]);
$y = intval($rows[1]); }
|
|
Habib Valanejad
28-Mar-2003 01:13 |
|
For those of you who want to check if <ENTER> key is passed, you
have to check the key agains both NL and CR keys:
function
get_str() { for ($str = "";;){ $key =
ncurses_getch(); switch ($key){ case 10: //
newline case 13: // Carrige Return
return($str); default: $str .= chr($key);
ncurses_refresh(); } // switch } // for } //
get_str()
Hope that would help.
|
|
add a note |
| |