示例#1
1
function getch_nonblock($timeout)
{
    $read = array(STDIN);
    $null = null;
    if (stream_select($read, $null, $null, floor($timeout / 1000000), $timeout % 1000000) != 1) {
        return null;
    }
    return ncurses_getch();
}
示例#2
0
文件: Ncurses.php 项目: swos-/ncurses
 public function run()
 {
     while (1) {
         $char = ncurses_getch();
         $this->parse($char);
     }
 }
示例#3
0
文件: basic.php 项目: nicholasc/blink
 public function execute(Application $app)
 {
     // Retrieve a character
     $chr = ncurses_getch();
     // Exit on escape
     switch ($chr) {
         case NCURSES_KEY_LEFT:
             $x = $this->window->getX();
             $y = $this->window->getY();
             $this->window->move(--$x, $y);
             break;
         case NCURSES_KEY_RIGHT:
             $x = $this->window->getX();
             $y = $this->window->getY();
             $this->window->move(++$x, $y);
             break;
         case NCURSES_KEY_UP:
             $x = $this->window->getX();
             $y = $this->window->getY();
             $this->window->move($x, --$y);
             break;
         case NCURSES_KEY_DOWN:
             $x = $this->window->getX();
             $y = $this->window->getY();
             $this->window->move($x, ++$y);
             break;
         case 27:
             $app->quit();
             break;
     }
 }
示例#4
0
function ncurses_show_screen($showHelp)
{
    // basic settings
    ncurses_noecho();
    ncurses_curs_set(0);
    // set app title
    $title = "Red Ventures Selenium Runner";
    // commands to be listed in help
    $commands = array('q' => 'quit', 'r' => 'run selected tests', 'space' => 'toggle test selection', 'enter' => 'run highlighted tests', 'up' => 'move up', 'down' => 'move down', 'pgUp' => 'scroll description up', 'pgDown' => 'scroll description down', '?/h' => 'show this help panel');
    // create a fullscreen window
    $fullscreen = ncurses_newwin(0, 0, 0, 0);
    ncurses_getmaxyx($fullscreen, $max_y, $max_x);
    // enter the main event loop
    $do_loop = 1;
    while ($do_loop) {
        // calculate width of help window columns
        $c = $t = 0;
        foreach ($commands as $cmd => $txt) {
            $c = strlen($cmd) > $c ? strlen($cmd) : $c;
            $t = strlen($txt) > $t ? strlen($txt) : $t;
        }
        $h = count($commands);
        // calculate the help windows height
        if ($showHelp) {
            if (!empty($helpWin)) {
                ncurses_delwin($helpWin);
            }
            $helpWin = ncurses_newwin($h + 4, $c + $t + 5, ($max_y - $h - 4) / 2, ($max_x - $c - $t - 5) / 2);
            ncurses_wborder($helpWin, 0, 0, 0, 0, 0, 0, 0, 0);
            $i = 0;
            foreach ($commands as $cmd => $txt) {
                ncurses_mvwaddstr($helpWin, 2 + $i, 2, $cmd);
                ncurses_mvwaddstr($helpWin, 2 + $i, 2 + $c + 1, $txt);
            }
            if (!empty($helpWin)) {
                ncurses_wrefresh($helpWin);
            } else {
                ncurses_refresh();
            }
        }
        if (empty($helpWin)) {
            $key = ncurses_getch();
        } else {
            $key = ncurses_wgetch($helpWin);
        }
        switch ($key) {
            case 27:
                ncurses_flushinp();
                $do_loop = 0;
                break;
            default:
                $showHelp = $showHelp === true ? false : true;
                ncurses_show_screen($showHelp);
        }
    }
}
示例#5
0
 public function output()
 {
     // Gain access to translations
     $lang = $this->linfo->getLang();
     // And info
     $this->linfo->scan();
     $info = $this->linfo->getInfo();
     // Say we're called more than once. Kill previous remnants
     if (count($this->_windows) > 0) {
         $this->_kill_windows();
     }
     // Get dimensions and give lovely header text
     $fullscreen = ncurses_newwin(0, 0, 0, 0);
     ncurses_wrefresh($fullscreen);
     ncurses_getmaxyx($fullscreen, $x, $y);
     ncurses_mvwaddstr($fullscreen, 0, 0, 'Generated by ' . $this->linfo->getAppName() . ' (' . $this->linfo->getVersion() . ') (ncurses) on ' . date('m/d/Y @ h:i:s A (T)'));
     ncurses_wrefresh($fullscreen);
     $this->_max_dims = array($x, $y);
     // Some important windows
     $core_wins = array(array('name' => $lang['core'], 'content' => array(array($lang['os'], $info['OS']), array_key_exists('Distro', $info) ? array($lang['distro'], $info['Distro']['name'] . ($info['Distro']['version'] ? ' ' . $info['Distro']['version'] : '')) : false, array($lang['kernel'], $info['Kernel']), array_key_exists('Model', $info) && !empty($info['Model']) ? array($lang['model'], $info['Model']) : false, array($lang['uptime'], str_ireplace(array(' ', 'days', 'minutes', 'hours', 'seconds'), array('', 'd', 'm', 'h', 's'), $info['UpTime']['text'])), array($lang['hostname'], $info['HostName']), array_key_exists('CPUArchitecture', $info) ? array($lang['cpu_arch'], $info['CPUArchitecture']) : false, array($lang['load'], implode(' ', (array) $info['Load'])))), array('name' => $lang['memory'], 'content' => array(array($lang['size'], Common::byteConvert($info['RAM']['total'])), array($lang['used'], Common::byteConvert($info['RAM']['total'] - $info['RAM']['free'])), array($lang['free'], Common::byteConvert($info['RAM']['free'])))));
     // Show them
     $h = 1;
     foreach ($core_wins as $win) {
         list($width, $height) = $this->_window_with_lines($win['name'], $win['content'], $h, 0);
         $h += $height + 1;
     }
     // Makeshift event loop
     while (true) {
         // Die on input
         $getch = ncurses_getch();
         if ($getch > 0 && $getch == 113) {
             $this->__destruct();
             echo "\nEnding at your request.\n";
             // exit(0);
         }
         // Stop temporariy
         ncurses_napms(1000);
         // Call ourselves
         $this->output();
     }
 }
示例#6
0
 static function loop()
 {
     self::$instance->desktop->draw();
     while (true) {
         switch (ncurses_getch()) {
             case NCURSES_KEY_MOUSE:
                 if (ncurses_getmouse($mevent)) {
                     $mask = $mevent['mmask'];
                     // Get click position and do hittesting
                     $evtx = $mevent['x'];
                     $evty = $mevent['y'];
                     // Figure out what event we are dealing with
                     if ($mask & NCURSES_BUTTON1_CLICKED) {
                         $evtb = 1;
                         $evtn = 'onClick';
                     } elseif ($mask & NCURSES_BUTTON1_DOUBLE_CLICKED) {
                         $evtb = 1;
                         $evtn = 'onDoubleClick';
                     } elseif ($mask & NCURSES_BUTTON1_PRESSED) {
                         $evtb = 1;
                         $evtn = 'onOnMouseDown';
                     } elseif ($mask & NCURSES_BUTTON1_RELEASED) {
                         $evtb = 1;
                         $evtn = 'onMouseUp';
                     }
                     // Resolve modifiers
                     $evtm = 0;
                     // Call event handler for $evtn with x, y, button and mod
                     self::$handlers[0]->call($evtx, $evty, $evtb, $evtm);
                 }
                 break;
             case " ":
                 return;
             default:
                 /* .... */
         }
         usleep(10000);
     }
 }
