コード例 #1
0
ファイル: Window.php プロジェクト: wapmorgan/ncursesobjects
 /**
  * Destructs a window and associated panel
  */
 public function __destruct()
 {
     if ($this->panel !== null) {
         $this->panel = null;
     }
     ncurses_delwin($this->windowResource);
 }
コード例 #2
0
ファイル: test.php プロジェクト: jean-pasqualini/ia
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);
        }
    }
}
コード例 #3
0
 /**
  * Check if the display size has changed, and destroy/recreate our
  * panels if it has.
  */
 private function checkSize()
 {
     $bottom = $left = 0;
     ncurses_getmaxyx(STDSCR, $bottom, $right);
     if ($bottom != $this->lastBottom || $right != $this->lastRight) {
         foreach ($panels as $p) {
             ncurses_delwin($p);
         }
         $panels = array();
         $this->init();
     }
 }
コード例 #4
0
 public function _kill_windows()
 {
     foreach ($this->_windows as $win) {
         is_resource($win) && ncurses_delwin($win);
     }
 }
コード例 #5
0
ファイル: nDialog.class.php プロジェクト: roelforg/UbFoInfo
 function _init_screen()
 {
     ncurses_curs_set(0);
     ncurses_noecho();
     $fullscreen = ncurses_newwin(0, 0, 0, 0);
     ncurses_getmaxyx($fullscreen, $this->_screen_max_height, $this->_screen_max_width);
     ncurses_delwin($fullscreen);
     ncurses_start_color();
     ncurses_init_pair(1, NCURSES_COLOR_WHITE, NCURSES_COLOR_RED);
     ncurses_init_pair(4, NCURSES_COLOR_BLACK, NCURSES_COLOR_RED);
     ncurses_init_pair(2, NCURSES_COLOR_BLACK, NCURSES_COLOR_WHITE);
     ncurses_init_pair(3, NCURSES_COLOR_WHITE, NCURSES_COLOR_WHITE);
     ncurses_init_pair(5, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE);
     ncurses_init_pair(6, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE);
     ncurses_init_pair(7, NCURSES_COLOR_YELLOW, NCURSES_COLOR_WHITE);
     ncurses_color_set(1);
     ncurses_erase();
     ncurses_mvhline(0, 0, 0, $this->_screen_max_width);
     ncurses_attron(NCURSES_A_BOLD);
     ncurses_mvaddstr(0, 1, $this->title_page_header);
     ncurses_attroff(NCURSES_A_BOLD);
     for ($y = 1; $y < $this->_screen_max_height; $y++) {
         ncurses_mvhline($y, 0, 32, $this->_screen_max_width);
     }
     ncurses_refresh();
 }
コード例 #6
0
ファイル: dialog.php プロジェクト: noccy80/lepton-ng
 function __destruct()
 {
     Console::debug("Deleting window with handle %xd", $this->_wh);
     ncurses_delwin($this->_wh);
 }
コード例 #7
0
 /**
  * Creates the footer window.
  * If the footer window already exists, it is deleted and recreated.
  */
 protected function createFooterWindow()
 {
     if (null !== $this->windowFooter) {
         ncurses_delwin($this->windowFooter);
     }
     $globalWidth = null;
     $globalHeight = null;
     ncurses_getmaxyx(STDSCR, $globalHeight, $globalWidth);
     $this->windowFooter = ncurses_newwin(1, 0, $globalHeight - 1, 0);
     ncurses_getmaxyx($this->windowFooter, $this->windowFooterHeight, $this->windowFooterWidth);
     ncurses_keypad($this->windowFooter, true);
 }
コード例 #8
0
ファイル: widget.php プロジェクト: noccy80/cherryphp
 public function __destroy()
 {
     if ($this->window) {
         ncurses_delwin($this->window);
     }
 }
