Created
September 21, 2015 00:02
-
-
Save psynaptic/bc7e3b13755043306042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$colors = array( | |
'BLACK' => NCURSES_COLOR_BLACK, | |
'WHITE' => NCURSES_COLOR_WHITE, | |
'RED' => NCURSES_COLOR_RED, | |
'GREEN' => NCURSES_COLOR_GREEN, | |
'YELLOW' => NCURSES_COLOR_YELLOW, | |
'BLUE' => NCURSES_COLOR_BLUE, | |
'CYAN' => NCURSES_COLOR_CYAN, | |
'MAGENTA' => NCURSES_COLOR_MAGENTA, | |
); | |
$attributes = array( | |
'NORMAL' => NCURSES_A_NORMAL, | |
'BOLD' => NCURSES_A_BOLD, | |
'DIM' => NCURSES_A_DIM, | |
'STANDOUT' => NCURSES_A_STANDOUT, | |
'UNDERLINE' => NCURSES_A_UNDERLINE, | |
); | |
ncurses_init(); | |
if (!ncurses_has_colors()) { | |
echo "Your terminal does not support colors.\n"; | |
exit(1); | |
} | |
ncurses_noecho(); | |
ncurses_curs_set(0); | |
ncurses_start_color(); | |
// Get the dimensions of the main window. | |
ncurses_getmaxyx(STDSCR, $height, $width); | |
$counter = 0; | |
$column_width = floor($width / count($attributes)); | |
foreach ($colors as $background_name => $background_color) { | |
foreach ($colors as $foreground_name => $foreground_color) { | |
ncurses_init_pair($counter, $foreground_color, $background_color); | |
ncurses_color_set($counter); | |
$column = 1; | |
foreach ($attributes as $attribute_name => $attribute) { | |
ncurses_attron($attribute); | |
$description = sprintf('%s %s ON %s', $attribute_name, $foreground_name, $background_name); | |
$y = $counter; | |
$x = $column * $column_width - $column_width; | |
ncurses_mvaddstr($y, $x, substr(str_pad($description, $column_width), 0, $column_width)); | |
ncurses_attroff($attribute); | |
$column++; | |
} | |
$counter++; | |
} | |
} | |
ncurses_refresh(); | |
sleep(120); | |
ncurses_end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment