Added getInput() method for basic async input
This commit is contained in:
31
examples/input.php
Normal file
31
examples/input.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* This example demonstrates how to use events to catch commands that
|
||||
* have not been handled by any context or builtin.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
use NoccyLabs\Shell\Shell;
|
||||
use NoccyLabs\Shell\Style;
|
||||
use NoccyLabs\Shell\Context;
|
||||
|
||||
$myShell = new Shell();
|
||||
|
||||
// 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 () use ($myShell) {
|
||||
$myShell->getInput("What is your name?", function ($name) use ($myShell) {
|
||||
echo "Hello, {$name}\n";
|
||||
$myShell->getInput("Who is your daddy and what does he do?", function ($daddy) {
|
||||
echo "{$daddy}? Oookay...\n";
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Run the shell
|
||||
$myShell->run();
|
Reference in New Issue
Block a user