merged branch lmcd/autocomplete-cleanups (PR #6594)
This PR was squashed before being merged into the master branch (closes #6594).
Commits
-------
9d94fc7
[Console] Autocomplete cleanups/optimisations
Discussion
----------
[Console] Autocomplete cleanups/optimisations
I know the optimisations to this code are getting kinda ridiculous, but I found a few more things to tidy up.
This commit is contained in:
commit
5adecd7780
@ -89,9 +89,9 @@ class DialogHelper extends Helper
|
|||||||
$ret = '';
|
$ret = '';
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$matches = array();
|
|
||||||
$numMatches = 0;
|
|
||||||
$ofs = -1;
|
$ofs = -1;
|
||||||
|
$matches = $autocomplete;
|
||||||
|
$numMatches = count($matches);
|
||||||
|
|
||||||
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
|
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
|
||||||
shell_exec('stty -icanon -echo');
|
shell_exec('stty -icanon -echo');
|
||||||
@ -111,29 +111,21 @@ class DialogHelper extends Helper
|
|||||||
|
|
||||||
if ($i === 0) {
|
if ($i === 0) {
|
||||||
$ofs = -1;
|
$ofs = -1;
|
||||||
|
$matches = $autocomplete;
|
||||||
|
$numMatches = count($matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erase characters from cursor to end of line
|
// Pop the last character off the end of our string
|
||||||
$output->write("\033[K");
|
|
||||||
$ret = substr($ret, 0, $i);
|
$ret = substr($ret, 0, $i);
|
||||||
|
|
||||||
$numMatches = 0;
|
$numMatches = 0;
|
||||||
|
} elseif ("\033" === $c) { // Did we read an escape sequence?
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Did we read an escape sequence?
|
|
||||||
if ("\033" === $c) {
|
|
||||||
$c .= fread($inputStream, 2);
|
$c .= fread($inputStream, 2);
|
||||||
|
|
||||||
|
// A = Up Arrow. B = Down Arrow
|
||||||
if ('A' === $c[2] || 'B' === $c[2]) {
|
if ('A' === $c[2] || 'B' === $c[2]) {
|
||||||
if (0 === $i) {
|
if ('A' === $c[2] && -1 === $ofs) {
|
||||||
$matches = $autocomplete;
|
$ofs = 0;
|
||||||
$numMatches = count($matches);
|
|
||||||
|
|
||||||
if ('A' === $c[2] && -1 === $ofs) {
|
|
||||||
$ofs = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === $numMatches) {
|
if (0 === $numMatches) {
|
||||||
@ -143,11 +135,11 @@ class DialogHelper extends Helper
|
|||||||
$ofs += ('A' === $c[2]) ? -1 : 1;
|
$ofs += ('A' === $c[2]) ? -1 : 1;
|
||||||
$ofs = ($numMatches + $ofs) % $numMatches;
|
$ofs = ($numMatches + $ofs) % $numMatches;
|
||||||
}
|
}
|
||||||
} else if (ord($c) < 32) {
|
} elseif (ord($c) < 32) {
|
||||||
if ("\t" === $c || "\n" === $c) {
|
if ("\t" === $c || "\n" === $c) {
|
||||||
if ($numMatches > 0) {
|
if ($numMatches > 0) {
|
||||||
$ret = $matches[$ofs];
|
$ret = $matches[$ofs];
|
||||||
// Echo out completed match
|
// Echo out remaining chars for current match
|
||||||
$output->write(substr($ret, $i));
|
$output->write(substr($ret, $i));
|
||||||
$i = strlen($ret);
|
$i = strlen($ret);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user