/ Published in: PHP
Expand |
Embed | Plain Text
#!/usr/bin/env php <?php // define some key constants. // get our initial data $tr_return = traceroute("destiney.com"); $ncurses_session = ncurses_init(); $main = ncurses_newwin(0, 0, 0, 0); // main window ncurses_getmaxyx(&$main, $lines, $columns); ncurses_border(0,0, 0,0, 0,0, 0,0); while(1){ // border the main window ncurses_attron(NCURSES_A_REVERSE); ncurses_mvaddstr(0, 1, "Traceroute example"); ncurses_attroff(NCURSES_A_REVERSE); // create a lower window which is dynamically sized... $lower_frame_window = ncurses_newwin(10, $columns-3, $lines-11, 1); ncurses_wborder($lower_frame_window, 0,0, 0,0, 0,0, 0,0); // border it $lower_main_window = ncurses_newwin(8, $columns-5, $lines-10, 2); $main_list_window = ncurses_newwin($lines-12, $columns-3, 1, 1); ncurses_wborder($main_list_window, 0,0, 0,0, 0,0, 0,0); // border it if($currently_selected == ""){ $currently_selected = 0; } for($a=0;$a<count($tr_return);$a++){ $out = $tr_return[$a]; ncurses_wattron($main_list_window,NCURSES_A_REVERSE); ncurses_mvwaddstr ($main_list_window, 1+$a, 1, $out); ncurses_wattroff($main_list_window,NCURSES_A_REVERSE); }else{ ncurses_mvwaddstr ($main_list_window, 1+$a, 1, $out); } } if($y == ENTER_KEY){ $a=0; ncurses_mvwaddstr($lower_main_window, 1+$a, 1, $key . " - " . $val); $a++; } } elseif($y == ESCAPE_KEY){ ncurses_end(); exit; } ncurses_move(-1,1); // toss cursor out of sight. ncurses_wrefresh($lower_frame_window); ncurses_wrefresh($lower_main_window); // show it ncurses_wrefresh($main_list_window); // wait for user to press a key $y = ncurses_getch($lower_main_window); // check for the presence of up-arrow and down-arrow keys if($y == NCURSES_KEY_UP){ $currently_selected--; if($currently_selected < 0){ $currently_selected = 0; } } elseif($y == NCURSES_KEY_DOWN){ $currently_selected++; } } }//end main while // the following are two helper functions for // this ncurses example. function traceroute($address){ return $trreturn; }//end function // reverse whois function rwhois($query){ if(!$fp){ $ret[] = "$errstr ($errno)\n"; } else { "); $count=1; $ret[$data[1]] = $data[2]; $count++; }//wend }//fi return $ret; }//end function ?>
Comments
Subscribe to comments
You need to login to post a comment.

I installed ncurses in a Centos, the installation was succesful but when i open the script say me
!/usr/bin/env php
Fatal error: Call to undefined function ncursesinit() in /home/august7/publichtml/interactu/Comuny/trace.php on line 11
This script need some aditional library? In this script have this /usr/sbin/traceroute and in the server from SSH say /usr/sbin/traceroute google.com No such file or directory
Also this script call functions not defined, and have not some include() or require() function calling anyother script or library
采用php开发终端字符界面 http://www.phpcoding.cn/2009/06/01/dev-terminal-by-php/
这里有一个关于ncurses的具体实例。。。
采用php开发终端字符界面 http://www.phpcoding.cn/2009/06/01/dev-terminal-by-php/
这里有一个关于ncurses的具体实例。。。