コード例 #9
0
ファイル: dialog.php プロジェクト: jean-pasqualini/ia
function dialog($params)
{
    ###############################################################################################
    if (empty($params) || !is_array($params)) {
        trigger_error('params must be non-empty array');
        return NULL;
    }
    $message = isset($params['message']) ? $params['message'] : '';
    $buttons = !empty($params['buttons']) && is_array($params['buttons']) ? $params['buttons'] : array('OK');
    $n_buttons = count($buttons);
    for ($i = 0; $i < $n_buttons; $i++) {
        $buttons[$i] = ' ' . $buttons[$i] . ' ';
    }
    $parent_rows = isset($params['rows']) && $params['rows'] > 0 ? (int) $params['rows'] : 25;
    $parent_cols = isset($params['cols']) && $params['cols'] > 0 ? (int) $params['cols'] : 80;
    if (empty($message) || empty($buttons) || $parent_rows <= 0 || $parent_cols <= 0) {
        trigger_error('wrong params');
        return NULL;
    }
    $message_lines = split("\n", $message);
    $message_width = 0;
    $n_message_lines = count($message_lines);
    for ($i = 0; $i < $n_message_lines; $i++) {
        $message_width = max(strlen($message_lines[$i]), $message_width);
    }
    $buttons_delim = '  ';
    $buttons_delim_len = strlen($buttons_delim);
    $buttons_len = strlen(implode($buttons_delim, $buttons));
    $width = 4 + max($buttons_len + 2 * $buttons_delim_len, $message_width);
    $height = 4 + $n_message_lines;
    $dlg_y = $parent_rows > $height ? $parent_rows - $height >> 1 : 1;
    $dlg_x = $parent_cols > $width ? $parent_cols - $width >> 1 : 1;
    $window = ncurses_newwin($height, $width, $dlg_y, $dlg_x);
    if (empty($window)) {
        trigger_error('unable to create window');
        return NULL;
    }
    ncurses_wborder($window, 0, 0, 0, 0, 0, 0, 0, 0);
    $i_x = 0;
    $i_y = 0;
    for ($i = 0; $i < $n_message_lines; $i++) {
        $i_y = 1 + $i;
        $i_x = 1 + ($width - 2 - strlen($message_lines[$i]) >> 1);
        ncurses_mvwaddstr($window, $i_y, $i_x, rtrim($message_lines[$i]));
    }
    $buttons_data = array();
    $buttons_shift_x = 1 + ($width - 1 - $buttons_len >> 1);
    $buttons_shift_y = 2 + $n_message_lines;
    $i_title = '';
    $i_x = $buttons_shift_x;
    for ($i = 0; $i < $n_buttons; $i++) {
        $i_title = $buttons[$i];
        $buttons_data[] = array('x' => $i_x, 's' => $i_title);
        if (0 == $i) {
            ncurses_wattron($window, NCURSES_A_REVERSE);
        }
        ncurses_mvwaddstr($window, $buttons_shift_y, $i_x, $i_title);
        if (0 == $i) {
            ncurses_wattroff($window, NCURSES_A_REVERSE);
        }
        $i_x += strlen($i_title) + $buttons_delim_len;
    }
    ncurses_wrefresh($window);
    ncurses_keypad($window, TRUE);
    ncurses_curs_set(0);
    ncurses_noecho();
    $result = -1;
    $do_loop = 1;
    $move = 0;
    $current = 0;
    while ($do_loop) {
        $key = ncurses_wgetch($window);
        $move = 0;
        switch ($key) {
            case NCURSES_KEY_LEFT:
                if ($current > 0) {
                    $move = -1;
                }
                break;
            case NCURSES_KEY_RIGHT:
                if ($current < $n_buttons - 1) {
                    $move = 1;
                }
                break;
            case XCURSES_KEY_LF:
            case XCURSES_KEY_CR:
                $result = $current;
                $do_loop = 0;
                break;
            case XCURSES_KEY_ESC:
                $do_loop = 0;
                break;
        }
        if (0 == $do_loop) {
            ncurses_flushinp();
        } elseif ($move) {
            ncurses_mvwaddstr($window, $buttons_shift_y, $buttons_data[$current]['x'], $buttons_data[$current]['s']);
            $current += $move;
            ncurses_wattron($window, NCURSES_A_REVERSE);
            ncurses_mvwaddstr($window, $buttons_shift_y, $buttons_data[$current]['x'], $buttons_data[$current]['s']);
            ncurses_wattroff($window, NCURSES_A_REVERSE);
            ncurses_wrefresh($window);
        }
    }
    ncurses_delwin($window);
    return $result;
}
コード例 #10
0
ファイル: ncurse.class.php プロジェクト: rburchell/ircc
 public function DeleteWindows()
 {
     ncurses_delwin($this->mainwin);
     ncurses_delwin($this->ircoutput);
     ncurses_delwin($this->userinputw);
 }
