Пример #1
0
 public function hitTest($x, $y)
 {
     ncurses_mvaddstr(11, 5, sprintf("Hittesting %dx%d", $x, $y));
     $offs = 0;
     foreach ($this->curlayout as $key => $height) {
         if ($y < $height + $offs) {
             ncurses_mvaddstr(12, 5, sprintf("Matched key %s", $key));
             $obj = $this->{$key};
             if (!empty($obj) && $obj instanceof Widget) {
                 return $obj->hitTest($x, $y);
             }
         } else {
             $offs += $height;
         }
     }
 }
Пример #2
0
 public function draw()
 {
     ncurses_color_set(1);
     ncurses_mvaddstr($this->top, $this->left, str_repeat(" ", $this->width));
     $yp = 1;
     foreach ($this->menus as $id => $data) {
         $str = ' ' . str_replace('_', '', $data->label) . ' ';
         $ofs = strpos($data->label, '_');
         ncurses_mvaddstr($this->top, $this->left + $yp, $str);
         if ($ofs !== false) {
             ncurses_attron(NCURSES_A_UNDERLINE);
             $hlchar = substr($data->label, $ofs + 1, 1);
             ncurses_mvaddstr($this->top, $this->left + 1 + $yp + $ofs, $hlchar);
             ncurses_attroff(NCURSES_A_UNDERLINE);
         }
         $yp += strlen($data->label) + 2;
     }
     ncurses_color_set(0);
 }
Пример #3
0
 public function openCLI($title = NULL)
 {
     // 1. initiate ncurses
     ncurses_init();
     // Create a full-screen window
     $this->window = ncurses_newwin(0, 0, 0, 0);
     // Disable echoing the characters without our control
     ncurses_noecho();
     // let ncurses know we wish to use the whole screen
     $screen = ncurses_newwin(0, 0, 0, 0);
     // get screen size
     ncurses_getmaxyx($screen, $this->rows, $this->cols);
     // draw a border around the whole thing.
     ncurses_border(0, 0, 0, 0, 0, 0, 0, 0);
     // set the application title
     if (!is_null($title)) {
         ncurses_mvaddstr(0, 2, " " . $title . " ");
     }
     // paint window
     ncurses_refresh();
 }
Пример #4
0
 private function parse($char = '')
 {
     switch ($char) {
         case ESCAPE_KEY:
             ncurses_end();
             exit;
             break;
         case ENTER:
             $buffer = $this->getBuffer();
             ncurses_mvaddstr(0, 1, $buffer);
             ncurses_wclear($this->small);
             ncurses_wborder($this->small, 0, 0, 0, 0, 0, 0, 0, 0);
             ncurses_mvwaddstr($this->small, 5, 5, $buffer);
             ncurses_wrefresh($this->small);
             break;
         default:
             $this->pushBuffer(chr($char));
             ncurses_wclear($this->small);
             ncurses_wborder($this->small, 0, 0, 0, 0, 0, 0, 0, 0);
             ncurses_mvwaddstr($this->small, 5, 5, chr($char));
             ncurses_wrefresh($this->small);
             break;
     }
 }
Пример #5
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
}
Пример #6
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();
 }
Пример #7
0
<?php

// define some key constants.
define("ESCAPE_KEY", 27);
define("ENTER_KEY", 13);
// get our initial data
$tr_return = traceroute("www.zend.com");
$ncurses_session = ncurses_init();
$main = ncurses_newwin(0, 0, 0, 0);
// main window
ncurses_getmaxyx($main, $lines, $columns);
ncurses_border(0, 0, 0, 0, 0, 0, 0, 0);
while (1) {
    // border the main window
    ncurses_attron(NCURSES_A_REVERSE);
    ncurses_mvaddstr(0, 1, "Traceroute example");
    ncurses_attroff(NCURSES_A_REVERSE);
    // create a lower window which is dynamically sized...
    $lower_frame_window = ncurses_newwin(10, $columns - 3, $lines - 11, 1);
    ncurses_wborder($lower_frame_window, 0, 0, 0, 0, 0, 0, 0, 0);
    // border it
    $lower_main_window = ncurses_newwin(8, $columns - 5, $lines - 10, 2);
    $main_list_window = ncurses_newwin($lines - 12, $columns - 3, 1, 1);
    ncurses_wborder($main_list_window, 0, 0, 0, 0, 0, 0, 0, 0);
    // border it
    if ($currently_selected == "") {
        $currently_selected = 0;
    }
    for ($a = 0; $a < count($tr_return); $a++) {
        $out = $tr_return[$a];
        if ($currently_selected == intval($a)) {
Пример #8
0
 protected function outputTitle($title)
 {
     ncurses_attron(NCURSES_A_REVERSE);
     ncurses_mvaddstr(0, 1, $title);
     ncurses_attroff(NCURSES_A_REVERSE);
     ncurses_refresh();
     // рисуем окна
 }
Пример #9
0
 public function onClick($b, $x, $y)
 {
     $this->emit(Widget::ON_CLICK, $b, $x, $y);
     ncurses_mvaddstr(13, 5, sprintf("StatusBar onClick: %dx%d (button %d)    ", $x, $y, $b));
 }
Пример #10
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
Пример #11
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();
 }
Пример #12
0
    ncurses_mvwaddstr($bl, $tmp, 24, "MAGENTA");
    ncurses_wcolor_set($bl, 6);
    ncurses_mvwaddstr($bl, $tmp, 32, "CYAN");
    ncurses_wcolor_set($bl, 7);
    ncurses_mvwaddstr($bl, $tmp, 37, "WHITE");
    ncurses_wcolor_set($bl, 0);
    ncurses_wattroff($bl, NCURSES_A_BOLD);
    ncurses_wattroff($bl, NCURSES_A_REVERSE);
    */
    ncurses_wrefresh($tl);
    ncurses_wrefresh($tr);
    ncurses_wrefresh($bl);
    ncurses_wrefresh($br);
    // Mise à jour des infos :
    // 	Consommation electrique : Tous les secondes ( 1 boucle )
    //	Reste des Infos ( Rechargement complet ? ) Toutes les 5 min ( 300 boucles )
    // Boucle pour faire 300 boucles
    for ($i = 0; $i < 300; $i++) {
        // Mise à jour de heure
        $date = strftime(" %A %d %B %Y %H:%M:%S ");
        ncurses_mvaddstr(0, $columns - 2 - strlen($date), $date);
        // Mise à jour de la consommation
        $conso = file_get_contents("/tmp/papp");
        $conso = intval($conso);
        ncurses_mvwaddstr($tr, 2, 2, "Consommation Electrique : " . sprintf("%5s", $conso) . " W");
        ncurses_wrefresh($tr);
        ncurses_move(-1, 1);
        ncurses_refresh();
        sleep(1);
    }
}