/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/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; } $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 ?>