8000 merged branch lmcd/autocomplete-cleanups (PR #6594) · symfony/symfony@5adecd7 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5adecd7

Browse files
committed
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.
2 parents dbca040 + 9d94fc7 commit 5adecd7

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/Symfony/Component/Console/Helper/DialogHelper.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public function ask(OutputInterface $output, $question, $default = null, array $
8989
$ret = '';
9090

9191
$i = 0;
92-
$matches = array();
93-
$numMatches = 0;
9492
$ofs = -1;
93+
$matches = $autocomplete;
94+
$numMatches = count($matches);
9595

9696
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
9797
shell_exec('stty -icanon -echo');
@@ -111,29 +111,21 @@ public function ask(OutputInterface $output, $question, $default = null, array $
111111

112112
if ($i === 0) {
113113
$ofs = -1;
114+
$matches = $autocomplete;
115+
$numMatches = count($matches);
114116
}
115117

116-
// Erase characters from cursor to end of line
117-
$output->write("\033[K");
118+
// Pop the last character off the end of our string
118119
$ret = substr($ret, 0, $i);
119120

120121
$numMatches = 0;
121-
122-
continue;
123-
}
124-
125-
// Did we read an escape sequence?
126-
if ("\033" === $c) {
122+
} elseif ("\033" === $c) { // Did we read an escape sequence?
127123
$c .= fread($inputStream, 2);
128124

125+
// A = Up Arrow. B = Down Arrow
129126
if ('A' === $c[2] || 'B' === $c[2]) {
130-
if (0 === $i) {
131-
$matches = $autocomplete;
132-
$numMatches = count($matches);
133-
134-
if ('A' === $c[2] && -1 === $ofs) {
135-
$ofs = 0;
136-
}
127+
if ('A' === $c[2] && -1 === $ofs) {
128+
$ofs = 0;
137129
}
138130

139131
if (0 === $numMatches) {
@@ -143,11 +135,11 @@ public function ask(OutputInterface $output, $question, $default = null, array $
143135
$ofs += ('A' === $c[2]) ? -1 : 1;
144136
$ofs = ($numMatches + $ofs) % $numMatches;
145137
}
146-
} else if (ord($c) < 32) {
138+
} elseif (ord($c) < 32) {
147139
if ("\t" === $c || "\n" === $c) {
148140
if ($numMatches > 0) {
149141
$ret = $matches[$ofs];
150-
// Echo out completed match
142+
// Echo out remaining chars for current match
151143
$output->write(substr($ret, $i));
152144
$i = strlen($ret);
153145
}

0 commit comments

Comments
 (0)
0