Improved the context stack
This commit is contained in:
parent
482d8a54e5
commit
7bfd8453e7
12
examples/basic.php
Normal file
12
examples/basic.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__."/../vendor/autoload.php";
|
||||||
|
|
||||||
|
use NoccyLabs\Shell\Shell;
|
||||||
|
use NoccyLabs\Shell\Context;
|
||||||
|
|
||||||
|
|
||||||
|
$myShell = new Shell();
|
||||||
|
$myShell->setPrompt("test>");
|
||||||
|
$myShell->pushContext(new Context());
|
||||||
|
$myShell->run();
|
@ -23,6 +23,11 @@ class Context
|
|||||||
$this->configure();
|
$this->configure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getContextInfo()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function setShell(Shell $shell)
|
public function setShell(Shell $shell)
|
||||||
{
|
{
|
||||||
$this->shell = $shell;
|
$this->shell = $shell;
|
||||||
|
@ -232,11 +232,11 @@ class Shell
|
|||||||
switch ($command) {
|
switch ($command) {
|
||||||
case '.':
|
case '.':
|
||||||
$type = basename(strtr(get_class($this->context), "\\", "/"));
|
$type = basename(strtr(get_class($this->context), "\\", "/"));
|
||||||
printf("%s<%s>: %s\n", $type, $this->context->getName(), json_encode($this->context->getData()));
|
printf("%s<%s>: %s\n", $type, $this->context->getName(), $this->context->getContextInfo());
|
||||||
$level = 0;
|
$level = 0;
|
||||||
foreach ($this->contextStack as $context) {
|
foreach ($this->contextStack as $context) {
|
||||||
$type = basename(strtr(get_class($context), "\\", "/"));
|
$type = basename(strtr(get_class($context), "\\", "/"));
|
||||||
printf(" %s- %s<%s>\n", str_repeat(" ",$level++), $type, $context->getName());
|
printf(" %s└─%s<%s>: %s\n", str_repeat(" ",$level++), $type, $context->getName(), $context->getContextInfo());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '..':
|
case '..':
|
||||||
|
Loading…
Reference in New Issue
Block a user