Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0e5a25567c | |||
bdec60717f |
12
README.md
12
README.md
@ -0,0 +1,12 @@
|
||||
NoccyLabs Shell Core
|
||||
====================
|
||||
|
||||
This library helps make elegant command line applications that spawn an isolated shell.
|
||||
It uses a standalone implementation for buffered input with support for arrow keys to
|
||||
navigate the history and more.
|
||||
|
||||
Note that this library requirements a fully ANSI compatible terminal with UTF-8 support
|
||||
in order to use colors, control the cursor position etc. As it uses `stty` to configure
|
||||
input buffering, it will likely not work on Windows.
|
||||
|
||||
|
||||
|
@ -161,22 +161,33 @@ class LineRead
|
||||
if ($this->posHistory == 0) {
|
||||
$this->stashedBuffer = $this->buffer;
|
||||
}
|
||||
if ($this->posCursor == strlen($this->buffer)) {
|
||||
$this->posCursor = -1;
|
||||
}
|
||||
if ($this->posHistory < count($this->history)) {
|
||||
$this->posHistory++;
|
||||
$this->buffer = $this->history[$this->posHistory-1];
|
||||
$this->redraw();
|
||||
}
|
||||
if ($this->posCursor == -1) {
|
||||
$this->posCursor = strlen($this->buffer);
|
||||
}
|
||||
$this->redraw();
|
||||
break;
|
||||
case "\e[B": // down
|
||||
if ($this->posCursor == strlen($this->buffer)) {
|
||||
$this->posCursor = -1;
|
||||
}
|
||||
if ($this->posHistory > 1) {
|
||||
$this->posHistory--;
|
||||
$this->buffer = $this->history[$this->posHistory-1];
|
||||
$this->redraw();
|
||||
} elseif ($this->posHistory > 0) {
|
||||
$this->posHistory--;
|
||||
$this->buffer = $this->stashedBuffer;
|
||||
$this->redraw();
|
||||
}
|
||||
if ($this->posCursor == -1) {
|
||||
$this->posCursor = strlen($this->buffer);
|
||||
}
|
||||
$this->redraw();
|
||||
break;
|
||||
default:
|
||||
fprintf(STDERR, "\n%s\n", substr($code,1));
|
||||
|
@ -321,6 +321,7 @@ class Shell
|
||||
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
$this->lineReader = new LineRead();
|
||||
|
||||
$this->lineReader->setPromptText($this->prompt);
|
||||
@ -374,6 +375,10 @@ class Shell
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
fprintf(STDERR, "\e[31;1mFatal: Unhandled exception\e[0m\n\n%s\n", $e);
|
||||
}
|
||||
|
||||
$this->lineReader = null;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user