Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
7bfd8453e7 | |||
482d8a54e5 |
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();
|
||||
}
|
||||
|
||||
public function getContextInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setShell(Shell $shell)
|
||||
{
|
||||
$this->shell = $shell;
|
||||
|
@ -68,7 +68,7 @@ class LineRead
|
||||
$this->posCursor = strlen($this->buffer);
|
||||
}
|
||||
|
||||
$cursor = strlen($this->prompt) + 1 + $this->posCursor - $this->posScroll;
|
||||
$cursor = strlen($this->prompt) + 2 + $this->posCursor - $this->posScroll;
|
||||
|
||||
$endStyle = "\e[0m";
|
||||
|
||||
|
@ -19,6 +19,8 @@ class Shell
|
||||
|
||||
protected $timers = [];
|
||||
|
||||
protected $prompt = ">";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->configure();
|
||||
@ -162,11 +164,12 @@ class Shell
|
||||
|
||||
public function setPrompt($text)
|
||||
{
|
||||
if (!$this->lineReader) {
|
||||
return;
|
||||
}
|
||||
$this->prompt = $text;
|
||||
|
||||
if ($this->lineReader) {
|
||||
$this->lineReader->setPromptText($text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a command and return a closure.
|
||||
@ -229,11 +232,11 @@ class Shell
|
||||
switch ($command) {
|
||||
case '.':
|
||||
$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;
|
||||
foreach ($this->contextStack as $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;
|
||||
case '..':
|
||||
@ -314,7 +317,7 @@ class Shell
|
||||
{
|
||||
$this->lineReader = new LineRead();
|
||||
|
||||
$this->lineReader->setPromptText("shell>");
|
||||
$this->lineReader->setPromptText($this->prompt);
|
||||
$this->lineReader->setPromptStyle(new Style(Style::BR_GREEN));
|
||||
$this->lineReader->setCommandStyle(new Style(Style::GREEN));
|
||||
|
||||
|
Reference in New Issue
Block a user