/** * Writes a message to the output. * * @param string $message A message to write to the output * @param bool $newline Whether to add a newline or not */ protected function doWrite($message, $newline) { //$message = "lol"; $message = strip_tags($message); //ncurses_waddstr($this->window, $message, count($message)); if ($newline) { ncurses_getyx(STDSCR, $curx, $cury); ncurses_move($cury + 1, 0); ncurses_wrefresh($this->window); // ncurses_addchnstr("\n", 1); // // } }
/** * */ function draw($workspace) { $wh = $this->_wh; ncurses_wcolor_set($wh, NCC_FRAME); ncurses_wborder($wh, 0, 0, 0, 0, 0, 0, 0, 0); ncurses_wcolor_set($wh, NCC_TITLE); ncurses_wattron($wh, NCURSES_A_BOLD); $left = floor(($this->_w - 2) / 2 - (strlen($this->_title) + 2) / 2); ncurses_mvwaddstr($wh, 0, $left, ' ' . $this->_title . ' '); ncurses_wattroff($wh, NCURSES_A_BOLD); ncurses_wcolor_set($wh, NCC_TEXT); for ($n = 0; $n < $this->_h - 2; $n++) { ncurses_mvwaddstr($wh, $n + 1, 1, str_repeat(" ", $this->_w - 2)); } ncurses_wrefresh($wh); ncurses_wcolor_set($wh, 0); ncurses_move(-1, 1); ncurses_refresh(); }
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(); }
$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(); } ?>
/** * Moves the main cursor * @param integer $y Row * @param integer $x Column * @return Ncurses This object */ public function moveOutput($y, $x) { ncurses_move($y, $x); return $this; }
ncurses_mvwaddstr($main_list_window, 1 + $a, 1, $out); } } if ($y == ENTER_KEY) { $newout = explode(" ", $check_me); $rwhois_return = rwhois(trim($newout[3])); $a = 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++;
/** * */ function moveCursorXY($x, $y) { ncurses_move($y, $x); }
/** * get IPC message and display * * @param callback $callback * return true to end the loop, called on every loop */ function curlInfoIPC($callback = null) { $queue = $this->getMessageQueue(true)[0]; $nc = ncurses_init(); $window = ncurses_newwin(0, 0, 0, 0); $caption = ''; $list = array(); $lastClear = time(); while (true) { $time = time(); if ($time - $lastClear > 10) { ncurses_clear(); $lastClear = $time; } $error = ''; if (msg_receive($queue, 0, $msgtype, 1024 * 1024, $msg, true, MSG_IPC_NOWAIT, $errorCode)) { if (strlen($msg['caption']) > strlen($caption)) { $caption = $msg['caption']; } $pid = $msg['pid']; $isLast = $msg['isLast']; unset($msg['pid'], $msg['isLast'], $msg['caption']); $list[$pid] = $msg; if (true === $isLast) { unset($list[$pid]); ncurses_clear(); if (empty($list)) { break; } } } else { if ($errorCode != MSG_ENOMSG) { $error = 'IPC receive error, errorCode=' . $errorCode; } } $content = ''; $output = ''; foreach ($list as $k => $v) { $content .= $v['content'] . "\n"; $output .= $v['output'] . "\n"; } $str = trim($caption . "\n" . $content . "\n" . $output . "\n" . $error); ncurses_move(0, 0); ncurses_addstr($str); ncurses_refresh(); if (isset($callback)) { if (call_user_func($callback)) { break; } } usleep(100 * 1000); } ncurses_end(); msg_remove_queue($queue); }
/** * Draws the menu on the workspace. * * @param int $workspace The workspace window handle for curses */ function draw($workspace) { $wh = $this->_wh; ncurses_wcolor_set($wh, NCC_FRAME); ncurses_wborder($wh, 0, 0, 0, 0, 0, 0, 0, 0); ncurses_wcolor_set($wh, NCC_TITLE); ncurses_wattron($wh, NCURSES_A_BOLD); $left = floor(($this->_w - 2) / 2 - (strlen($this->_title) + 2) / 2); ncurses_mvwaddstr($wh, 0, $left, ' ' . $this->_title . ' '); ncurses_wattroff($wh, NCURSES_A_BOLD); ncurses_wcolor_set($wh, NCC_TEXT); $i = $this->_scroll; $sm = count($this->_items) - ($this->_h - 2); if ($sm < 0) { $sm = 0; } for ($n = 0; $n < $this->_h - 2; $n++) { if ($n + $i < count($this->_items)) { $str = " " . $this->_itemsidx[$n + $i]; } else { $str = ""; } $str .= str_repeat(' ', $this->_w - 2 - strlen($str)); if ($n + $i == $this->_selected) { ncurses_wattron($wh, NCURSES_A_REVERSE); } $str = substr($str, 0, $this->_w - 2); ncurses_mvwaddstr($wh, $n + 1, 1, $str); ncurses_wattroff($wh, NCURSES_A_REVERSE); } ncurses_wcolor_set($wh, NCC_MORE); if ($i > 0) { ncurses_wmove($wh, 1, $this->_w - 1); ncurses_waddch($wh, NCURSES_ACS_UARROW | NCURSES_A_BOLD); } if ($sm - $i > 0) { ncurses_wmove($wh, $this->_h - 2, $this->_w - 1); ncurses_waddch($wh, NCURSES_ACS_DARROW | NCURSES_A_BOLD); } ncurses_wrefresh($wh); ncurses_wcolor_set($wh, 0); ncurses_move(-1, 1); ncurses_refresh(); }
/** * Move the cursor's position on the screen. * * @param int $x The cursors' position on the x axis. * @param int $y The cursor's position on the y axis. * * @return void */ public function move($x, $y) { ncurses_move($x, $y); ncurses_getyx(STDSCR, $this->y, $this->x); }