示例#1
0
 /**
  *
  */
 function removeChild(CursesWidget $widget = null)
 {
     if ($widget == null) {
         if (count($this->children) > 0) {
             unset($this->children[count($this->children) - 1]);
             $this->children = array_values($this->children);
             $this->topmost = $this->children[count($this->children) - 1];
             ncurses_erase();
             return true;
         }
     }
     foreach ($this->children as $index => $child) {
         if ($child == $widget) {
             unset($this->children[$index]);
             $this->children = array_values($this->children);
             $this->topmost = $this->children[count($this->children) - 1];
             ncurses_erase();
             return true;
         }
     }
     return false;
 }
示例#2
0
 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();
 }
示例#3
0
 public function draw()
 {
     ncurses_bkgd("X");
     ncurses_erase();
     ncurses_refresh();
 }
示例#4
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;
}
示例#5
0
 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();
 }