@@ 135-218 (lines=84) @@ | ||
132 | $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white')); |
|
133 | ||
134 | // Read a keypress |
|
135 | while (!feof($inputStream)) { |
|
136 | $c = fread($inputStream, 1); |
|
137 | ||
138 | // Backspace Character |
|
139 | if ("\177" === $c) { |
|
140 | if (0 === $numMatches && 0 !== $i) { |
|
141 | $i--; |
|
142 | // Move cursor backwards |
|
143 | $output->write("\033[1D"); |
|
144 | } |
|
145 | ||
146 | if ($i === 0) { |
|
147 | $ofs = -1; |
|
148 | $matches = $autocomplete; |
|
149 | $numMatches = count($matches); |
|
150 | } else { |
|
151 | $numMatches = 0; |
|
152 | } |
|
153 | ||
154 | // Pop the last character off the end of our string |
|
155 | $ret = substr($ret, 0, $i); |
|
156 | } elseif ("\033" === $c) { |
|
157 | // Did we read an escape sequence? |
|
158 | $c .= fread($inputStream, 2); |
|
159 | ||
160 | // A = Up Arrow. B = Down Arrow |
|
161 | if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) { |
|
162 | if ('A' === $c[2] && -1 === $ofs) { |
|
163 | $ofs = 0; |
|
164 | } |
|
165 | ||
166 | if (0 === $numMatches) { |
|
167 | continue; |
|
168 | } |
|
169 | ||
170 | $ofs += ('A' === $c[2]) ? -1 : 1; |
|
171 | $ofs = ($numMatches + $ofs) % $numMatches; |
|
172 | } |
|
173 | } elseif (ord($c) < 32) { |
|
174 | if ("\t" === $c || "\n" === $c) { |
|
175 | if ($numMatches > 0 && -1 !== $ofs) { |
|
176 | $ret = $matches[$ofs]; |
|
177 | // Echo out remaining chars for current match |
|
178 | $output->write(substr($ret, $i)); |
|
179 | $i = strlen($ret); |
|
180 | } |
|
181 | ||
182 | if ("\n" === $c) { |
|
183 | $output->write($c); |
|
184 | break; |
|
185 | } |
|
186 | ||
187 | $numMatches = 0; |
|
188 | } |
|
189 | ||
190 | continue; |
|
191 | } else { |
|
192 | $output->write($c); |
|
193 | $ret .= $c; |
|
194 | $i++; |
|
195 | ||
196 | $numMatches = 0; |
|
197 | $ofs = 0; |
|
198 | ||
199 | foreach ($autocomplete as $value) { |
|
200 | // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle) |
|
201 | if (0 === strpos($value, $ret) && $i !== strlen($value)) { |
|
202 | $matches[$numMatches++] = $value; |
|
203 | } |
|
204 | } |
|
205 | } |
|
206 | ||
207 | // Erase characters from cursor to end of line |
|
208 | $output->write("\033[K"); |
|
209 | ||
210 | if ($numMatches > 0 && -1 !== $ofs) { |
|
211 | // Save cursor position |
|
212 | $output->write("\0337"); |
|
213 | // Write highlighted text |
|
214 | $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>'); |
|
215 | // Restore cursor position |
|
216 | $output->write("\0338"); |
|
217 | } |
|
218 | } |
|
219 | ||
220 | // Reset stty so it behaves normally again |
|
221 | shell_exec(sprintf('stty %s', $sttyMode)); |
@@ 190-273 (lines=84) @@ | ||
187 | $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white')); |
|
188 | ||
189 | // Read a keypress |
|
190 | while (!feof($inputStream)) { |
|
191 | $c = fread($inputStream, 1); |
|
192 | ||
193 | // Backspace Character |
|
194 | if ("\177" === $c) { |
|
195 | if (0 === $numMatches && 0 !== $i) { |
|
196 | $i--; |
|
197 | // Move cursor backwards |
|
198 | $output->write("\033[1D"); |
|
199 | } |
|
200 | ||
201 | if ($i === 0) { |
|
202 | $ofs = -1; |
|
203 | $matches = $autocomplete; |
|
204 | $numMatches = count($matches); |
|
205 | } else { |
|
206 | $numMatches = 0; |
|
207 | } |
|
208 | ||
209 | // Pop the last character off the end of our string |
|
210 | $ret = substr($ret, 0, $i); |
|
211 | } elseif ("\033" === $c) { |
|
212 | // Did we read an escape sequence? |
|
213 | $c .= fread($inputStream, 2); |
|
214 | ||
215 | // A = Up Arrow. B = Down Arrow |
|
216 | if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) { |
|
217 | if ('A' === $c[2] && -1 === $ofs) { |
|
218 | $ofs = 0; |
|
219 | } |
|
220 | ||
221 | if (0 === $numMatches) { |
|
222 | continue; |
|
223 | } |
|
224 | ||
225 | $ofs += ('A' === $c[2]) ? -1 : 1; |
|
226 | $ofs = ($numMatches + $ofs) % $numMatches; |
|
227 | } |
|
228 | } elseif (ord($c) < 32) { |
|
229 | if ("\t" === $c || "\n" === $c) { |
|
230 | if ($numMatches > 0 && -1 !== $ofs) { |
|
231 | $ret = $matches[$ofs]; |
|
232 | // Echo out remaining chars for current match |
|
233 | $output->write(substr($ret, $i)); |
|
234 | $i = strlen($ret); |
|
235 | } |
|
236 | ||
237 | if ("\n" === $c) { |
|
238 | $output->write($c); |
|
239 | break; |
|
240 | } |
|
241 | ||
242 | $numMatches = 0; |
|
243 | } |
|
244 | ||
245 | continue; |
|
246 | } else { |
|
247 | $output->write($c); |
|
248 | $ret .= $c; |
|
249 | $i++; |
|
250 | ||
251 | $numMatches = 0; |
|
252 | $ofs = 0; |
|
253 | ||
254 | foreach ($autocomplete as $value) { |
|
255 | // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle) |
|
256 | if (0 === strpos($value, $ret) && $i !== strlen($value)) { |
|
257 | $matches[$numMatches++] = $value; |
|
258 | } |
|
259 | } |
|
260 | } |
|
261 | ||
262 | // Erase characters from cursor to end of line |
|
263 | $output->write("\033[K"); |
|
264 | ||
265 | if ($numMatches > 0 && -1 !== $ofs) { |
|
266 | // Save cursor position |
|
267 | $output->write("\0337"); |
|
268 | // Write highlighted text |
|
269 | $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>'); |
|
270 | // Restore cursor position |
|
271 | $output->write("\0338"); |
|
272 | } |
|
273 | } |
|
274 | ||
275 | // Reset stty so it behaves normally again |
|
276 | shell_exec(sprintf('stty %s', $sttyMode)); |