/** * Writes a message to the output. * * @param string $message A message to write to the output * @param bool $newline Whether to add a newline or not */ protected function doWrite($message, $newline) { //$message = "lol"; $message = strip_tags($message); //ncurses_waddstr($this->window, $message, count($message)); if ($newline) { ncurses_getyx(STDSCR, $curx, $cury); ncurses_move($cury + 1, 0); ncurses_wrefresh($this->window); // ncurses_addchnstr("\n", 1); // // } }
/** * {@inheritdoc} */ protected function render() { foreach ($this->constants as $cat => $values) { // retrieve current position $x = null; $y = null; ncurses_getyx($this->getPadResource(), $y, $x); // category name ncurses_wattron($this->getPadResource(), NCURSES_A_BOLD); $catText = $this->isElementExpanded($cat) ? "{$cat} ▾" : "{$cat} ▸"; $this->printText("<<4>>{$catText}\n"); ncurses_wattroff($this->getPadResource(), NCURSES_A_BOLD); $this->setExpandableElementPositionY($cat, $y); if (!$this->isElementExpanded($cat)) { continue; } // category constants if (!empty($values)) { $maxLength = 0; foreach ($values as $name => $value) { $maxLength = max($maxLength, strlen($name)); } foreach ($values as $name => $value) { $name = str_pad($name, $maxLength, " ", STR_PAD_RIGHT); switch (gettype($value)) { case "string": $value = str_replace(array("\n", "\r", "\t"), array("\\n", "\\r", "\\t"), $value); break; case "bool": case "boolean": $value = $value ? "true" : "false"; $value = "<<2>>{$value}"; break; case "null": case "NULL": $value = "<<2>>null"; break; } $this->printText(" <<3>>{$name} : <<0>>{$value}\n"); } } else { // no constants $this->_firePhp->log("* empty *"); } } }
public function handleKey() { ncurses_getyx(STDSCR, $cury, $curx); // Read one character $c = ncurses_getch(); if ($c == NCURSES_KEY_RETURN) { $in = trim($this->getInput()); // Split input to command and arguments $command = explode(' ', $in, 2); $command[0] = strtolower($command[0]); // Empty command - user just pressed enter if (strlen($command[0]) == 0) { return; } // Command has been given, so: // Add to history, clear the prompt, disable scrollback array_push($this->history, $in); $this->drawPrompt(); $this->historyScrollback = -1; // Add to output so we can see what we are doing $this->addOutput('> ' . $in); // Command not found if (!array_key_exists($command[0], $this->commands)) { $this->addOutput('Unknown command: ' . $command[0]); return; } // Run the command $this->commands[$command[0]]($this, $command[1]); } else { if ($c == NCURSES_KEY_LEFT) { // Move the cursor left ncurses_move($cury, $curx - 1); } else { if ($c == NCURSES_KEY_RIGHT) { // Move the cursor right ncurses_move($cury, $curx + 1); } else { if ($c == NCURSES_KEY_UP) { // If the user is not browsing history, start with the last element + 1 if ($this->historyScrollback == -1) { // There is no history - we can't open it if (count($this->history) == 0) { return; } $this->historyScrollback = count($this->history); } // Move to a previous element $this->historyScrollback--; // The user scrolled beyond the list - move to the first item if ($this->historyScrollback < 0) { $this->historyScrollback = 0; } $this->drawPrompt($this->history[$this->historyScrollback]); } else { if ($c == NCURSES_KEY_DOWN) { // User is not browsing the history - we can't go lower if ($this->historyScrollback == -1) { return; } $this->historyScrollback++; // Disable scrollback when the user went outside the list if ($this->historyScrollback >= count($this->history)) { $this->historyScrollback = -1; $this->drawPrompt(); return; } $this->drawPrompt($this->history[$this->historyScrollback]); } else { if ($c == NCURSES_KEY_BACKSPACE) { // Remove one character to the left of the cursor ncurses_mvdelch($cury, $curx - 1); } else { if ($c == NCURSES_KEY_DC) { // Remove one character at the cursor ncurses_delch($c); } else { if (ctype_print($c)) { // Just print out an ordinary character ncurses_insch($c); ncurses_move($cury, $curx + 1); } } } } } } } } $this->checkCursorBounds(); ncurses_refresh(); }
public function log($msg, $color = self::CLR_DEFAULT) { ncurses_getmaxyx($this->windows['log'], $y, $x); ncurses_getyx($this->windows['log'], $cy, $cx); // cursor xy if ($cy > $y - 3) { ncurses_werase($this->windows['log']); ncurses_wborder($this->windows['log'], 0, 0, 0, 0, 0, 0, 0, 0); $cy = 0; } $msg = mb_substr($msg, 0, $x - 2); $color and ncurses_wcolor_set($this->windows['log'], $color); ncurses_mvwaddstr($this->windows['log'], $cy + 1, 1, $msg); ncurses_clrtoeol(); $color and ncurses_wcolor_set($this->windows['log'], self::CLR_DEFAULT); // никак скроллить не выходит #ncurses_insdelln (1); #ncurses_scrl (-2); // вообще 0 реакции #ncurses_insertln (); ncurses_wrefresh($this->windows['log']); }
/** * {@inheritdoc} */ protected function render() { if (null === $this->profilerManager || 0 == count($this->profilerManager)) { return; } $this->profileParamsList = array(); foreach ($this->profilerManager as $idProfiler => $profiler) { // retrieve current position $x = null; $y = null; ncurses_getyx($this->getPadResource(), $y, $x); // print profiler name and total execution time for that profiler $totalTime = count($profiler) ? $profiler->getTotalElapsedSecs() : 0; $totalTime = number_format($totalTime, 4, ".", " "); $title = $profiler->getProfilerName() . " <<5>>(total execution time : {$totalTime} s)"; $symbol = $this->isElementExpanded($idProfiler) ? "▾" : "▸"; ncurses_wattron($this->getPadResource(), NCURSES_A_BOLD); $this->printText("<<4>>{$title} <<4>>{$symbol}\n"); ncurses_wattroff($this->getPadResource(), NCURSES_A_BOLD); $this->setExpandableElementPositionY($idProfiler, $y); if (!$this->isElementExpanded($idProfiler)) { continue; } // print profiles if (count($profiler)) { foreach ($profiler as $i => $profile) { $funcName = $profile->getCallingFunction(); $file = $profile->getCallingFile(); $line = $profile->getCallingLine(); $comment = $profile->getComment(); $this->printText(" "); ncurses_wattron($this->getPadResource(), NCURSES_A_REVERSE); $this->printText("<<6>>#{$i} {$funcName}\n"); ncurses_wattroff($this->getPadResource(), NCURSES_A_REVERSE); // base infos $this->printText(" <<2>>Start file : <<0>>{$file}\n"); $this->printText(" <<2>>Start line : <<0>>{$line}\n"); if ($comment) { $this->printText(" <<2>>Comment : <<0>>{$comment}\n"); } $this->printText(" \n"); // args $x = null; $y = null; ncurses_getyx($this->getPadResource(), $y, $x); $this->printText(" <<4>>Params ▸\n"); $this->printText(" \n"); $this->profileParamsList[$y] = $profile->getParams(); // query stats $startTime = $profile->getStartMicrotime() - $this->startMicrotime; $endTime = $profile->getEndMicrotime() ? $profile->getEndMicrotime() - $this->startMicrotime : 0; $profileTime = $this->formatQueryTime($startTime, $endTime); $startMemory = $profile->getStartMemoryUsage(true); $endMemory = $profile->getEndMemoryUsage(true); $startPeakMemory = $profile->getStartPeakMemoryUsage(true); $endPeakMemory = $profile->getEndPeakMemoryUsage(true); $profileMemory = $this->formatQueryMemory($startMemory, $endMemory, "Memory usage"); $profilePeakMemory = $this->formatQueryMemory($startPeakMemory, $endPeakMemory, "Memory peak usage"); $profileStats = array("{$profileTime[0]} | {$profileMemory[0]} | {$profilePeakMemory[0]}", "{$profileTime[1]} | {$profileMemory[1]} | {$profilePeakMemory[1]}", "{$profileTime[2]} | {$profileMemory[2]} | {$profilePeakMemory[2]}", "{$profileTime[3]} |"); foreach ($profileStats as $statLine) { $this->printText(" {$statLine}\n"); } $this->printText(" \n"); // stack trace $stackTrace = $profile->getCallingTrace(); $num = count($stackTrace) - 1; $numLength = strlen($num); foreach ($stackTrace as $event) { $numString = str_pad($num, $numLength, "0", STR_PAD_LEFT); $this->printText(" <<0>>#{$numString} <<1>>{$event['func']}\n"); $this->printText(" <<2>>File :<<0>> {$event['file']}\n"); $this->printText(" <<2>>Line :<<0>> {$event['line']}\n"); $this->printText(" \n"); $num--; } } } } }
/** * {@inheritdoc} */ protected function render() { if (null === $this->dataProfilerManager || 0 == count($this->dataProfilerManager)) { return; } foreach ($this->dataProfilerManager as $idProfiler => $profiler) { // retrieve current position $x = null; $y = null; ncurses_getyx($this->getPadResource(), $y, $x); // print profiler name and total execution time for that profiler $totalTime = count($profiler) ? $profiler->getTotalElapsedSecs() : 0; $totalTime = number_format($totalTime, 4, ".", " "); $title = $profiler->getDataSourceName() . " <<5>>(total execution time : {$totalTime} s)"; $symbol = $this->isElementExpanded($idProfiler) ? "▾" : "▸"; ncurses_wattron($this->getPadResource(), NCURSES_A_BOLD); $this->printText("<<4>>{$title} <<4>>{$symbol}\n"); ncurses_wattroff($this->getPadResource(), NCURSES_A_BOLD); $this->setExpandableElementPositionY($idProfiler, $y); if (!$this->isElementExpanded($idProfiler)) { continue; } // print profiles if (count($profiler)) { foreach ($profiler as $i => $query) { $this->printText(" "); ncurses_wattron($this->getPadResource(), NCURSES_A_REVERSE); $i = str_pad($i, 6, " ", STR_PAD_RIGHT); $this->printText("<<6>>#{$i}\n"); ncurses_wattroff($this->getPadResource(), NCURSES_A_REVERSE); // print query $queryText = $profiler->getFormatter()->formatPlain($query->getQueryText()); $queryText = str_replace(array("\r\n", "\r"), "\n", $queryText); $queryText = str_replace("\t", " ", $queryText); $queryText = explode("\n", $queryText); foreach ($queryText as $queryLine) { $this->printText(" {$queryLine}\n"); } $this->printText(" \n"); // query params if ($query->getQueryParams()) { $maxLength = 0; foreach ($query->getQueryParams() as $paramName => $paramValue) { $maxLength = max($maxLength, strlen($paramName)); } foreach ($query->getQueryParams() as $paramName => $paramValue) { $paramType = "object" == gettype($paramValue) ? get_class($paramValue) : gettype($paramValue); switch ($paramType) { case "string": case "integer": case "long": case "float": case "double": // leave value as is break; case "bool": case "boolean": $paramValue = $paramValue ? "true" : "false"; break; case "null": case "NULL": case "array": default: $paramValue = ""; } $paramName = str_pad($paramName, $maxLength, " ", STR_PAD_RIGHT); $this->printText(" <<5>>{$paramName} => <<2>>({$paramType}) <<5>>{$paramValue}\n"); } $this->printText(" \n"); } // query stats $startTime = $query->getStartMicrotime() - $this->startMicrotime; $endTime = $query->getEndMicrotime() ? $query->getEndMicrotime() - $this->startMicrotime : 0; $queryTime = $this->formatQueryTime($startTime, $endTime); $startMemory = $query->getStartMemoryUsage(true); $endMemory = $query->getEndMemoryUsage(true); $startPeakMemory = $query->getStartPeakMemoryUsage(true); $endPeakMemory = $query->getEndPeakMemoryUsage(true); $queryMemory = $this->formatQueryMemory($startMemory, $endMemory, "Memory usage"); $queryPeakMemory = $this->formatQueryMemory($startPeakMemory, $endPeakMemory, "Memory peak usage"); $queryStats = array("{$queryTime[0]} | {$queryMemory[0]} | {$queryPeakMemory[0]}", "{$queryTime[1]} | {$queryMemory[1]} | {$queryPeakMemory[1]}", "{$queryTime[2]} | {$queryMemory[2]} | {$queryPeakMemory[2]}", "{$queryTime[3]} |"); foreach ($queryStats as $statLine) { $this->printText(" {$statLine}\n"); } $this->printText(" \n"); } } } }
/** * Move the cursor's position on the screen. * * @param int $x The cursors' position on the x axis. * @param int $y The cursor's position on the y axis. * * @return void */ public function move($x, $y) { ncurses_move($x, $y); ncurses_getyx(STDSCR, $this->y, $this->x); }
/** * {@inheritdoc} */ protected function printRawText($text, $color = ExceptionRendererNcurses::COLOR_DEFAULT) { // if the current position is pointed by the cursor, change the text color to display a white background $x = null; $y = null; ncurses_getyx($this->getPadResource(), $y, $x); if ($y == $this->cursorPositionY) { $color += 10; } // print text parent::printRawText($text, $color); // calculate max Y position ncurses_getyx($this->getPadResource(), $y, $x); if ("\n" == substr($text, -1)) { $y -= 1; } $this->maxY = max($this->maxY, $y); }