/** * Initiate our NCurses panels. */ private function init() { // Get Sizes $top = $right = $bottom = $left = 0; ncurses_getmaxyx(STDSCR, $bottom, $right); $this->lastBottom = $bottom; $this->lastRight = $right; // Panel Layouts $traceWidth = min($right / 2, 55); $traceHeight = $bottom; $debugWidth = $right - $traceWidth; $debugHeight = 8; $inputWidth = $debugWidth; $inputHeight = 3; $outputWidth = $debugWidth; $outputHeight = $bottom - $debugHeight - $inputHeight; $this->panels['trace'] = ncurses_newwin($traceHeight, $traceWidth, $top, $right - $traceWidth); ncurses_wborder($this->panels['trace'], 0, 0, 0, 0, 0, 0, 0, 0); ncurses_mvwaddstr($this->panels['trace'], 0, 2, "[ Logging ]"); ncurses_wmove($this->panels['trace'], 2, 2); $this->panels['debug'] = ncurses_newwin($debugHeight, $debugWidth, $bottom - $debugHeight, $left); $this->panels['input'] = ncurses_newwin($inputHeight, $inputWidth, $bottom - $debugHeight - $inputHeight, $left); $this->panels['output'] = ncurses_newwin($outputHeight, $outputWidth, $top, $left); ncurses_wborder($this->panels['output'], 0, 0, 0, 0, 0, 0, 0, 0); ncurses_mvwaddstr($this->panels['output'], 0, 2, "[ Output ]"); ncurses_wmove($this->panels['output'], 2, 2); ncurses_curs_set(0); ncurses_cbreak(); ncurses_noecho(); $this->redrawAll(); }
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(); }); }
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']); }
/** * Application class constructor * * @param int $bufferMode The desired ncurses buffer mode */ public function __construct($bufferMode = null) { // Buffer mode muse be an integer if (isset($bufferMode) && !is_int($bufferMode)) { throw new Exception("Buffer mode must be an integer"); } // Initialize ncurses & save terminal state ncurses_init(); ncurses_savetty(); // Initialize buffer mode switch ($bufferMode) { case self::BUFFER_CBREAK: ncurses_cbreak(); break; default: if (isset($bufferMode) && $bufferMode !== self::BUFFER_RAW) { throw new Exception("Invalid buffer mode"); } ncurses_raw(); } // Do not echo characters ncurses_noecho(); // Create an instance of the terminal $this->terminal = new Terminal(); // Initialize colors for capable terminals if ($this->terminal->hasColor()) { ncurses_start_color(); } // Create the events manager $this->eventsMananager = new EventsManager(); // Create the states manager $this->statesManager = new StatesManager(); // The application has been initialized $this->initialized = true; }
/** * Renders the dump */ public function render() { // initialize ncurses window ncurses_init(); ncurses_curs_set(0); ncurses_noecho(); ncurses_cbreak(); ncurses_start_color(); ncurses_use_default_colors(); ncurses_init_pair(self::COLOR_RED, NCURSES_COLOR_RED, -1); ncurses_init_pair(self::COLOR_GREEN, NCURSES_COLOR_GREEN, -1); ncurses_init_pair(self::COLOR_YELLOW, NCURSES_COLOR_YELLOW, -1); ncurses_init_pair(self::COLOR_BLUE, NCURSES_COLOR_BLUE, -1); ncurses_init_pair(self::COLOR_MAGENTA, NCURSES_COLOR_MAGENTA, -1); ncurses_init_pair(self::COLOR_CYAN, NCURSES_COLOR_CYAN, -1); ncurses_init_pair(self::COLOR_WHITE, NCURSES_COLOR_WHITE, -1); ncurses_init_pair(self::COLOR_HIGHLIGHTED_DEFAULT, 0, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_RED, NCURSES_COLOR_RED, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_GREEN, NCURSES_COLOR_GREEN, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_YELLOW, NCURSES_COLOR_YELLOW, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_BLUE, NCURSES_COLOR_BLUE, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_MAGENTA, NCURSES_COLOR_MAGENTA, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_CYAN, NCURSES_COLOR_CYAN, NCURSES_COLOR_WHITE); ncurses_init_pair(self::COLOR_HIGHLIGHTED_WHITE, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLACK); // create a dummy pad which will receive user inputs $this->windowDummy = ncurses_newpad(1, 1); ncurses_keypad($this->windowDummy, true); // run interface $continue = true; $this->currentRenderer = $this->rendererVarDump; $this->createTitleWindow(); $this->createFooterWindow(); $this->refreshTitle(); $this->refreshFooter(); while ($continue) { $this->currentRenderer->refresh(); $key = ncurses_wgetch($this->windowDummy); $continue = $this->onKeypress($key); } ncurses_end(); }