Esempio n. 1
0
 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();
     });
 }
Esempio n. 2
0
File: main.php Progetto: ck99/kurses
<?php

/**
 * main.php
 * @author ciaran
 * @author Fabian 'zetaron' Stegemann
 * @date 31.10.2014 19:16
 */
require_once './vendor/autoload.php';
/**
 * @var \Kurses\EventLoop
 */
$eventLoop = \Kurses\EventLoopFactory::select();
$screen = new \Kurses\Screen($eventLoop);
$main = $screen->addPanel([]);
$hPanels = $screen->hSplitPanel($main, [1, 10]);
$vPanels = $screen->vSplitPanel($hPanels[0], [2, 2, 1]);
/** @var \Kurses\ScrollingList $scroller */
$scroller = $screen->replacePanelWithType($vPanels[1], 'Kurses\\ScrollingList');
$scroller->border();
$scroller->setTitle('Scroller');
$eventLoop->every(function () use($scroller) {
    $scroller->addLine(sprintf("[%03d] %s", mt_rand(0, 100), time()));
}, 1200);
/** @var \Kurses\ScrollingList $scroller */
$fastScroller = $screen->replacePanelWithType($vPanels[2], 'Kurses\\ScrollingList');
$fastScroller->border();
$fastScroller->setTitle('FastScroller');
$eventLoop->every(function () use($fastScroller) {
    $fastScroller->addLine(sprintf("[%03d] %s", mt_rand(0, 100), time()));
}, 200);