예제 #1
0
파일: TabsManager.php 프로젝트: ck99/kurses
 public function draw()
 {
     $start = 3;
     foreach ($this->tabs as $i => $tab) {
         $attrs = NCURSES_A_UNDERLINE;
         ncurses_wmove($this->window, 0, $start);
         //            ncurses_wvline($this->window, NCURSES_A_NORMAL, 1);
         if ($i === $this->active) {
             $attrs += NCURSES_A_REVERSE;
         }
         if ($tab->hasAlert()) {
             ncurses_wcolor_set($this->window, 0);
         }
         if ($attrs) {
             ncurses_wattron($this->window, $attrs);
         }
         $tabName = sprintf("[F%d] %s", $i + 1, $tab->name);
         ncurses_mvwaddstr($this->window, 0, $start + 1, $tabName);
         if ($attrs) {
             ncurses_wattroff($this->window, $attrs);
         }
         //            ncurses_wvline($this->window, NCURSES_A_NORMAL, 1);
         $start += strlen($tabName) + 3;
         if ($i === $this->active) {
             $tab->draw();
             ncurses_top_panel($tab->panel->panel);
         }
     }
 }
예제 #2
0
파일: Map.php 프로젝트: jean-pasqualini/ia
 public function draw($map)
 {
     foreach ($map as $i => $line) {
         foreach ($line as $j => $item) {
             //$lineStr .= $this->format($item);
             ncurses_wmove($this->getWindow(), $i + 1, $j + 1);
             ncurses_wcolor_set($this->getWindow(), $this->formatColor($item));
             ncurses_waddstr($this->getWindow(), $this->format($item));
         }
         //ncurses_color_set(62);
         // ncurses_mvwaddstr($this->getWindow(), $i+1, 1, $lineStr);
     }
 }
 /**
  * Draw an array of text to a given panel, with line wraps.
  * This makes sure we only draw text within the panel borders, not over
  * the top of them.
  *
  * @param $panel Panel we are drawing text on.
  * @param Array of text to draw.
  */
 public function drawTextToWindow($panel, $text)
 {
     $y = 1;
     $x = 2;
     ncurses_getmaxyx($panel, $height, $width);
     $arrayStart = 0 - $height + 2;
     $out = array();
     foreach (array_slice($text, $arrayStart) as $line) {
         $line = wordwrap($line, $width - 4, "\n", true);
         foreach (explode("\n", $line) as $l) {
             $out[] = $l;
         }
     }
     foreach (array_slice($out, $arrayStart) as $line) {
         ncurses_wmove($panel, $y, $x);
         ncurses_waddstr($panel, $line);
         $y++;
     }
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function refresh()
 {
     if (null === $this->pad) {
         $this->createPad();
     }
     ncurses_werase($this->pad);
     ncurses_wmove($this->pad, 0, 0);
     $this->renderStackTrace($this->stackTrace);
     ncurses_prefresh($this->pad, $this->decY, $this->decX, $this->padPositionY, $this->padPositionX, $this->padHeight + $this->padPositionY - 1, $this->padWidth - 1);
 }
예제 #5
0
 /**
  * Displays specified input text box
  * @param $index
  */
 protected function drawInputBox($index)
 {
     $label_offset = 0;
     $win =& $this->inputBoxList[$index]['win'];
     $label =& $this->inputBoxList[$index]['label'];
     $hotkey =& $this->inputBoxList[$index]['hot'];
     $cord_y =& $this->inputBoxList[$index]['y'];
     $cord_x =& $this->inputBoxList[$index]['x'];
     $max_length =& $this->inputBoxList[$index]['max_length'];
     ncurses_wcolor_set($win, 2);
     // draws the label
     if ($label != "") {
         ncurses_mvwaddstr($win, $cord_y, $cord_x, $label);
         $label_offset = strlen($label);
         // overide offset due to label length
     }
     // draws border for input field
     //$this->_drawThinBorders($win,$cord_y-1,($cord_x+$label_offset),3,$max_length+2,"out");
     //ncurses_wmove ( $win, $y+$height-1, $x+1 );
     // draws input box contents
     $this->drawInputBoxContents($index);
     // draws bottom border
     ncurses_wcolor_set($win, 2);
     ncurses_wmove($win, $cord_y + 1, $cord_x + $label_offset + 1);
     ncurses_whline($win, 175, 20);
     // bottom line
 }
예제 #6
0
 public function refreshInput($typing)
 {
     $this->paneInput->clear();
     $this->paneInput->addStr(1, 2, $typing);
     $this->paneInput->draw();
     ncurses_wmove($this->paneInput->window, 1, 2 + strlen($typing));
     return $this;
 }
예제 #7
0
 function _createMenuSubWindow(&$win, $parent_height, $parent_width, $para_offset_y)
 {
     // auto-detect window width based on menu contents
     if ($this->mode == "checklist") {
         $menu_width = 1 + 4 + $this->menu_label_width + 2 + $this->menu_desc_width + 1;
     } else {
         $menu_width = 1 + $this->menu_label_width + 2 + $this->menu_desc_width + 1;
     }
     // Draw borders
     $cord['y'] = 1 + $para_offset_y;
     $cord['x'] = round(($parent_width - $menu_width) / 2);
     //$cord = $this->_getCoordinates($parent_height,$menu_width,"center","middle");
     $y = $this->menu_total + 2;
     $x = $menu_width;
     $this->_drawThinBorders($win, $cord['y'], $cord['x'], $y, $x);
     // draw window inside borders
     $cord = $this->_getCoordinates($parent_height, $menu_width, "center", "middle");
     $swin = ncurses_newwin($y - 2, $x - 2, $cord['y'] + $para_offset_y + 2, $cord['x'] + 1);
     // fill window
     ncurses_wcolor_set($swin, 2);
     for ($row = 0; $row < $y - 2; $row++) {
         ncurses_wmove($swin, $row, 0);
         ncurses_whline($swin, 32, $x - 2);
     }
     return $swin;
 }
예제 #8
0
 /**
  * Moves a cursor
  * @param integer $x Cursor column
  * @param integer $y Cursor row
  * @return Window This object
  */
 public function moveCursor($x, $y)
 {
     $this->cursorX = $x;
     $this->cursorY = $y;
     ncurses_wmove($this->windowResource, $y, $x);
     return $this;
 }
예제 #9
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;
}
예제 #10
0
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;
}
예제 #11
0
 /**
  * Defines X and Y position
  * @param int $x
  * @param int $y
  */
 protected function setPositionXY($x, $y)
 {
     $this->posX = max(0, $x);
     $this->posY = max(0, $y);
     ncurses_wmove($this->pad, $this->posY - $this->decY, $this->posX);
     $this->maxY = max($this->maxY, $this->posY);
 }
