public function draw() { ncurses_color_set(1); ncurses_mvwaddstr($this->wnd(), 0, 0, str_repeat(" ", $this->width)); // Measure items $fullwidth = $this->width; $numauto = 0; $alloc = 0; foreach ($this->items as $key => $item) { $item->item->update(); $itemwidth = $item->item->measure(); if ($item->width == self::SBR_WIDTH_AUTO) { $numauto++; } elseif ($item->width == self::SBR_WIDTH_EXPAND) { $alloc += $itemwidth; } else { $alloc += $item->width; } } // Count in the separator bars $alloc += (count($this->items) - 1) * 3; // With the items measured, hand out the auto space if ($numauto > 0) { $autowidth = floor(($fullwidth - $alloc) / $numauto); } // Now draw it all $cptr = 1; $idx = 0; foreach ($this->items as $key => $item) { if ($item->width == self::SBR_WIDTH_AUTO) { $itemwidth = $autowidth; } elseif ($item->width == self::SBR_WIDTH_EXPAND) { $itemwidth = $item->measure(); } else { $itemwidth = $item->width; } $cstr = substr($item->item->value, 0, $itemwidth); ncurses_color_set(1); ncurses_mvwaddstr($this->wnd(), 0, $cptr, $cstr); $idx++; $cptr += $itemwidth; if ($idx != count($this->items)) { ncurses_color_set(2); ncurses_mvwaddstr($this->wnd(), 0, $cptr, ' | '); } $cptr += 3; } ncurses_color_set(0); }
public function draw() { ncurses_color_set(1); ncurses_mvaddstr($this->top, $this->left, str_repeat(" ", $this->width)); $yp = 1; foreach ($this->menus as $id => $data) { $str = ' ' . str_replace('_', '', $data->label) . ' '; $ofs = strpos($data->label, '_'); ncurses_mvaddstr($this->top, $this->left + $yp, $str); if ($ofs !== false) { ncurses_attron(NCURSES_A_UNDERLINE); $hlchar = substr($data->label, $ofs + 1, 1); ncurses_mvaddstr($this->top, $this->left + 1 + $yp + $ofs, $hlchar); ncurses_attroff(NCURSES_A_UNDERLINE); } $yp += strlen($data->label) + 2; } ncurses_color_set(0); }
$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(); } ?>
function _init_screen() { ncurses_curs_set(0); ncurses_noecho(); $fullscreen = ncurses_newwin(0, 0, 0, 0); ncurses_getmaxyx($fullscreen, $this->_screen_max_height, $this->_screen_max_width); ncurses_delwin($fullscreen); ncurses_start_color(); ncurses_init_pair(1, NCURSES_COLOR_WHITE, NCURSES_COLOR_RED); ncurses_init_pair(4, NCURSES_COLOR_BLACK, NCURSES_COLOR_RED); ncurses_init_pair(2, NCURSES_COLOR_BLACK, NCURSES_COLOR_WHITE); ncurses_init_pair(3, NCURSES_COLOR_WHITE, NCURSES_COLOR_WHITE); ncurses_init_pair(5, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE); ncurses_init_pair(6, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE); ncurses_init_pair(7, NCURSES_COLOR_YELLOW, NCURSES_COLOR_WHITE); ncurses_color_set(1); ncurses_erase(); ncurses_mvhline(0, 0, 0, $this->_screen_max_width); ncurses_attron(NCURSES_A_BOLD); ncurses_mvaddstr(0, 1, $this->title_page_header); ncurses_attroff(NCURSES_A_BOLD); for ($y = 1; $y < $this->_screen_max_height; $y++) { ncurses_mvhline($y, 0, 32, $this->_screen_max_width); } ncurses_refresh(); }
<?php ncurses_init(); ncurses_start_color(); ncurses_init_pair(1, NCURSES_COLOR_GREEN, NCURSES_COLOR_BLACK); ncurses_init_pair(2, NCURSES_COLOR_RED, NCURSES_COLOR_BLACK); ncurses_init_pair(3, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLACK); ncurses_color_set(1); ncurses_addstr("OK "); ncurses_color_set(3); ncurses_addstr("Something succeeded!\n"); ncurses_color_set(2); ncurses_addstr("FAIL "); ncurses_color_set(3); ncurses_addstr("Something succeeded!\n");
protected function initScreen() { ncurses_curs_set(0); ncurses_noecho(); $fullscreen = ncurses_newwin(0, 0, 0, 0); ncurses_getmaxyx($fullscreen, $this->screenMaxHeight, $this->screenMaxWidth); ncurses_delwin($fullscreen); //COLOR SCHEMES ncurses_start_color(); // text color, background color /* COLOR_BLACK 0 COLOR_RED 1 COLOR_GREEN 2 COLOR_YELLOW 3 COLOR_BLUE 4 COLOR_MAGENTA 5 COLOR_CYAN 6 COLOR_WHITE 7 */ ncurses_init_pair(1, NCURSES_COLOR_WHITE, NCURSES_COLOR_RED); ncurses_init_pair(2, NCURSES_COLOR_BLACK, NCURSES_COLOR_WHITE); ncurses_init_pair(3, NCURSES_COLOR_WHITE, NCURSES_COLOR_WHITE); ncurses_init_pair(4, NCURSES_COLOR_BLACK, NCURSES_COLOR_RED); ncurses_init_pair(5, NCURSES_COLOR_WHITE, NCURSES_COLOR_BLUE); ncurses_init_pair(6, NCURSES_COLOR_YELLOW, NCURSES_COLOR_BLUE); ncurses_init_pair(7, NCURSES_COLOR_BLUE, NCURSES_COLOR_WHITE); ncurses_color_set(5); ncurses_erase(); ncurses_mvhline(0, 0, 0, $this->screenMaxWidth); ncurses_attron(NCURSES_A_BOLD); ncurses_mvaddstr(0, 1, $this->titlePageHeader); ncurses_attroff(NCURSES_A_BOLD); for ($y = 1; $y < $this->screenMaxHeight; $y++) { ncurses_mvhline($y, 0, 32, $this->screenMaxWidth); } ncurses_refresh(); }