All pastes #434388 Raw Edit

Someone

public text v1 · immutable
·published 2007-04-11 12:06 UTC
rendered paste body
<?php

require_once('ncurses.php');

nCurses::init();
ncurses_curs_set(0);

$window = new nCursesWindow(10,20, 1,1);
$window->set_title('window one');
$window2 = new nCursesWindow(10,20, 5,10, 'window two long title test 1 2 3 4 5');

nCurses::refresh(); // will be handeled by nCurses class
$window->refresh(); // will be handeled by nCurses class
$window2->refresh(); // will be handeled by nCurses class

nCurses::main();

?>
<?php

define('__NCURSES_COLOR_PAIR0', nCurses::COLOR_WHITE.'|'.nCurses::COLOR_BLACK);

class nCurses {

	const COLOR_BLACK = NCURSES_COLOR_BLACK;
	const COLOR_WHITE = NCURSES_COLOR_WHITE;
	const COLOR_RED = NCURSES_COLOR_RED;
	const COLOR_GREEN = NCURSES_COLOR_GREEN;
	const COLOR_YELLOW = NCURSES_COLOR_YELLOW;
	const COLOR_BLUE = NCURSES_COLOR_BLUE;
	const COLOR_CYAN = NCURSES_COLOR_CYAN;
	const COLOR_MAGENTA = NCURSES_COLOR_MAGENTA;
	
	static protected $mainloop = false;
	static protected $colorpairs = array( __NCURSES_COLOR_PAIR0 => 0);
	
	protected function __construct(){}
	protected function __clone(){}
	
	static public function end(){
		ncurses_end();
	}

	static public function get_screen_size(){
		$screen = ncurses_newwin ( 0, 0, 0, 0);
		ncurses_getmaxyx($screen, $rows,$cols);
		ncurses_delwin($screen);
		return array('rows'=>$rows, 'cols'=>$cols);
	}

	static public function refresh(){
		ncurses_refresh();
	}

	static public function init(){
		ncurses_init();
		ncurses_start_color();
		register_shutdown_function(array('nCurses','end'));
	}
	
	static public function main(){
		// this needs bulking out to handel windows and mouse stuff
		self::$mainloop = true;
		ncurses_timeout(0);
		while(self::$mainloop){
			$key = ncurses_getch();
			if ($key == nCursesKey::ESC) nCurses::main_quit();
		}
	}
	
	static public function main_quit(){
		self::$mainloop = false;
	}
	
}

require_once('ncurses/key.php');
require_once('ncurses/window.php');
require_once('ncurses/button.php');
require_once('ncurses/dialog.php');

?>