Zend - The PHP Company




Text

Add Code


ncurses examples (plus undocumented)  

Type: application
Added by: joeldg
Entered: 15/12/2002
Last modified: 02/11/2001
Rating: - (fewer than 3 votes)
Views: 5057
I started playing around with ncurses in PHP with php 4.3.0.rc0 compiled with --with-ncurses and started noticing a huge lack of *any* documentation.. There are a lot of functions I write which could make good use of the functions as I write a lot of php shell scripts.


<?php
/*
php 4.3.0rc0 compiled with the following
./configure --with-mysql --enable-pcntl --with-tsrm-pthreads --enable-sysvsem --enable-sysvshm --with-curl --enable-bcmath --enable-cli --enable-sigchild --enable-sockets --with-ncurses
*/
ini_set("ncurses.value",42);
ini_set("ncurses.string","foobar");

$n=0;
$a ncurses_init();//$a,$b,$c,$d,$e,$f,$g,$h
$z ncurses_newwin 15151010);

if(
ncurses_has_colors()){
    
ncurses_start_color();
        
ncurses_init_pair(1,NCURSES_COLOR_RED,NCURSES_COLOR_BLACK);
        
ncurses_init_pair(2,NCURSES_COLOR_BLUE,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);
}
ncurses_border(0,00,00,00,0);
while(
1){
for (
$x=1$x<80$x++) {
for (
$y=1$y<24$y++) {
  
$n++;
  
ncurses_move($y,$x);
  
ncurses_addch($n+64);
  
ncurses_color_set($n%8);
  
ncurses_refresh();
  if(
$n>26)$n=0;
}
}
$z ncurses_newwin 15151010);
/*
    the following function ncurses_wborder() has nothing written about it on
    php.net. I was reading through the ncurses examples and man pages when I just
    decided to try the following.... then I started 'n'cursing... 
*/
ncurses_wborder($z,0,00,00,00,0); // undocumented function

ncurses_wrefresh($z);
ncurses_getch(); // wait for use to press key
}

// here is a function I wrote before realizing that php ncurses had this built-in
// as the following two functions
// ncurses_getmaxyx($z, $x, $y); // undocumented function gets maximum x and y
// ncurses_getyx($window_handle, $return_y, $return_x); // undocumented function, get current x/y
// 
function getmaxxy(){
    
$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;
}

?>


Usage Example


just run the source.


Rate This Script





Search



This Category All Categories