scanner/ncurses/example.php
Correl Roush a3dfc6d2b8 Updated ncurses library, now event driven!
git-svn-id: file:///srv/svn/scanner/trunk@18 a0501263-5b7a-4423-a8ba-1edf086583e7
2008-04-24 18:22:08 +00:00

60 lines
1.6 KiB
PHP

<?php
/**
* Example ncurses application
*
* @package Nc
* @subpackage Example
*/
/**
* Include ncurses library
*/
require_once( 'ncurses.php' );
/**
* Example Nc Application
*
* @package Nc
* @subpackage Example
*/
define( 'DEBUG', 1 );
class LogView extends NcTableView {
public function __construct($parent, $height, $width, $y, $x, $params = array()) {
parent::__construct($parent, $height, $width, $y, $x, $params);
// If we don't prevent the event logging table from logging its own signals,
// it'll find itself in a recursive spiral into memory usage hell
$this->emit_log_filter[] = 'change';
}
}
class MyEventApp extends NcApp {
function init() {
$this->screen->title('Ncurses Example Application');
$input = array();
for($i = 0; $i < 3; $i++) {
$input[] = new NcTextInput($this->screen, 0, 2*$i, 0);
}
$log = new LogView($this->screen, $this->screen->height() - 11, 0, 7, 0, array(
'columns' => array(
'class' => 'Class',
'message' => 'Message'
)
));
$log->title('Application Log');
$progress = new NcProgressBar($this->screen, 0, $this->screen->height() - 4, 0);
$button = new NcButton($this->screen, 3, 10, $this->screen->height() - 3, 0, 'Quit');
Signaler::connect($this, 'log', $log, 'load');
Signaler::connect($log, 'change', $progress, 'pos');
Signaler::connect($this, 'log_items', $progress, 'max');
Signaler::connect($button, 'clicked', $this, 'quit');
$log->load($this->log);
}
function log(&$object, $message) {
parent::log($object, $message);
$this->emit('log_items', count($this->log) - 1);
}
}
$app = new MyEventApp();
$app->exec();
?>