コード例 #11
0
ファイル: menu.php プロジェクト: jean-pasqualini/ia
function menu_select($params)
{
    ###################################################################################################
    if (!is_array($params) || empty($params)) {
        trigger_error('wrong params');
        return NULL;
    }
    $menu = isset($params['items']) ? $params['items'] : NULL;
    $rows = isset($params['rows']) ? (int) $params['rows'] : 0;
    $cols = isset($params['cols']) ? (int) $params['cols'] : 0;
    $selected = isset($params['selected']) ? (int) $params['selected'] : 0;
    $centered = empty($params['centered']) ? 0 : 1;
    $y_menu = isset($params['y']) ? (int) $params['y'] : 0;
    $x_menu = isset($params['x']) ? (int) $params['x'] : 0;
    if (!is_array($menu) || empty($menu) || $rows <= 0 || $cols <= 0 || $y_menu < 0 || $x_menu < 0) {
        trigger_error('wrong params');
        return NULL;
    }
    $keys = array_keys($menu);
    $values = array();
    $current = 0;
    $width = 0;
    $height = count($menu) + 2;
    foreach ($menu as $value) {
        $width = max($width, strlen($value));
    }
    $i = 0;
    foreach ($menu as $k => $v) {
        $values[$i] = ' ' . $v . str_repeat(' ', 1 + $width - strlen($v));
        if ($k == $selected) {
            $current = $i;
        }
        $i++;
    }
    $width += 4;
    if ($centered) {
        $y_menu = $rows - $height >> 1;
        $x_menu = $cols - $width >> 1;
    }
    $window = ncurses_newwin($height, $width, $y_menu, $x_menu);
    if (empty($window)) {
        trigger_error('unable to create window');
        return NULL;
    }
    ncurses_wborder($window, 0, 0, 0, 0, 0, 0, 0, 0);
    for ($a = 0; $a < count($values); $a++) {
        if ($a == $current) {
            ncurses_wattron($window, NCURSES_A_REVERSE);
        }
        ncurses_mvwaddstr($window, 1 + $a, 1, $values[$a]);
        if ($a == $current) {
            ncurses_wattroff($window, NCURSES_A_REVERSE);
        }
    }
    ncurses_wrefresh($window);
    ncurses_keypad($window, TRUE);
    ncurses_curs_set(0);
    do {
        $key = ncurses_wgetch($window);
        $move = 0;
        switch ($key) {
            case NCURSES_KEY_UP:
                if ($current > 0) {
                    $move = -1;
                }
                break;
            case NCURSES_KEY_DOWN:
                if ($current < count($values) - 1) {
                    $move = 1;
                }
                break;
            case XCURSES_KEY_LF:
            case XCURSES_KEY_CR:
                $result = $keys[$current];
                break;
            case XCURSES_KEY_ESC:
                ncurses_flushinp();
                $result = '';
                break;
        }
        if ($move) {
            ncurses_mvwaddstr($window, 1 + $current, 1, $values[$current]);
            $current += $move;
            ncurses_wattron($window, NCURSES_A_REVERSE);
            ncurses_mvwaddstr($window, 1 + $current, 1, $values[$current]);
            ncurses_wattroff($window, NCURSES_A_REVERSE);
            ncurses_wrefresh($window);
        }
    } while (!isset($result));
    ncurses_delwin($window);
    return $result;
}
コード例 #12
0
ファイル: input.php プロジェクト: jean-pasqualini/ia
function dlg_input($params = array())
{
    ###############################################################################################
    $title = isset($params['title']) ? $params['title'] : NULL;
    $max_length = isset($params['max_len']) ? (int) $params['max_len'] : 10;
    $dlg_rows = isset($params['dlg_cols']) ? (int) $params['dlg_cols'] : 3;
    $dlg_cols = isset($params['dlg_cols']) ? (int) $params['dlg_cols'] : 40;
    $parent_cols = isset($params['cols']) ? (int) $params['cols'] : NULL;
    $parent_rows = isset($params['rows']) ? (int) $params['rows'] : NULL;
    $dlg_x = (int) (($parent_cols - $dlg_cols) / 2);
    if ($dlg_x < 0) {
        $dlg_x = 0;
    }
    $dlg_y = (int) (($parent_rows - $dlg_rows) / 2);
    if ($dlg_y < 0) {
        $dlg_y = 0;
    }
    if ($max_length <= 0 || $dlg_rows <= 0 || $dlg_cols <= 0) {
        trigger_error('wrong params');
        return NULL;
    }
    $dlg_window = ncurses_newwin($dlg_rows, $dlg_cols, $dlg_y, $dlg_x);
    if (empty($dlg_window)) {
        return NULL;
    }
    ncurses_wborder($dlg_window, 0, 0, 0, 0, 0, 0, 0, 0);
    if ($title) {
        ncurses_wattron($dlg_window, NCURSES_A_REVERSE);
        ncurses_mvwaddstr($dlg_window, 0, 2, ' ' . $title . ' ');
        ncurses_wattroff($dlg_window, NCURSES_A_REVERSE);
    }
    ncurses_curs_set(1);
    ncurses_wmove($dlg_window, 2, 2);
    ncurses_wrefresh($dlg_window);
    $do_getch = 1;
    $input_val = '';
    $input_char = '';
    $input_len = 0;
    $cursor_x = 2;
    $cursor_y = 1;
    ncurses_wmove($dlg_window, $cursor_y, $cursor_x);
    ncurses_noecho();
    ncurses_keypad($dlg_window, TRUE);
    while ($do_getch) {
        $key_code = ncurses_wgetch($dlg_window);
        if ($key_code == XCURSES_KEY_CR || $key_code == XCURSES_KEY_LF) {
            $do_getch = 0;
        } elseif ($key_code == NCURSES_KEY_BACKSPACE) {
            if ($input_len > 0) {
                $input_len--;
                $input_val = substr($input_val, 0, $input_len);
                $cursor_x--;
                ncurses_mvwaddstr($dlg_window, $cursor_y, $cursor_x, ' ');
                ncurses_wmove($dlg_window, $cursor_y, $cursor_x);
            }
        } elseif ($key_code < XCURSES_KEY_PRINTABLE_MIN || $key_code > XCURSES_KEY_PRINTABLE_MAX) {
            continue;
        } elseif ($input_len < $max_length) {
            $input_val .= $input_char = chr($key_code);
            $input_len++;
            $cursor_x++;
            ncurses_waddstr($dlg_window, $input_char);
        }
    }
    ncurses_delwin($dlg_window);
    return $input_val;
}
コード例 #13
0
ファイル: Window.php プロジェクト: nicholasc/blink
 /**
  * Move the window to a specific position.
  *
  * @param int $x The position on the x axis.
  * @param int $y The position on the y axis.
  *
  * @return void
  */
 public function move($x, $y)
 {
     if ($x < 0 || $y < 0) {
         return;
     }
     // Store new window location
     $this->x = $x;
     $this->y = $y;
     // Erase any existing window
     ncurses_wborder($this->window, ord(' '), ord(' '), ord(' '), ord(' '), ord(' '), ord(' '), ord(' '), ord(' '));
     ncurses_wrefresh($this->window);
     // Delete and recreate a new position
     ncurses_delwin($this->window);
     $this->window = ncurses_newwin($this->width, $this->height, $y, $x);
     $this->setBorder($this->border);
 }