示例#7
0
 /**
  * Gets user input and acts based on Menu/Checklist navigation style
  * @param $win
  * @return array|bool|mixed|null
  */
 protected function getMenuInput(&$win)
 {
     $exit = null;
     $keyPressed = ncurses_getch();
     //print" {".$keyPressed."} ";
     switch ($keyPressed) {
         case NCURSES_KEY_DOWN:
             $this->menuCursor++;
             if ($this->menuCursor >= $this->menuTotal) {
                 $this->menuCursor = 0;
             }
             break;
         case NCURSES_KEY_UP:
             $this->menuCursor--;
             if ($this->menuCursor < 0) {
                 $this->menuCursor = $this->menuTotal - 1;
             }
             break;
         case NCURSES_KEY_RIGHT:
         case 9:
             // tab
             $this->focusCursor++;
             if ($this->focusCursor >= $this->focusTotal) {
                 $this->focusCursor = 0;
             }
             break;
         case NCURSES_KEY_LEFT:
         case 353:
             // shift-tab
             $this->focusCursor--;
             if ($this->focusCursor < 0) {
                 $this->focusCursor = $this->focusTotal - 1;
             }
             break;
         case 32:
             // space
             if ($this instanceof NcursesChecklist) {
                 // toggle item selection
                 $this->menuList[$this->menuCursor]['selected'] = !$this->menuList[$this->menuCursor]['selected'];
             }
             break;
         case 13:
             //enter
             $ii = $this->focusSubindex();
             // get selected inputbox
             if ($this instanceof NcursesChecklist) {
                 if ($this->buttonList[$ii]['value'] === true) {
                     return $this->getAllCheckboxVals();
                 } else {
                     return $this->buttonList[$ii]['value'];
                 }
             }
             if ($this instanceof NcursesMenu) {
                 if ($this->buttonList[$ii]['value'] === true) {
                     return $this->menuList[$this->menuCursor]['value'];
                 } else {
                     return $this->buttonList[$ii]['value'];
                 }
             }
             return $this->buttonList[$ii]['value'];
         default:
             // check if any button hotkeys were pressed - return 'null' if no match
             $hot = $this->checkHotButtons($keyPressed);
             // try trap for hot buttons 1st.
             if ($hot === true) {
                 // was hot button pressed?
                 if ($this instanceof NcursesChecklist) {
                     // checklist support -- (optional)
                     $exit = $this->getAllCheckboxVals();
                 } else {
                     // menu selection
                     // return the menu value we are focused on
                     $exit = $this->menuList[$this->menuCursor]['value'];
                 }
             } elseif ($hot === false) {
                 $exit = false;
             } else {
                 // $hot == null , so let see if there is a hot-checkbox match
                 $exit = $this->checkHotMenuItems($keyPressed);
             }
             break;
     }
     return $exit;
 }
示例#8
0
function gui()
{
    // we begin by initializing ncurses
    $ncurse = ncurses_init();
    // let ncurses know we wish to use the whole screen
    $fullscreen = ncurses_newwin(0, 0, 0, 0);
    // draw a border around the whole thing.
    ncurses_border(0, 0, 0, 0, 0, 0, 0, 0);
    ncurses_attron(NCURSES_A_REVERSE);
    ncurses_mvaddstr(0, 1, "AEMB2 SIMULATOR OUTPUT TRANSLATOR");
    ncurses_attroff(NCURSES_A_REVERSE);
    // now lets create a small window
    $small = ncurses_newwin(10, 30, 2, 2);
    // border our small window.
    ncurses_wborder($small, 0, 0, 0, 0, 0, 0, 0, 0);
    ncurses_refresh();
    // paint both windows
    // move into the small window and write a string
    ncurses_mvwaddstr($small, 5, 5, "   Test  String   ");
    // show our handiwork and refresh our small window
    ncurses_wrefresh($small);
    $pressed = ncurses_getch();
    // wait for a user keypress
    ncurses_end();
    // clean up our screen
}
示例#9
0
<?php

// we begin by initializing ncurses
$ncurse = ncurses_init();
// let ncurses know we wish to use the whole screen
$fullscreen = ncurses_newwin(0, 0, 0, 0);
// draw a border around the whole thing.
ncurses_border(0, 0, 0, 0, 0, 0, 0, 0);
// now lets create a small window
$small = ncurses_newwin(10, 30, 7, 25);
// border our small window.
ncurses_wborder($small, 0, 0, 0, 0, 0, 0, 0, 0);
ncurses_refresh();
// paint both windows
// move into the small window and write a string
ncurses_mvwaddstr($small, 5, 5, "   Test  String   ");
ncurses_attron(NCURSES_A_REVERSE);
ncurses_mvaddstr(0, 1, "My first ncurses application");
ncurses_attroff(NCURSES_A_REVERSE);
// show our handiwork and refresh our small window
ncurses_wrefresh($small);
$pressed = ncurses_getch();
// wait for a user keypress
ncurses_end();
// clean up our screen
示例#10
0
 /**
  * Reads a char from keyboard
  * @return int Ascii-code of char
  * @see Keys for keys
  */
 public function getCh()
 {
     return ncurses_getch();
 }
<?php

