2008-02-28 16:39:33 +00:00
|
|
|
<?php
|
2008-02-29 15:39:44 +00:00
|
|
|
/**
|
|
|
|
* Example ncurses application
|
|
|
|
*
|
|
|
|
* @package Nc
|
|
|
|
* @subpackage Example
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include ncurses library
|
|
|
|
*/
|
2008-02-28 16:39:33 +00:00
|
|
|
require_once( 'ncurses.php' );
|
|
|
|
|
2008-02-29 15:39:44 +00:00
|
|
|
/**
|
|
|
|
* Example Nc Application
|
|
|
|
*
|
|
|
|
* @package Nc
|
|
|
|
* @subpackage Example
|
|
|
|
*/
|
2008-04-24 18:22:08 +00:00
|
|
|
|
|
|
|
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);
|
2008-02-28 16:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-24 18:22:08 +00:00
|
|
|
$app = new MyEventApp();
|
|
|
|
$app->exec();
|
2008-02-28 16:39:33 +00:00
|
|
|
?>
|