예제 #12
0
파일: menu.php 프로젝트: noccy80/lepton-ng
 /**
  * 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();
 }
예제 #13
0
 public function draw()
 {
     ncurses_wmove($this->getWindow(), 1, 1);
     ncurses_waddstr($this->getWindow(), date("H:i:s"));
 }
예제 #14
0
 /**
  * Displays and creates a sub-window to contain the Menu Items
  * @param $win
  * @param $parentHeight
  * @param $parentWidth
  * @param $paraOffsetY
  * @param int $border
  * @return resource - ID of the sub-window
  */
 protected function createMenuSubWindow(&$win, $parentHeight, $parentWidth, $paraOffsetY, $border = 0)
 {
     // auto-detect window width based on menu contents
     if ($this instanceof NcursesChecklist) {
         $menuWidth = 1 + 4 + $this->menuLabelWidth + 2 + $this->menuDescWidth + 1;
     } else {
         $menuWidth = 1 + $this->menuLabelWidth + 2 + $this->menuDescWidth + 1;
     }
     // Draw borders
     $cord['y'] = 1 + $paraOffsetY;
     $cord['x'] = round(($parentWidth - $menuWidth) / 2);
     //$cord = $this->getCoordinates($parent_height,$menu_width,"center","middle");
     $y = $this->menuTotal + 2;
     $x = $menuWidth;
     if ($border != 0) {
         $this->drawThinBorders($win, $cord['y'], $cord['x'], $y, $x);
     }
     // draw window inside borders
     $cord = $this->getCoordinates($parentHeight, $menuWidth, self::COORD_X_CENTER, self::COORD_Y_MIDDLE);
     $swin = ncurses_newwin($y - 2, $x - 2, $cord['y'] + $paraOffsetY + 2, $cord['x'] + 1);
     // fill window
     ncurses_wcolor_set($swin, 2);
     for ($row = 0; $row < $y - 2; $row++) {
         ncurses_wmove($swin, $row, 0);
         ncurses_whline($swin, 32, $x - 2);
     }
     return $swin;
 }