$password = '';
ncurses_init();
ncurses_addstr("Enter your password:\n");
/* Do not display the keystrokes as they are typed */
ncurses_noecho();
while (true) {
    // get a character from the keyboard
    $c = chr(ncurses_getch());
    if ("\r" == $c || "\n" == $c) {
        // if it's a newline, break out of the loop, we've got our password
        break;
    } elseif ("" == $c) {
        /* if it's a backspace, delete the previous char from $password */
        $password = substr_replace($password, '', -1, 1);
    } elseif ("" == $c) {
        // if it's Control-C, clear $password and break out of the loop
        $password = NULL;
        break;
    } else {
        // otherwise, add the character to the password
        $password .= $c;
    }
}
ncurses_end();
示例#12
0
 function _getMenuInput(&$win)
 {
     $exit = NULL;
     $keyPressed = ncurses_getch();
     //print" {".$keyPressed."} ";
     switch ($keyPressed) {
         case NCURSES_KEY_DOWN:
             $this->menu_cursor++;
             if ($this->menu_cursor >= $this->menu_total) {
                 $this->menu_cursor = 0;
             }
             break;
         case NCURSES_KEY_UP:
             $this->menu_cursor--;
             if ($this->menu_cursor < 0) {
                 $this->menu_cursor = $this->menu_total - 1;
             }
             break;
         case NCURSES_KEY_RIGHT:
         case 9:
             // tab
             $this->_focus_cursor++;
             if ($this->_focus_cursor >= $this->_focus_total) {
                 $this->_focus_cursor = 0;
             }
             break;
         case NCURSES_KEY_LEFT:
         case 353:
             // shift-tab
             $this->_focus_cursor--;
             if ($this->_focus_cursor < 0) {
                 $this->_focus_cursor = $this->_focus_total - 1;
             }
             break;
         case 32:
             // space
             if ($this->mode == "checklist") {
                 // toggle item selection
                 $this->menu_list[$this->menu_cursor]['selected'] = $this->menu_list[$this->menu_cursor]['selected'] == false ? true : false;
             }
             break;
         case 13:
             // enter
             $ii = $this->_focusSubindex();
             // get selected inputbox
             if ($this->button_list[$ii]['value'] == true) {
                 if ($this->mode == "checklist") {
                     $exit = $this->_getAllCheckboxVals();
                 } else {
                     // return the menu value we are focused on
                     $exit = $this->menu_list[$this->menu_cursor]['value'];
                 }
             } else {
                 $exit = false;
             }
             break;
         default:
             // check if any button hotkeys were pressed - return 'null' if no match
             $hot = $this->_checkHotButtons($keyPressed);
             // try trap for hot buttons 1st.
             if ($hot === true) {
                 if ($this->mode == "checklist") {
                     $exit = $this->_getAllCheckboxVals();
                 } else {
                     // return the menu value we are focused on
                     $exit = $this->menu_list[$this->menu_cursor]['value'];
                 }
             } elseif ($hot === false) {
                 $exit = false;
             } else {
                 $exit = $this->_checkHotMenuItems($keyPressed);
             }
             break;
     }
     return $exit;
 }
示例#13
0
文件: Screen.php 项目: ck99/kurses
 public function handleStdIn()
 {
     $k = ncurses_getch();
     $this->panels[0]->setTitle("KeyPressed: " . $k);
 }
