public function draw() { $start = 3; foreach ($this->tabs as $i => $tab) { $attrs = NCURSES_A_UNDERLINE; ncurses_wmove($this->window, 0, $start); // ncurses_wvline($this->window, NCURSES_A_NORMAL, 1); if ($i === $this->active) { $attrs += NCURSES_A_REVERSE; } if ($tab->hasAlert()) { ncurses_wcolor_set($this->window, 0); } if ($attrs) { ncurses_wattron($this->window, $attrs); } $tabName = sprintf("[F%d] %s", $i + 1, $tab->name); ncurses_mvwaddstr($this->window, 0, $start + 1, $tabName); if ($attrs) { ncurses_wattroff($this->window, $attrs); } // ncurses_wvline($this->window, NCURSES_A_NORMAL, 1); $start += strlen($tabName) + 3; if ($i === $this->active) { $tab->draw(); ncurses_top_panel($tab->panel->panel); } } }
public function draw($map) { foreach ($map as $i => $line) { foreach ($line as $j => $item) { //$lineStr .= $this->format($item); ncurses_wmove($this->getWindow(), $i + 1, $j + 1); ncurses_wcolor_set($this->getWindow(), $this->formatColor($item)); ncurses_waddstr($this->getWindow(), $this->format($item)); } //ncurses_color_set(62); // ncurses_mvwaddstr($this->getWindow(), $i+1, 1, $lineStr); } }
/** * */ function draw($workspace) { $wh = $this->_wh; ncurses_wcolor_set($wh, NCC_FRAME); ncurses_wborder($wh, 0, 0, 0, 0, 0, 0, 0, 0); ncurses_wcolor_set($wh, NCC_TITLE); ncurses_wattron($wh, NCURSES_A_BOLD); $left = floor(($this->_w - 2) / 2 - (strlen($this->_title) + 2) / 2); ncurses_mvwaddstr($wh, 0, $left, ' ' . $this->_title . ' '); ncurses_wattroff($wh, NCURSES_A_BOLD); ncurses_wcolor_set($wh, NCC_TEXT); for ($n = 0; $n < $this->_h - 2; $n++) { ncurses_mvwaddstr($wh, $n + 1, 1, str_repeat(" ", $this->_w - 2)); } ncurses_wrefresh($wh); ncurses_wcolor_set($wh, 0); ncurses_move(-1, 1); ncurses_refresh(); }
/** * Prints a text to the pad * @param string $text text to print * @param int $color [optional] text color. One of the VarDumpNcurses::COLOR_* constants. Defaults to VarDumpNcurses::COLOR_DEFAULT. * @return int number of characters printed */ protected function printRawText($text, $color = VarDumpNcurses::COLOR_DEFAULT) { if ($this->internalWriteEnabled) { return $this->printRawTextInternal($text); } // print the text ncurses_wcolor_set($this->pad, $color); ncurses_waddstr($this->pad, $text); return strlen($text); }
/** * Displays specified input text box value contents * @param $index */ protected function drawInputBoxContents($index) { $win =& $this->inputBoxList[$index]['win']; $val =& $this->inputBoxList[$index]['val']; $cord_y =& $this->inputBoxList[$index]['y']; $cord_x =& $this->inputBoxList[$index]['x']; $label =& $this->inputBoxList[$index]['label']; // label offset $label_offset = 0; if ($label !== '') { $label_offset = strlen($label); // overide offset due to label length } // output the value for ($n = 0; $n < $this->inputBoxList[$index]['max_length']; $n++) { // Set content color based on has focus or not. if ($this->focusCat() === 'I' && $this->focusSubindex() == $index) { if ($n == $this->inputBoxList[$index]['val_cursor']) { //CURSOR COLOR - RED ncurses_wcolor_set($win, 1); } else { ncurses_wcolor_set($win, 5); } } else { ncurses_wcolor_set($win, 2); } // print chars that exist if (isset($val[$n])) { $char = $val[$n]; } else { $char = ' '; } ncurses_mvwaddstr($win, $cord_y, $cord_x + $label_offset + 1 + $n, $char); } }
/** * Prints a text to the pad * @param string $text text to print * @param int $color [optional] text color. One of the VarDumpNcurses::COLOR_* constants. Defaults to VarDumpNcurses::COLOR_DEFAULT. * @return int number of characters printed */ protected function printRawText($text, $color = VarDumpNcurses::COLOR_DEFAULT) { if ($this->internalWriteEnabled) { return $this->printRawTextInternal($text); } // verify if the color must be bolded $bold = false; if (in_array($color, $this->boldColorList)) { ncurses_wattron($this->pad, NCURSES_A_BOLD); $bold = true; } // print the text ncurses_wcolor_set($this->pad, $color); ncurses_waddstr($this->pad, $text); // unbold if ($bold) { ncurses_wattroff($this->pad, NCURSES_A_BOLD); } return strlen($text); }
/** * 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; }
function _createMenuSubWindow(&$win, $parent_height, $parent_width, $para_offset_y) { // auto-detect window width based on menu contents if ($this->mode == "checklist") { $menu_width = 1 + 4 + $this->menu_label_width + 2 + $this->menu_desc_width + 1; } else { $menu_width = 1 + $this->menu_label_width + 2 + $this->menu_desc_width + 1; } // Draw borders $cord['y'] = 1 + $para_offset_y; $cord['x'] = round(($parent_width - $menu_width) / 2); //$cord = $this->_getCoordinates($parent_height,$menu_width,"center","middle"); $y = $this->menu_total + 2; $x = $menu_width; $this->_drawThinBorders($win, $cord['y'], $cord['x'], $y, $x); // draw window inside borders $cord = $this->_getCoordinates($parent_height, $menu_width, "center", "middle"); $swin = ncurses_newwin($y - 2, $x - 2, $cord['y'] + $para_offset_y + 2, $cord['x'] + 1); // fill window ncurses_wcolor_set($swin, 2); for ($row = 0; $row < $y - 2; $row++) { ncurses_wmove($swin, $row, 0); ncurses_whline($swin, 32, $x - 2); } return $swin; }
/** * Refresh the footer window */ protected function refreshFooter() { $length = 1; $labels = array("F1" => "Help", "F2" => "Var dump", "F3" => "Stack trace", "Q" => "Quit"); if (null === $this->rendererStackTrace) { unset($labels["F3"]); } ncurses_werase($this->windowFooter); // write an empty space ncurses_wattron($this->windowFooter, NCURSES_A_REVERSE); ncurses_wcolor_set($this->windowFooter, NCURSES_COLOR_CYAN); ncurses_waddstr($this->windowFooter, " "); ncurses_wattroff($this->windowFooter, NCURSES_A_REVERSE); // write key/labels foreach ($labels as $key => $label) { ncurses_wcolor_set($this->windowFooter, 0); ncurses_waddstr($this->windowFooter, $key); ncurses_wattron($this->windowFooter, NCURSES_A_REVERSE); ncurses_wcolor_set($this->windowFooter, NCURSES_COLOR_CYAN); ncurses_waddstr($this->windowFooter, "{$label} "); ncurses_wattroff($this->windowFooter, NCURSES_A_REVERSE); $length += strlen($key); $length += strlen($label); $length += 1; } // fill the line $fillStr = str_repeat(" ", $this->windowFooterWidth - $length); ncurses_wattron($this->windowFooter, NCURSES_A_REVERSE); ncurses_wcolor_set($this->windowFooter, NCURSES_COLOR_CYAN); ncurses_waddstr($this->windowFooter, $fillStr); ncurses_wattroff($this->windowFooter, NCURSES_A_REVERSE); ncurses_wrefresh($this->windowFooter); }
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']); }
function setuserinput() { $sStatus = date("[H:i:s] ") . "[" . $this->aDisplayVars['nick'] . "] [Win: "; ncurses_mvwaddstr($this->userinputw, 0, 0, $this->cl); ncurses_mvwaddstr($this->userinputw, 0, 0, $sStatus); /* Now we need to draw states for our various windows. */ $bShow = false; $aInactive = array(); $aActive = array(); $iChans = 0; // Draw a list of all windows. First, get two arrays of which are active and not. foreach ($this->aBuffers as $iBuffer => $oBuffer) { if ($oBuffer->active == true) { $aActive[] = $iBuffer; } else { $aInactive[] = $iBuffer; } } // Now generate out list. First of all, we want to draw only active windows. We also want them to stand out. foreach ($aActive as $iActive) { if ($bShow == false) { ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT_ACTIVE); ncurses_waddstr($this->userinputw, $iActive); ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT); $bShow = true; } else { ncurses_waddstr($this->userinputw, ","); ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT_ACTIVE); ncurses_waddstr($this->userinputw, $iActive); ncurses_wcolor_set($this->userinputw, NC_PAIR_INPUT); } } /* * Now append inactive windows. We don't make these stand out of course. */ foreach ($aInactive as $iInactive) { if ($bShow == false) { ncurses_waddstr($this->userinputw, $iInactive); $bShow = true; } else { ncurses_waddstr($this->userinputw, ","); ncurses_waddstr($this->userinputw, $iInactive); } } ncurses_waddstr($this->userinputw, "]"); ncurses_mvwaddstr($this->userinputw, 1, 0, $this->cl); ncurses_mvwaddstr($this->userinputw, 1, 0, "[" . $this->aDisplayVars['window'] . "] " . $this->userinputt . '_'); ncurses_wrefresh($this->userinputw); }
/** * Prints a text to the pad * @param string $text text to print * @param int $color [optional] text color. One of the VarDumpNcurses::COLOR_* constants. Defaults to VarDumpNcurses::COLOR_DEFAULT. * @return int number of characters printed */ protected function printRawText($text, $color = VarDumpNcurses::COLOR_DEFAULT) { if ($this->disablePrint) { return; } // if the line being printed is the one pointed by the cursor, highlight it if ($this->posY == $this->highlightedPositionY && $this->cursorHighlight) { $color += 10; } // verify if the color must be bolded $bold = false; if (in_array($color, $this->boldColorList)) { ncurses_wattron($this->pad, NCURSES_A_BOLD); $bold = true; } // print the text line by line // each line is checked for its visibility // we save the current Y position to be able to restore it $lines = explode("\n", $text); $nLines = count($lines); $posY = $this->posY; foreach ($lines as $k => $line) { if ($this->isBeingPrintedOutside(1)) { // the line is outside of the viewport // we increment the current Y position and skip drawing it $this->posY++; continue; } elseif ($k !== $nLines - 1) { // re-add the newline character for each line but the last $line .= "\n"; } ncurses_wcolor_set($this->pad, $color); ncurses_waddstr($this->pad, $line); $this->posY++; } $this->posY = $posY; // unbold if ($bold) { ncurses_wattroff($this->pad, NCURSES_A_BOLD); } return strlen($text); }
/** * Draws the menu on the workspace. * * @param int $workspace The workspace window handle for curses */ function draw($workspace) { $wh = $this->_wh; ncurses_wcolor_set($wh, NCC_FRAME); ncurses_wborder($wh, 0, 0, 0, 0, 0, 0, 0, 0); ncurses_wcolor_set($wh, NCC_TITLE); ncurses_wattron($wh, NCURSES_A_BOLD); $left = floor(($this->_w - 2) / 2 - (strlen($this->_title) + 2) / 2); ncurses_mvwaddstr($wh, 0, $left, ' ' . $this->_title . ' '); ncurses_wattroff($wh, NCURSES_A_BOLD); ncurses_wcolor_set($wh, NCC_TEXT); $i = $this->_scroll; $sm = count($this->_items) - ($this->_h - 2); if ($sm < 0) { $sm = 0; } for ($n = 0; $n < $this->_h - 2; $n++) { if ($n + $i < count($this->_items)) { $str = " " . $this->_itemsidx[$n + $i]; } else { $str = ""; } $str .= str_repeat(' ', $this->_w - 2 - strlen($str)); if ($n + $i == $this->_selected) { ncurses_wattron($wh, NCURSES_A_REVERSE); } $str = substr($str, 0, $this->_w - 2); ncurses_mvwaddstr($wh, $n + 1, 1, $str); ncurses_wattroff($wh, NCURSES_A_REVERSE); } ncurses_wcolor_set($wh, NCC_MORE); if ($i > 0) { ncurses_wmove($wh, 1, $this->_w - 1); ncurses_waddch($wh, NCURSES_ACS_UARROW | NCURSES_A_BOLD); } if ($sm - $i > 0) { ncurses_wmove($wh, $this->_h - 2, $this->_w - 1); ncurses_waddch($wh, NCURSES_ACS_DARROW | NCURSES_A_BOLD); } ncurses_wrefresh($wh); ncurses_wcolor_set($wh, 0); ncurses_move(-1, 1); ncurses_refresh(); }
<?php require_once __DIR__ . '/NC/init.php'; $main = new \NC\StdWindow(); $main->setBorder(); $main->setTitle('MAIN'); $left = new \NC\Window(10, 20, 1, 1); $left->setBorder(); $left->setTitle('left'); 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_CYAN, NCURSES_COLOR_BLACK); ncurses_wcolor_set($left->getWindow(), 2); $right = new \NC\Window(10, 40, 1, 21); $right->setBorder(); $right->setTitle('right'); $main->add($left); $main->add($right); $main->run();
/** * Displays and creates a sub-window to contain the Menu Items * @param $win * @param $parentHeight * @param $parentWidth * @param $paraOffsetY * @param int $border * @return resource - ID of the sub-window */ protected function createMenuSubWindow(&$win, $parentHeight, $parentWidth, $paraOffsetY, $border = 0) { // auto-detect window width based on menu contents if ($this instanceof NcursesChecklist) { $menuWidth = 1 + 4 + $this->menuLabelWidth + 2 + $this->menuDescWidth + 1; } else { $menuWidth = 1 + $this->menuLabelWidth + 2 + $this->menuDescWidth + 1; } // Draw borders $cord['y'] = 1 + $paraOffsetY; $cord['x'] = round(($parentWidth - $menuWidth) / 2); //$cord = $this->getCoordinates($parent_height,$menu_width,"center","middle"); $y = $this->menuTotal + 2; $x = $menuWidth; if ($border != 0) { $this->drawThinBorders($win, $cord['y'], $cord['x'], $y, $x); } // draw window inside borders $cord = $this->getCoordinates($parentHeight, $menuWidth, self::COORD_X_CENTER, self::COORD_Y_MIDDLE); $swin = ncurses_newwin($y - 2, $x - 2, $cord['y'] + $paraOffsetY + 2, $cord['x'] + 1); // fill window ncurses_wcolor_set($swin, 2); for ($row = 0; $row < $y - 2; $row++) { ncurses_wmove($swin, $row, 0); ncurses_whline($swin, 32, $x - 2); } return $swin; }
$ligne++; } $result = pg_query($db, "select count(*) as nb_sonde, sum(case when date_trunc('minute', last_update) = (select date_trunc('minute', max(last_update)) from onewire) then 1 else 0 end ) as nb_sonde_ok, sum(case when date_trunc('minute', last_update) != (select date_trunc('minute', max(last_update)) from onewire) then 1 else 0 end ) as nb_sonde_ko, date_trunc('minute', max(last_update)) as last_update, case when (select date_trunc('minute', max(last_update)) from onewire) < current_timestamp - interval '1 min' then 1 else 0 end as alerte, current_timestamp - interval '1 min' from onewire;") or die('Erreur SQL sur recuperation des valeurs: ' . pg_error()); $maj = pg_fetch_array($result); if ($maj['nb_sonde_ok'] == $maj['nb_sonde']) { ncurses_mvwaddstr($bl, 13, 2, "Maj : "); ncurses_wcolor_set($bl, 2); ncurses_mvwaddstr($bl, 13, 8, $maj['last_update'] . " " . $maj['nb_sonde_ok'] . "/" . $maj['nb_sonde'] . " sondes"); ncurses_wcolor_set($bl, 0); } else { ncurses_mvwaddstr($bl, 13, 2, "Maj : "); ncurses_wattron($bl, NCURSES_A_BOLD); ncurses_wcolor_set($bl, 1); ncurses_mvwaddstr($bl, 13, 8, $maj['last_update'] . " " . $maj['nb_sonde_ok'] . "/" . $maj['nb_sonde'] . " sondes"); ncurses_wattroff($bl, NCURSES_A_BOLD); ncurses_wcolor_set($bl, 0); } // nb_sonde | nb_sonde_ok | nb_sonde_ko | last_update | alerte | ?column? //----------+-------------+-------------+---------------------+--------+------------------------------- // 35 | 35 | 0 | 2013-04-29 23:10:02 | 0 | 2013-04-29 21:11:27.299489+00 /* $tmp=9; ncurses_wcolor_set($bl, 1); ncurses_mvwaddstr($bl, $tmp, 2, "RED"); ncurses_wcolor_set($bl, 2); ncurses_mvwaddstr($bl, $tmp, 6, "GREEN"); ncurses_wcolor_set($bl, 3); ncurses_mvwaddstr($bl, $tmp, 12, "YELLOW"); ncurses_wcolor_set($bl, 4); ncurses_mvwaddstr($bl, $tmp, 19, "BLUE"); ncurses_wcolor_set($bl, 5);