37 lines
		
	
	
		
			1015 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1015 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/*
 | 
						|
 *  Basic shell example, demonstrates adding a listener to update the prompt with
 | 
						|
 *  the current time as well as creating an "anonymous" context and adding a
 | 
						|
 *  command to it. It also shows how to change the style of the prompt.
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
require_once __DIR__."/../vendor/autoload.php";
 | 
						|
 | 
						|
use NoccyLabs\Shell\Shell;
 | 
						|
use NoccyLabs\Shell\Style;
 | 
						|
use NoccyLabs\Shell\Context;
 | 
						|
 | 
						|
$myShell = new Shell();
 | 
						|
 | 
						|
// Set the style of prompt and input
 | 
						|
$myShell->setPromptStyle(new Style(Style::BR_GREEN, Style::GREEN));
 | 
						|
$myShell->setInputStyle(new Style(Style::BR_CYAN));
 | 
						|
 | 
						|
// Add a listener to update the prompt
 | 
						|
$myShell->addListener(Shell::EVT_UPDATE_PROMPT, function ($e) {
 | 
						|
    $e->shell->setPrompt(date("H:i:s").">");
 | 
						|
});
 | 
						|
 | 
						|
// Set the initial prompt, not really needed.
 | 
						|
$myShell->setPrompt("test>");
 | 
						|
 | 
						|
// Create an anonymous context and add a command
 | 
						|
$ctx = $myShell->createContext("root");
 | 
						|
$ctx->addCommand("hello", function () {
 | 
						|
    echo "Hello World!\n";
 | 
						|
}, [ 'descr'=>'Say hello' ]);
 | 
						|
 | 
						|
// Run the shell
 | 
						|
$myShell->run();
 |