示例#14
0
        while (list($key, $val) = each($rwhois_return)) {
            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++;
        if ($currently_selected >= count($tr_return)) {
            $currently_selected = count($tr_return) - 1;
        }
    }
}
//end main while
// the following are two helper functions for
示例#15
0
 public function handleKey()
 {
     ncurses_getyx(STDSCR, $cury, $curx);
     // Read one character
     $c = ncurses_getch();
     if ($c == NCURSES_KEY_RETURN) {
         $in = trim($this->getInput());
         // Split input to command and arguments
         $command = explode(' ', $in, 2);
         $command[0] = strtolower($command[0]);
         // Empty command - user just pressed enter
         if (strlen($command[0]) == 0) {
             return;
         }
         // Command has been given, so:
         // Add to history, clear the prompt, disable scrollback
         array_push($this->history, $in);
         $this->drawPrompt();
         $this->historyScrollback = -1;
         // Add to output so we can see what we are doing
         $this->addOutput('> ' . $in);
         // Command not found
         if (!array_key_exists($command[0], $this->commands)) {
             $this->addOutput('Unknown command: ' . $command[0]);
             return;
         }
         // Run the command
         $this->commands[$command[0]]($this, $command[1]);
     } else {
         if ($c == NCURSES_KEY_LEFT) {
             // Move the cursor left
             ncurses_move($cury, $curx - 1);
         } else {
             if ($c == NCURSES_KEY_RIGHT) {
                 // Move the cursor right
                 ncurses_move($cury, $curx + 1);
             } else {
                 if ($c == NCURSES_KEY_UP) {
                     // If the user is not browsing history, start with the last element + 1
                     if ($this->historyScrollback == -1) {
                         // There is no history - we can't open it
                         if (count($this->history) == 0) {
                             return;
                         }
                         $this->historyScrollback = count($this->history);
                     }
                     // Move to a previous element
                     $this->historyScrollback--;
                     // The user scrolled beyond the list - move to the first item
                     if ($this->historyScrollback < 0) {
                         $this->historyScrollback = 0;
                     }
                     $this->drawPrompt($this->history[$this->historyScrollback]);
                 } else {
                     if ($c == NCURSES_KEY_DOWN) {
                         // User is not browsing the history - we can't go lower
                         if ($this->historyScrollback == -1) {
                             return;
                         }
                         $this->historyScrollback++;
                         // Disable scrollback when the user went outside the list
                         if ($this->historyScrollback >= count($this->history)) {
                             $this->historyScrollback = -1;
                             $this->drawPrompt();
                             return;
                         }
                         $this->drawPrompt($this->history[$this->historyScrollback]);
                     } else {
                         if ($c == NCURSES_KEY_BACKSPACE) {
                             // Remove one character to the left of the cursor
                             ncurses_mvdelch($cury, $curx - 1);
                         } else {
                             if ($c == NCURSES_KEY_DC) {
                                 // Remove one character at the cursor
                                 ncurses_delch($c);
                             } else {
                                 if (ctype_print($c)) {
                                     // Just print out an ordinary character
                                     ncurses_insch($c);
                                     ncurses_move($cury, $curx + 1);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->checkCursorBounds();
     ncurses_refresh();
 }
示例#16
0
 /**
  * Non-blocking user input
  *
  * ncurses_getch is a blocking command, which we don't want. So we first
  * check STDIN via stream_select to see if there are any messages there
  * that would be non-blocking. If we find one, we call ncurses_getch --
  * which is blocking, but won't block because there's a keystroke queued.
  * If we don't find anything just return null
  *
  * @return int|null character key code (decode with `chr()`), or null
  */
 public function getInput()
 {
     $timeout = 1000000;
     $read = array(STDIN);
     $null = null;
     $stream = stream_select($read, $null, $null, floor($timeout / 1000000), $timeout % 1000000);
     if ($stream !== 1) {
         return null;
     }
     return ncurses_getch();
 }
示例#17
0
 private function handleStdIn()
 {
     $k = ncurses_getch();
     $this->keyboard->handle($k);
     $this->mouse->handle($k);
 }
示例#18
0
文件: cwt.php 项目: noccy80/cherryphp
 function handleinput()
 {
     static $lastchars = array();
     do {
         $ch = ncurses_getch();
         if ($ch == NCURSES_KEY_MOUSE) {
             if (ncurses_getmouse($mevent)) {
                 $mx = $mevent["x"];
                 // Save mouse position
                 $my = $mevent["y"];
                 $ctl =& $this->desktop->hitTest($mx, $my);
                 $mtd = null;
                 if ($ctl) {
                     if ($mevent["mmask"] & NCURSES_BUTTON1_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(1, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON2_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(2, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON3_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(3, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON4_PRESSED) {
                         $mtd = 'onMouseDown';
                         $arg = array(4, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON1_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(1, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON2_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(2, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON3_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(3, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON4_RELEASED) {
                         $mtd = 'onMouseUp';
                         $arg = array(4, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON1_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(1, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON2_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(2, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON3_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(3, $mx, $my);
                     } elseif ($mevent["mmask"] & NCURSES_BUTTON4_CLICKED) {
                         $mtd = 'onClick';
                         $arg = array(4, $mx, $my);
                     }
                     if ($mtd && is_callable(array(&$ctl, $mtd))) {
                         call_user_func_array(array(&$ctl, $mtd), $arg);
                     }
                     //Cwt::cwt()->debug('Event at %3dx%3d. Hittest: %5s. Mtd:%-25s', $mx, $my, !empty($ctl)?'Yes':'No',$mtd);
                 }
             }
         }
         /*
         ncurses_mvaddstr(5,5,"Char: ".sprintf('%02x',$ch)."             ");
         if ($ch>=0) {
             array_unshift($lastchars, sprintf('%02x',$ch));
             ncurses_mvaddstr(6,5,"Last: ".join(', ',$lastchars)."             ");
             $lastchars = array_slice($lastchars,0,6);
         }
         */
     } while ($ch != -1);
     ncurses_refresh();
     if ($ch == ' ') {
         $this->quit();
     }
 }
<?php

$line = '';
ncurses_init();
ncurses_addstr("Type a message, ending with !\n");
/* Display the keystrokes as they are typed */
ncurses_echo();
while (($c = ncurses_getch()) != ord("!")) {
    $line .= chr($c);
}
ncurses_end();
print "You typed: [{$line}]\n";
示例#20
0
for ($i = 0; $i < $n_lines; $i++) {
    $window_width = max($window_width, strlen($lines[$i]));
}
$window_width += 4;
$x_coords = array(10, 14, 18);
$y_coords = array(10, 12, 8);
for ($i = 0; $i < 3; $i++) {
    $windows[$i] = ncurses_newwin(4 + $n_lines, $window_width, $y_coords[$i], $x_coords[$i]);
    ncurses_wborder($windows[$i], 0, 0, 0, 0, 0, 0, 0, 0);
    ncurses_wattron($windows[$i], NCURSES_A_REVERSE);
    ncurses_mvwaddstr($windows[$i], 0, 2, ' window #' . $i . ' ');
    ncurses_wattroff($windows[$i], NCURSES_A_REVERSE);
    for ($j = 0; $j < $n_lines; $j++) {
        ncurses_mvwaddstr($windows[$i], 2 + $j, 2, $lines[$j]);
    }
    ncurses_wrefresh($windows[$i]);
    $panels[$i] = ncurses_new_panel($windows[$i]);
}
ncurses_update_panels();
ncurses_curs_set(0);
ncurses_noecho();
$i = 0;
$k = NULL;
while (XCURSES_KEY_ESC != $k) {
    $k = ncurses_getch();
    ncurses_top_panel($panels[$i % 3]);
    ncurses_update_panels();
    ncurses_doupdate();
    $i++;
}
ncurses_end();
示例#21
0
 /**
  *
  */
 function refresh()
 {
     ncurses_refresh();
     // paint both windows
     foreach ((array) $this->children as $child) {
         $child->draw($this->workspace);
     }
     ncurses_move(-1, 1);
     $kp = ncurses_getch();
     // wait for a user keypress
     if ($kp == NCURSES_KEY_MOUSE) {
         if (!ncurses_getmouse($mevent)) {
             if ($mevent["mmask"] & NCURSES_MOUSE_BUTTON1_PRESSED) {
                 $mouse_x = $mevent["x"];
                 // Save mouse position
                 $mouse_y = $mevent["y"];
             }
         }
     }
     if (count($this->children) > 0) {
         // Pass it on to topmost window
         @$this->children[count($this->children) - 1]->keypress($kp);
     }
     return $kp;
 }
 /**
  * Get a single character of input from the terminal.
  *
  * @return A single character of input.
  */
 public function getInput()
 {
     $this->redrawInput();
     return ncurses_getch();
 }
示例#23
0
function ncurses_show_text($title, $text, $question, $keys = TRUE)
{
    // prepare text
    $textH = count($text);
    $textW = 1;
    $textLEN = array();
    for ($i = 0; $i < $textH; $i++) {
        $textLEN[$i] = strlen($text[$i]);
        if ($textLEN[$i] > $textW) {
            $textW = $textLEN[$i];
        }
    }
    // create text pad (invisible window)
    $textWIN = ncurses_newpad($textH, $textW);
    // fill it with text
    for ($i = 0; $i < $textH; $i++) {
        ncurses_mvwaddstr($textWIN, $i, 0, $text[$i]);
    }
    // prepare question
    $questionH = count($question);
    $questionLastW = strlen($question[$questionH - 1]);
    // initialize...
    $posX = $posY = 0;
    $screenH = $screenW = 0;
    // loop around...
    while (1) {
        // get actual screen size
        $oldH = $screenH;
        $oldW = $screenW;
        ncurses_getmaxyx(STDSCR, $screenH, $screenW);
        // something changed?
        if ($screenH != $oldH || $screenW != $oldW) {
            if ($oldH > 0) {
                ncurses_delwin($upperWIN);
                ncurses_delwin($lowerWIN);
            }
            ncurses_erase();
            ncurses_refresh(STDSCR);
            $upperWIN = ncurses_newwin($screenH - (2 + $questionH), $screenW, 0, 0);
            $lowerWIN = ncurses_newwin(2 + $questionH, $screenW, $screenH - (2 + $questionH), 0);
            $upperH = $screenH - (4 + $questionH);
            $upperW = $screenW - 2;
            $copyH = $upperH > $textH ? $textH : $upperH;
            $copyW = $upperW > $textW ? $textW : $upperW;
            // border lower window
            ncurses_wborder($lowerWIN, 0, 0, 0, 0, 0, 0, 0, 0);
            // print text in lower window
            for ($i = 0; $i < $questionH; $i++) {
                ncurses_mvwaddstr($lowerWIN, $i + 1, 1, $question[$i]);
            }
        }
        // check and fix positions
        if ($posY < 0 || $upperH >= $textH) {
            $posY = 0;
        } else {
            if ($upperH + $posY > $textH) {
                $posY = $textH - $upperH;
            }
        }
        if ($posX < 0 || $upperW >= $textW) {
            $posX = 0;
        } else {
            if ($upperW + $posX > $textW) {
                $posX = $textW - $upperW;
            }
        }
        // border upper window
        ncurses_wborder($upperWIN, 0, 0, 0, 0, 0, 0, 0, 0);
        // draw title and info line
        ncurses_wattron($upperWIN, NCURSES_A_REVERSE);
        ncurses_mvwaddstr($upperWIN, 0, 2, ' ' . $title . ' ');
        if ($upperH < $textH) {
            ncurses_mvwaddstr($upperWIN, $upperH + 1, 2, ' line ' . ($posY + 1) . '-' . ($posY + $copyH) . '/' . $textH . ' ');
        }
        ncurses_wattroff($upperWIN, NCURSES_A_REVERSE);
        // draw < and > at left/right side when horizontal scrolling is nesseccary
        if ($upperW < $textW) {
            for ($i = 0; $i < $copyH; $i++) {
                if ($textLEN[$i + $posY] > $copyW + $posX) {
                    ncurses_mvwaddstr($upperWIN, $i + 1, $screenW - 1, '>');
                }
                if ($posX > 0 && $textLEN[$i + $posY] > 0) {
                    ncurses_mvwaddstr($upperWIN, $i + 1, 0, '<');
                }
            }
        }
        // draw upper window
        ncurses_wrefresh($upperWIN);
        // copy a part of the text (pad) to the screen
        ncurses_prefresh($textWIN, $posY, $posX, 1, 1, $upperH, $upperW);
        // move cursor to end of last line of question
        ncurses_wmove($lowerWIN, $questionH, $questionLastW + 1);
        // draw lower window
        ncurses_wrefresh($lowerWIN);
        // get a character and do...
        $char = ncurses_getch();
        if (is_array($keys) && array_search($char, $keys) !== FALSE) {
            break;
        } else {
            if ($char == NCURSES_KEY_UP) {
                $posY--;
            } else {
                if ($char == NCURSES_KEY_DOWN) {
                    $posY++;
                } else {
                    if ($char == NCURSES_KEY_LEFT) {
                        $posX--;
                    } else {
                        if ($char == NCURSES_KEY_RIGHT) {
                            $posX++;
                        } else {
                            if ($char == NCURSES_KEY_PPAGE) {
                                $posY -= $copyH - 1;
                            } else {
                                if ($char == NCURSES_KEY_NPAGE) {
                                    $posY += $copyH - 1;
                                } else {
                                    if ($char == 362) {
                                        // HOME
                                        $posX = 0;
                                    } else {
                                        if ($char == 385) {
                                            // END
                                            $posX = 99999;
                                        } else {
                                            if ($char == 410 || $char == -1) {
                                                // these "characters" are pressed on resizing
                                            } else {
                                                if ($keys === TRUE) {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //end loop
    // free all resources
    ncurses_delwin($textWIN);
    ncurses_delwin($upperWIN);
    ncurses_delwin($lowerWIN);
    // return the pressed character
    return $char;
}