コード例 #1
0
ファイル: Application.php プロジェクト: ck99/kurses
 public function __construct(EventLoop $loop = null)
 {
     if ($loop === null) {
         $loop = \Kurses\EventLoopFactory::select();
     }
     $this->loop = $loop;
     ncurses_init();
     ncurses_cbreak();
     ncurses_noecho();
     $this->panels = [];
     if (ncurses_has_colors()) {
         ncurses_start_color();
         ncurses_init_pair(1, NCURSES_COLOR_RED, NCURSES_COLOR_BLACK);
     }
     $this->cursor = new Cursor(null, null, false);
     $this->screen = new Screen();
     $onKeyboardEvent = function (KeyboardEvent $keyboardEvent) {
         $this->handleKeyboardEvent($keyboardEvent);
     };
     $onMouseEvent = function (MouseEvent $mouseEvent) {
         $this->handleMouseEvent($mouseEvent);
     };
     $refreshScreen = function () {
         $this->refreshScreen();
     };
     $this->keyboard = new Keyboard($onKeyboardEvent);
     $this->mouse = new Mouse($onMouseEvent);
     $this->loop->every($refreshScreen, 200);
     stream_set_blocking(STDIN, FALSE);
     $this->loop->attachStreamHandler(STDIN, function () {
         $this->handleStdIn();
     });
 }
コード例 #2
0
ファイル: Terminal.php プロジェクト: nicholasc/blink
 /**
  * Terminal class constructor
  *
  * return \Blink\Terminal $this
  */
 public function __construct()
 {
     // Populate the terminals attributes
     $this->hasColor = ncurses_has_colors();
     $this->hasIl = (bool) ncurses_has_il();
     $this->hasIc = (bool) ncurses_has_ic();
     $this->attributes = ncurses_termattrs();
     $this->name = ncurses_termname();
     $this->longName = ncurses_longname();
 }
コード例 #3
0
ファイル: Map.php プロジェクト: jean-pasqualini/ia
 public function __construct($rows, $cols, $y, $x)
 {
     parent::__construct($rows, $cols, $y, $x);
     $mappingColor = $this->getMappingColor();
     if (ncurses_has_colors()) {
         ncurses_start_color();
         ncurses_init_pair($mappingColor[MapBuilder::HERBE], NCURSES_COLOR_GREEN, NCURSES_COLOR_GREEN);
         ncurses_init_pair($mappingColor[MapBuilder::ARBRE], NCURSES_COLOR_BLACK, NCURSES_COLOR_GREEN);
         ncurses_init_pair($mappingColor[MapBuilder::EAU], NCURSES_COLOR_WHITE, NCURSES_COLOR_CYAN);
         ncurses_init_pair($mappingColor["P"], NCURSES_COLOR_WHITE, NCURSES_COLOR_BLACK);
         ncurses_init_pair($mappingColor[MapBuilder::FLEUR], NCURSES_COLOR_RED, NCURSES_COLOR_GREEN);
     }
 }
コード例 #4
0
ファイル: application.php プロジェクト: noccy80/lepton-ng
 /**
  *
  */
 function __construct()
 {
     ncurses_init();
     if (ncurses_has_colors()) {
         ncurses_start_color();
         ncurses_init_pair(NCC_FRAME, NCURSES_COLOR_BLACK, NCURSES_COLOR_BLUE);
         ncurses_init_pair(NCC_TEXT, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE);
         ncurses_init_pair(NCC_TITLE, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE);
         ncurses_init_pair(NCC_MORE, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE);
         ncurses_curs_set(0);
     }
     $this->workspace = ncurses_newwin(0, 0, 0, 0);
 }
コード例 #5
0
 public function init($title = 'AcePHProxy')
 {
     // начинаем с инициализации библиотеки
     $ncurse = ncurses_init();
     // используем весь экран
     $this->windows['main'] = ncurses_newwin(0, 0, 0, 0);
     // рисуем рамку вокруг окна
     ncurses_border(0, 0, 0, 0, 0, 0, 0, 0);
     ncurses_getmaxyx($this->windows['main'], $y, $x);
     // save current main window size
     $this->cur_x = $x;
     $this->cur_y = $y;
     // создаём второе окно для лога
     $rows = floor($y / 2);
     $cols = $x;
     $sy = $y - $rows;
     $sx = 0;
     $this->windows['log'] = ncurses_newwin($rows, $cols, $sy, $sx);
     // и окно для статистики (остальное пространство)
     $rows = $y - $rows - 1;
     $cols = $x;
     $sy = 1;
     $sx = 0;
     // еще -1 чтобы границы не перекрывались
     $this->windows['stat'] = ncurses_newwin($rows, $cols, $sy, $sx);
     if (ncurses_has_colors()) {
         ncurses_start_color();
         // colors http://php.net/manual/en/ncurses.colorconsts.php
         ncurses_init_pair(self::CLR_ERROR, NCURSES_COLOR_RED, NCURSES_COLOR_BLACK);
         ncurses_init_pair(self::CLR_GREEN, NCURSES_COLOR_GREEN, NCURSES_COLOR_BLACK);
         ncurses_init_pair(self::CLR_YELLOW, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLACK);
         ncurses_init_pair(self::CLR_SPEC1, NCURSES_COLOR_RED, NCURSES_COLOR_WHITE);
         ncurses_init_pair(5, NCURSES_COLOR_MAGENTA, NCURSES_COLOR_BLACK);
         ncurses_init_pair(6, NCURSES_COLOR_CYAN, NCURSES_COLOR_BLACK);
         ncurses_init_pair(self::CLR_DEFAULT, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLACK);
         $this->log('Init colors', self::CLR_GREEN);
     }
     // рамка для него
     ncurses_wborder($this->windows['log'], 0, 0, 0, 0, 0, 0, 0, 0);
     ncurses_wborder($this->windows['stat'], 0, 0, 0, 0, 0, 0, 0, 0);
     $this->outputTitle($title);
     ncurses_nl();
     ncurses_curs_set(0);
     // visibility
     ncurses_refresh();
     // рисуем окна
     // обновляем маленькое окно для вывода строки
     ncurses_wrefresh($this->windows['log']);
 }
