To determine screen width and height without any external (OS specific) commands, I use:
<?php
ncurses_init();
$fullscreen = ncurses_newwin ( 0, 0, 0, 0);
ncurses_getmaxyx($fullscreen,&$a,&$b);
ncurses_end();
echo "Width:$b\nHeight:$a\n";
?>
Ncurses Functions
Table of Contents
- ncurses_addch — اضافه کردن کاراکتر در موقعیت فعلی و پیش بردن cursor
- ncurses_addchnstr — اضافه کردن رشته دارای ویژگی با طول مشخص در موقعیت فعلی
- ncurses_addchstr — اضافه کردن رشته دارای ویژگی در موقعیت فعلی
- ncurses_addnstr — اضافه کردن رشته با طول مشخص در موقعیت فعلی
- ncurses_addstr — خروجی متن در موقعیت فعلی
- ncurses_assume_default_colors — تعریف رنگ پیشفرض برای رنگ 0
- ncurses_attroff — خاموش نمودن ویژگی داده شده
- ncurses_attron — روشن نمودن ویژگی داده شده
- ncurses_attrset — تنظیم ویژگی داده شده
- ncurses_baudrate — بازگرداندن baudrate پایانه
- ncurses_beep — اجازه پایانه برای زنگ زدن
- ncurses_bkgd — تنظیم خاصیت پسزمینه برای صفحه پایانه
- ncurses_bkgdset — کنترل پیشزمینه صفحه
- ncurses_border — رسم مرز صفحه با استفاده از کاراکترهای دارای ویژگی
- ncurses_bottom_panel — Moves a visible panel to the bottom of the stack
- ncurses_can_change_color — بررسی امکان تغییر رنگ پایانه
- ncurses_cbreak — Switch of input buffering
- ncurses_clear — Clear screen
- ncurses_clrtobot — Clear screen from current position to bottom
- ncurses_clrtoeol — Clear screen from current position to end of line
- ncurses_color_content — Retrieves RGB components of a color
- ncurses_color_set — Set active foreground and background colors
- ncurses_curs_set — تعیین حالت cursor
- ncurses_def_prog_mode — Saves terminals (program) mode
- ncurses_def_shell_mode — ذخیره حالت پایانه (shell)
- ncurses_define_key — تعریف keycode
- ncurses_del_panel — حذف پانل از پشته و حذف کلی آن (اما نه پنجره مرتبط)
- ncurses_delay_output — تاخیر خروجی در پایانه با استفاده از کاراکترهای padding
- ncurses_delch — Delete character at current position, move rest of line left
- ncurses_deleteln — Delete line at current position, move rest of screen up
- ncurses_delwin — حذف پنجره ncurses
- ncurses_doupdate — Write all prepared refreshes to terminal
- ncurses_echo — Activate keyboard input echo
- ncurses_echochar — انتقال کاراکتر تنها به خروجی و بروزرسانی
- ncurses_end — توقف استفاده از ncurses تمیز کردن صفحه
- ncurses_erase — Erase terminal screen
- ncurses_erasechar — Returns current erase character
- ncurses_filter — تعیین LINES برای iniscr() و newterm() به 1
- ncurses_flash — Flash terminal screen (visual bell)
- ncurses_flushinp — Flush keyboard input buffer
- ncurses_getch — خواندن کاراکتر از صفحه کلید
- ncurses_getmaxyx — Returns the size of a window
- ncurses_getmouse — Reads mouse event
- ncurses_getyx — بازگرداندن موقعیت فعلی cursor در پنجره
- ncurses_halfdelay — قرار دادن پایانه در حالت halfdelay
- ncurses_has_colors — Checks if terminal has color capabilities
- ncurses_has_ic — Check for insert- and delete-capabilities
- ncurses_has_il — Check for line insert- and delete-capabilities
- ncurses_has_key — بررسی حضور کلید تابع در پایانه keyboard
- ncurses_hide_panel — حذف پانل از پشته و نامرئی کردن آن
- ncurses_hline — رسم خط افقی درموقعیت فعلی با استفاده از کاراکتر دارای ویژگی و max. کاراکترهای به طول n
- ncurses_inch — Get character and attribute at current position
- ncurses_init_color — Define a terminal color
- ncurses_init_pair — Define a color pair
- ncurses_init — Initialize ncurses
- ncurses_insch — وارد نمودن کاراکتر و انتقال باقی کاراکترها به راست
- ncurses_insdelln — وارد نمودن خط پیش از خط فعلی (عدد منفی حذف میکند و صفحه بالا میرود)
- ncurses_insertln — وارد نمودن خط انتقال بقیه صفحه به پایین
- ncurses_insstr — وارد نمودن رشته در موقعیت فعلی انتقال باقی خط به راست
- ncurses_instr — Reads string from terminal screen
- ncurses_isendwin — Ncurses در حالت endwin است خروجی معمولی صفحه ایجاد میشود
- ncurses_keyok — فعالسازی/غیرفعالسازی keycode
- ncurses_keypad — روشن/ خاموش کردن keypad
- ncurses_killchar — Returns current line kill character
- ncurses_longname — Returns terminals description
- ncurses_meta — فعالسازی/غیرفعالسازی اطلاعات 8-bit meta key
- ncurses_mouse_trafo — تبدیل مختصات
- ncurses_mouseinterval — تعیین timeout برای کلیک چپ ماوس
- ncurses_mousemask — Sets mouse options
- ncurses_move_panel — انتقال پانل تا گوشه بالا و چپ در [startx, starty] باشد
- ncurses_move — انتقال موقعیت خروجی
- ncurses_mvaddch — انتقال موقعیت فعلی و اضافه نمودن کاراکتر
- ncurses_mvaddchnstr — انتقال موقعیت و اضافه نمودن رشته موقعیت دار به همراه طول مشخص
- ncurses_mvaddchstr — انتقال موقعیت و اضافه نمودن رشته دارای موقعیت
- ncurses_mvaddnstr — انتقال موقعیت و اضافه نمودن رشته با طول مشخص
- ncurses_mvaddstr — انتقال موقعیت و اضافه نمودن رشته
- ncurses_mvcur — انتقال بلافاصله cursor
- ncurses_mvdelch — انتقال موقعیت و حذف کاراکتر و شیفت بقیه به چپ
- ncurses_mvgetch — انتقال موقعیت و دریافت کاراکتر در موقعیت جدید
- ncurses_mvhline — تعیین موقعیت جدید و رسم خط عمودی با استفاده از کاراکترهای دارای ویژگی و max. کاراکترهای به طول n
- ncurses_mvinch — انتقال موقعیت و دریافت کاراکتر دارای ویژگی در موقعیت جدید
- ncurses_mvvline — تعیین موقعیت جدید و رسم خط عمودی با استفاده از کاراکتر دارای ویژگی و max. کاراکترها به طول n
- ncurses_mvwaddstr — اضافه نمودن رشته در موقعیت جدید
- ncurses_napms — Sleep
- ncurses_new_panel — ساخت پانل جدید و ارتباط آن با پنجره
- ncurses_newpad — ساخت pad (پنجره) جدید
- ncurses_newwin — Create a new window
- ncurses_nl — ترجمه newline and carriage return / line feed
- ncurses_nocbreak — Switch terminal to cooked mode
- ncurses_noecho — Switch off keyboard input echo
- ncurses_nonl — عدم ترجمه newline و carriage return / line feed
- ncurses_noqiflush — عدم خالی نمودن دراثر کاراکترهای ویژه
- ncurses_noraw — Switch terminal out of raw mode
- ncurses_pair_content — Retrieves foreground and background colors of a color pair
- ncurses_panel_above — بازگرداندن بالای پانل
- ncurses_panel_below — بازگرداندن پانل زیر پانل
- ncurses_panel_window — انتقال پنجره مرتبط با پانل
- ncurses_pnoutrefresh — کپی منطقه از pad به صفحه مجازی
- ncurses_prefresh — کپی منطقه از pad به صفحه مجازی
- ncurses_putp — بکار بردن اطلاعات padding به رشته و انتقال آن به خروجی
- ncurses_qiflush — تخلیه هنگام روبرویی با کاراکترهای ویژه
- ncurses_raw — Switch terminal into raw mode
- ncurses_refresh — بروز رسانی صفحه
- ncurses_replace_panel — جایگزینی ضفحه مرتبط با پانل
- ncurses_reset_prog_mode — بازنشانی حالت prog ذخیره شده توسط def_prog_mode
- ncurses_reset_shell_mode — بازنشانی حالت shell ذخیره شده توسط def_shell_mode
- ncurses_resetty — Restores saved terminal state
- ncurses_savetty — Saves terminal state
- ncurses_scr_dump — کپی محتوای صفحه به فایل
- ncurses_scr_init — آغاز صفحه از فایل کپی
- ncurses_scr_restore — بازیابی صفحه از فایل کپی
- ncurses_scr_set — وراثت صفحه از فایل کپی
- ncurses_scrl — حرکت دادن محتوای پنجره به بالا و پایین بدون تغییر دادن موقعیت فعلی
- ncurses_show_panel — قرار دادن پانل نامرئی بالای پشته و نمایش آن
- ncurses_slk_attr — Returns current soft label key attribute
- ncurses_slk_attroff — خاموش نمودن ویژگی داده شده برای برچسب کلید تابع نرم
- ncurses_slk_attron — روشن نمودن ویژگی داده شده برای برچسب کلید تابع نرم
- ncurses_slk_attrset — تعین ویژگیهای داده شده برای برچسب کلیدهای تابع نرم
- ncurses_slk_clear — Clears soft labels from screen
- ncurses_slk_color — تعیین رنگ برای برچسب کلیدهای نرم
- ncurses_slk_init — Initializes soft label key functions
- ncurses_slk_noutrefresh — کپی برچسب کلیدهای نرم به صفحه مجازی
- ncurses_slk_refresh — Copies soft label keys to screen
- ncurses_slk_restore — بازیابی برچسب کلیدهای نرم
- ncurses_slk_set — تعیین برجسب کلید تابع
- ncurses_slk_touch — Forces output when ncurses_slk_noutrefresh is performed
- ncurses_standend — توقف استفاده از 'standout'
- ncurses_standout — شروع استفاده از ویژگی 'standout'
- ncurses_start_color — Initializes color functionality
- ncurses_termattrs — بازگرداندن OR منطقی تمام پرچمهای ویژگی در پایانه
- ncurses_termname — بازگرداندن پایانه (short)-name
- ncurses_timeout — تعیین timeout برای ترتیب کلید ویژه
- ncurses_top_panel — انتقال پانل قابل مشاهده به بالای پشته
- ncurses_typeahead — تعیین filedescriptor متفاوت برای بررسی typeahead
- ncurses_ungetch — قرار دادن کاراکتر در سیستم ورودی
- ncurses_ungetmouse — Pushes mouse event to queue
- ncurses_update_panels — بروزرسانی صفحه مجازی برای نمایش پانلها پشته
- ncurses_use_default_colors — انتصال رنگ پیشفرض پایانه به رنگ id -1
- ncurses_use_env — کنترل استفاده اطلاعات محیط درباره اندازه صفحه
- ncurses_use_extended_names — کنترل نامهای گسترش یافته در توضیحات terminfo
- ncurses_vidattr — نمایش رشته در پایانه در حالت ویژگی ویدئو
- ncurses_vline — رسم خط عمودی با استفاده از کاراکتر دارای ویژگی و max. کاراکترها به طول n
- ncurses_waddch — اضافه نمودن کاراکتر در موقعیت فعلی پنجره و جلو بردن cursor
- ncurses_waddstr — خروجی متن در موقعیت فعلی پنجره
- ncurses_wattroff — خاموش نمودن ویژگیهای پنجره
- ncurses_wattron — روشن نمودن ویژگیهای پنجره
- ncurses_wattrset — تعیین ویژگیهای پنجره
- ncurses_wborder — Draws a border around the window using attributed characters
- ncurses_wclear — پاک کردن پنجره
- ncurses_wcolor_set — تعیین جفت رنگ پنجره
- ncurses_werase — حذف محتوای پنجره
- ncurses_wgetch — خواندن کاراکتر از صفحه کلید (پنجره)
- ncurses_whline — رسم خط افقی در موقعیت فعلی پنجره با استفاده از کاراکترهای دارای ویژگی و max. کاراکترهای به طول n
- ncurses_wmouse_trafo — تبدیل مختصات window/stdscr
- ncurses_wmove — انتقال موقعیت خروجی پنجره
- ncurses_wnoutrefresh — کپی پنجره به صفحه مجازی
- ncurses_wrefresh — بروزرسانی پنجره در پایانه
- ncurses_wstandend — پایان حالت standout در پنجره
- ncurses_wstandout — وارد شدن به حالت standout در پنجره
- ncurses_wvline — رسم خط عمودی در موقعیت فعلی پنچره با استفاده از کاراکترهای دارای ویژگی و max. کاراکترها به طول n
g_a at freemail dot deletethispart dot hu ¶
7 years ago
krzysztof dot gorzelak at gmail dot com ¶
7 years ago
Here is a small example, how to use STDIN to read keys combinations in console.
$stdin = fopen('php://stdin', 'r');
stream_set_timeout($stdin, 1);
while (1) {
$temp="";
while (1) {
if(stream_select($read = array($stdin), $write = NULL, $except = NULL, 0))
$temp .= ord(fgetc($stdin));
else break;
}
// F1 : $temp == 27914949126
// ALT+F1 : $temp = 2727914949126
// ....
usleep("50000");
}
kermodebear at kermodebear dot org ¶
9 years ago
An implementation of a scrolling selection box:
<?php
function ncurses_menu_select( $options, $values, $max_height = 7, $max_width = 20, $y = 2, $x = 2 ) {
// Size inside of borders
$height = $max_height - 2;
$width = $max_width - 2;
// Number of options
$num_options = count( $options );
// Trim all values to fit
foreach( $options as $key => $value ) {
$options[ $key ] = substr( $value, 0, $width );
}
// Create Window
$menu_window = ncurses_newwin( $max_height, $max_width, $y, $x );
ncurses_wborder( $menu_window, 0, 0, 0, 0, 0, 0, 0, 0 );
// Initialize Window
$current = 0; // Currently selected
$position = 1; // Position in list
$topitem = 0; // Top menu item
for ( $a = 0; $a < min( $height, $num_options ); $a++ ) {
if ( $a == $current ) {
ncurses_wattron( $menu_window, NCURSES_A_REVERSE );
ncurses_mvwaddstr( $menu_window, 1 + $a, 1, $options[ $a ] );
ncurses_wattroff( $menu_window, NCURSES_A_REVERSE );
} else {
ncurses_mvwaddstr( $menu_window, 1 + $a, 1, $options[ $a ] );
}
}
ncurses_mvwaddstr( $menu_window, 1, 0, '*' );
ncurses_wrefresh( $menu_window );
// Loop until a selection is made
while( ! in_array( $key = ncurses_getch( $menu_window ), array( 13, 10 ) ) ) {
if ( $key == NCURSES_KEY_UP && $current > 0 ) {
$move = -1;
} else if ( $key == NCURSES_KEY_DOWN && $current < $num_options - 1 ) {
$move = 1;
} else {
continue;
}
$current += $move;
$position += $move;
// If we scroll off the window, redraw items.
if ( $position < 1 || $position > $height ) {
if ( $position < 1 ) {
$position = 1;
} else {
$position = $height;
}
$topitem += $move;
for ( $a = 1; $a <= $height; $a++ ) {
ncurses_mvwaddstr( $menu_window, $a, 1, str_repeat( ' ', $width ) );
if ( $a == $position ) {
ncurses_wattron( $menu_window, NCURSES_A_REVERSE );
ncurses_mvwaddstr( $menu_window, $a, 1, $options[ $topitem + $a - 1 ] );
ncurses_wattroff( $menu_window, NCURSES_A_REVERSE );
} else {
ncurses_mvwaddstr( $menu_window, $a, 1, $options[ $topitem + $a - 1 ] );
}
}
} else { // Just update changed items
ncurses_wattron( $menu_window, NCURSES_A_REVERSE );
ncurses_mvwaddstr( $menu_window, $position, 1, $options[ $current ] );
ncurses_wattroff( $menu_window, NCURSES_A_REVERSE );
ncurses_mvwaddstr( $menu_window, $position - $move, 1, $options[ $current - $move ] );
}
// Update 'scroll bar dot'
ncurses_wborder( $menu_window, 0, 0, 0, 0, 0, 0, 0, 0 );
$dot_position = round ( ( $current / $num_options ) * ( $height - 1 ) );
ncurses_mvwaddstr( $menu_window, 1 + $dot_position, 0, '*' );
ncurses_wrefresh( $menu_window );
}
return $values[ $current ];
}
?>
kermodebear at kermodebear dot org ¶
9 years ago
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.
kermodebear at kermodebear dot org ¶
9 years ago
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!
<?php
/**
* Create a simple selection menu
* @param array Associative array; The value will be shown on the menu, while the key will be returned when the associated value is selected.
* @return mixed
*/
function ncurses_menu_select( $menu ) {
$keys = array_keys( $menu );
$values = array_values( $menu );
$height = $width = 0;
$height = count( $menu ) + 2;
foreach( $values as $value ) {
$width = max( $width, strlen( $value ) + 2 );
}
$menu_window = ncurses_newwin( $height, $width, 5, 5 );
ncurses_wborder( $menu_window, 0,0, 0,0, 0,0, 0,0 );
$current = 0;
for( $a = 0; $a < count( $values ); $a++ ) {
if ( $a == $current ) {
ncurses_wattron( $menu_window, NCURSES_A_REVERSE );
ncurses_mvwaddstr( $menu_window, 1 + $a, 1, $values[ $a ] );
ncurses_wattroff( $menu_window, NCURSES_A_REVERSE );
} else {
ncurses_mvwaddstr( $menu_window, 1 + $a, 1, $values[ $a ] );
}
}
ncurses_wrefresh( $menu_window );
while( ! in_array( $key = ncurses_getch( $menu_window ), array( 13, 10 ) ) ) {
if ( $key == NCURSES_KEY_UP AND $current > 0 ) {
$move = -1;
} else if ( $key == NCURSES_KEY_DOWN and $current < count( $values ) - 1 ) {
$move = 1;
} else {
$move = 0;
}
ncurses_mvwaddstr( $menu_window, 1 + $current, 1, $values[ $current ] );
$current += $move;
ncurses_wattron( $menu_window, NCURSES_A_REVERSE );
ncurses_mvwaddstr( $menu_window, 1 + $current, 1, $values[ $current ] );
ncurses_wattroff( $menu_window, NCURSES_A_REVERSE );
ncurses_wrefresh( $menu_window );
}
ncurses_delwin( $menu_window );
return $keys[ $current ];
}
?>
Example Use:
<?php
// Initialie ncurses
$ncurse = ncurses_init();
// A full screen window
$fullscreen = ncurses_newwin ( 0, 0, 0, 0);
// Add a pretty border
ncurses_border(0,0, 0,0, 0,0, 0,0);
// Draw everything so far
ncurses_refresh();
// Set up menu array
$menu_items = array(
'one' => 'Menu Item #1',
'two' => 'Menu Item #2',
'three' => 'Menu Item #3' );
// Display menu and return selection
$selection = ncurses_menu_select( $menu_items );
// Print selection
ncurses_mvaddstr( 1, 1, 'You selected ' . $menu_items[$selection] . ' with the value ' . $selection );
// Draw updates
ncurses_refresh( $fullscreen );
// End
ncurses_end();
?>
Habib Valanejad ¶
9 years ago
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 back
again!
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 again
function 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 */
}
Habib Valanejad ¶
9 years ago
Here is a function which would do the job for missing
ncurses_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);
}
}
rainman at darkwired dot org ¶
9 years ago
This is not meant as spam to get people to use my client.
I have been working on a PHP4 IRC client with ncurses interface and I think it is a useful example of how ncurses with php could be used.
It is GPL licensed so you can just go and take a loot at it.
It can be found at http://torc.sourceforge.net or http://www.darkwired.org/projects/torc/
I hope this will help out some of you because php ncurses can be quite difficult I experienced :]
For any questions about the code you can ofcourse just mail me.
Habib Valanejad ¶
9 years ago
I had a small problem building php+ncurses support.
ncurses include files were installed in:
ncurses_installed_dir/include/ncurses
This 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.
Habib Valanejad ¶
10 years ago
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.
Anonymous ¶
10 years ago
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]);
}
joeldegan AT yahoo.com ¶
10 years ago
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.
joeldegan AT yahoo.com ¶
10 years ago
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 ¶
10 years ago
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 ¶
10 years ago
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
nweeks at utas dot edu dot au ¶
10 years ago
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.