コード例 #14
0
ファイル: checkbox.php プロジェクト: jean-pasqualini/ia
function menu_check_list($params)
{
    ###############################################################################################
    if (!is_array($params) || empty($params)) {
        trigger_error('wrong_params');
        return NULL;
    }
    $menu = isset($params['items']) ? $params['items'] : NULL;
    $rows = isset($params['rows']) ? (int) $params['rows'] : 0;
    $cols = isset($params['cols']) ? (int) $params['cols'] : 0;
    $centered = empty($params['centered']) ? 0 : 1;
    $y_menu = isset($params['y']) ? (int) $params['y'] : 0;
    $x_menu = isset($params['x']) ? (int) $params['x'] : 0;
    if (!is_array($menu) || empty($menu) || $rows <= 0 || $cols <= 0 || $y_menu < 0 || $x_menu < 0) {
        trigger_error('wrong params');
        return NULL;
    }
    $keys = array_keys($menu);
    $n_menu = count($keys);
    $items = array();
    $checked = array();
    $current = 0;
    $width = 0;
    $height = $n_menu + 2;
    $i = 0;
    $k = NULL;
    $i_checked = NULL;
    for ($i = 0; $i < $n_menu; $i++) {
        $k = $keys[$i];
        $i_checked = isset($menu[$k][1]) && $menu[$k][1] == 1 ? 1 : 0;
        $items[$i] = ' [' . ($i_checked ? '*' : ' ') . '] ' . $menu[$k][0];
        $width = max($width, strlen($items[$i]));
        $checked[$i] = $i_checked;
    }
    for ($i = 0; $i < $n_menu; $i++) {
        $items[$i] = $items[$i] . str_repeat(' ', 2 + $width - strlen($items[$i]));
    }
    $width += 4;
    if ($centered) {
        $r = $rows - $height >> 1;
        $c = $cols - $width >> 1;
    }
    $window = ncurses_newwin($height, $width, $r, $c);
    if (empty($window)) {
        trigger_error('unable to create window');
        return NULL;
    }
    ncurses_wborder($window, 0, 0, 0, 0, 0, 0, 0, 0);
    $n_items = count($items);
    for ($i = 0; $i < $n_items; $i++) {
        if ($i == $current) {
            ncurses_wattron($window, NCURSES_A_REVERSE);
        }
        ncurses_mvwaddstr($window, 1 + $i, 1, $items[$i]);
        if ($i == $current) {
            ncurses_wattroff($window, NCURSES_A_REVERSE);
        }
    }
    ncurses_wrefresh($window);
    ncurses_keypad($window, TRUE);
    ncurses_noecho();
    ncurses_curs_set(0);
    $do_loop = 1;
    $save_result = 0;
    while ($do_loop) {
        $key = ncurses_wgetch($window);
        $move = 0;
        switch ($key) {
            case NCURSES_KEY_UP:
                if ($current > 0) {
                    $move = -1;
                }
                break;
            case NCURSES_KEY_DOWN:
                if ($current < $n_menu - 1) {
                    $move = 1;
                }
                break;
            case XCURSES_KEY_LF:
            case XCURSES_KEY_CR:
                $do_loop = 0;
                $save_result = 1;
                break;
            case XCURSES_KEY_SPACE:
                if ($checked[$current]) {
                    $checked[$current] = 0;
                    $items[$current] = ' [ ] ' . substr($items[$current], 5);
                } else {
                    $checked[$current] = 1;
                    $items[$current] = ' [*] ' . substr($items[$current], 5);
                }
                ncurses_wattron($window, NCURSES_A_REVERSE);
                ncurses_mvwaddstr($window, 1 + $current, 1, $items[$current]);
                ncurses_wattroff($window, NCURSES_A_REVERSE);
                ncurses_wrefresh($window);
                break;
            case XCURSES_KEY_ESC:
                ncurses_flushinp();
                $do_loop = 0;
                break;
        }
        if ($move) {
            ncurses_mvwaddstr($window, 1 + $current, 1, $items[$current]);
            $current += $move;
            ncurses_wattron($window, NCURSES_A_REVERSE);
            ncurses_mvwaddstr($window, 1 + $current, 1, $items[$current]);
            ncurses_wattroff($window, NCURSES_A_REVERSE);
            ncurses_wrefresh($window);
        }
    }
    ncurses_delwin($window);
    $result = NULL;
    if ($save_result) {
        for ($i = 0; $i < $n_menu; $i++) {
            $result[$keys[$i]] = $checked[$i];
        }
    }
    return $result;
}
コード例 #15
0
ファイル: Message.php プロジェクト: jean-pasqualini/ia
 public function __destruct()
 {
     ncurses_delwin($this->getWindow());
     $this->parent->refresh();
 }