コード例 #6
0
ファイル: context.php プロジェクト: noccy80/cherryphp
 public function __construct()
 {
     $this->nc = ncurses_init();
     if (!ncurses_has_colors()) {
         $this->onTerminate();
         echo "No color support.\n";
     }
     ncurses_start_color();
     $this->screen = ncurses_newwin(0, 0, 0, 0);
     $this->setCursorVisible(false);
     assert($this->screen);
     ncurses_init_pair(Widget\Widget::COLOR_DIALOGBG, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE);
     ncurses_init_pair(Widget\Widget::COLOR_DIALOGTEXT, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE);
     ncurses_refresh();
 }
コード例 #7
0
ファイル: Screen.php プロジェクト: ck99/kurses
 public function __construct(EventLoop $loop)
 {
     $this->loop = $loop;
     ncurses_init();
     ncurses_cbreak();
     ncurses_noecho();
     $this->panels = [];
     if (ncurses_has_colors()) {
         ncurses_start_color();
     }
     $this->cursor = new Cursor(null, null, false);
     $this->loop->every([$this, 'refresh'], 200);
     stream_set_blocking(STDIN, FALSE);
     $this->loop->attachStreamHandler(STDIN, [$this, 'handleStdIn']);
 }
コード例 #8
0
ファイル: cwt.php プロジェクト: noccy80/cherryphp
 function __construct()
 {
     if (!self::$cwt) {
         self::$cwt = $this;
     }
     $this->buffer = new \Data\FifoQueue(50);
     if (!function_exists('\\ncurses_init')) {
         die("This application requires ncurses to work.");
     }
     \ncurses_init();
     if (ncurses_has_colors()) {
         $this->initColors();
     }
     ncurses_curs_set(0);
     ncurses_noecho();
     ncurses_mousemask(NCURSES_ALL_MOUSE_EVENTS);
     $oldmask = null;
     $newmask = NCURSES_BUTTON1_CLICKED | NCURSES_BUTTON1_RELEASED | NCURSES_BUTTON1_PRESSED | NCURSES_BUTTON2_CLICKED | NCURSES_BUTTON2_RELEASED | NCURSES_BUTTON1_PRESSED | NCURSES_BUTTON3_CLICKED | NCURSES_BUTTON3_RELEASED | NCURSES_BUTTON1_PRESSED | NCURSES_BUTTON4_CLICKED | NCURSES_BUTTON4_RELEASED | NCURSES_BUTTON1_PRESSED;
     $mask = ncurses_mousemask($newmask, $oldmask);
     $this->fpin = fopen("php://stdin", "r");
     //open direct input stream for reading
     stream_set_blocking($this->fpin, 0);
     //set non-blocking mode
 }
コード例 #9
0
ファイル: Window.php プロジェクト: jean-pasqualini/ia
 /**
  * Set color
  *
  * @param   int     $pair
  * @param   int     $foreground
  * @param   int     $background
  * @return void
  */
 public function setColor($pair, $foreground = 0, $background = 0)
 {
     if (ncurses_has_colors()) {
         ncurses_start_color();
         ncurses_init_pair($pair, $foreground, $background);
         ncurses_wcolor_set($this->getWindow(), $pair);
     }
     $this->setChanged(true);
     return $pair;
 }
コード例 #10
0
ファイル: example1.php プロジェクト: senggen/php52-backports
<?php

$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();
}
?>
コード例 #11
0
ファイル: ApplicationTest.php プロジェクト: nicholasc/blink
 public function testHasColorIsBool()
 {
     $app = new \Blink\Application();
     $this->assertInternalType('boolean', $app->hasColor());
     $this->assertEquals(ncurses_has_colors(), $app->hasColor());
 }
コード例 #12
0
ファイル: Terminal.php プロジェクト: wapmorgan/ncursesobjects
 /**
  * @return bool
  */
 public function hasColors()
 {
     return ncurses_has_colors();
 }