コード例 #16
0
 /**
  * {@inheritdoc}
  */
 public function clearPad()
 {
     if (null !== $this->pad) {
         ncurses_delwin($this->pad);
         $this->pad = null;
     }
 }
コード例 #17
0
ファイル: example.php プロジェクト: jean-pasqualini/ia
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;
}
コード例 #18
0
ファイル: dialog.php プロジェクト: noccy80/cherryphp
 public function onDestroy()
 {
     \ncurses_delwin($this->window);
     parent::onDestroy();
 }
コード例 #19
0
ファイル: NcursesBase.php プロジェクト: vsychov/php_ncurses
 protected function initScreen()
 {
     ncurses_curs_set(0);
     ncurses_noecho();
     $fullscreen = ncurses_newwin(0, 0, 0, 0);
     ncurses_getmaxyx($fullscreen, $this->screenMaxHeight, $this->screenMaxWidth);
     ncurses_delwin($fullscreen);
     //COLOR SCHEMES
     ncurses_start_color();
     // text color, background color
     /*
      COLOR_BLACK   0
      COLOR_RED     1
      COLOR_GREEN   2
      COLOR_YELLOW  3
      COLOR_BLUE    4
      COLOR_MAGENTA 5
      COLOR_CYAN    6
      COLOR_WHITE   7
     */
     ncurses_init_pair(1, NCURSES_COLOR_WHITE, NCURSES_COLOR_RED);
     ncurses_init_pair(2, NCURSES_COLOR_BLACK, NCURSES_COLOR_WHITE);
     ncurses_init_pair(3, NCURSES_COLOR_WHITE, NCURSES_COLOR_WHITE);
     ncurses_init_pair(4, NCURSES_COLOR_BLACK, NCURSES_COLOR_RED);
     ncurses_init_pair(5, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE);
     ncurses_init_pair(6, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE);
     ncurses_init_pair(7, NCURSES_COLOR_BLUE, NCURSES_COLOR_WHITE);
     ncurses_color_set(5);
     ncurses_erase();
     ncurses_mvhline(0, 0, 0, $this->screenMaxWidth);
     ncurses_attron(NCURSES_A_BOLD);
     ncurses_mvaddstr(0, 1, $this->titlePageHeader);
     ncurses_attroff(NCURSES_A_BOLD);
     for ($y = 1; $y < $this->screenMaxHeight; $y++) {
         ncurses_mvhline($y, 0, 32, $this->screenMaxWidth);
     }
     ncurses_refresh();
 }