@@ -89,9 +89,9 @@ public function ask(OutputInterface $output, $question, $default = null, array $
89
89
$ ret = '' ;
90
90
91
91
$ i = 0 ;
92
- $ matches = array ();
93
- $ numMatches = 0 ;
94
92
$ ofs = -1 ;
93
+ $ matches = $ autocomplete ;
94
+ $ numMatches = count ($ matches );
95
95
96
96
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
97
97
shell_exec ('stty -icanon -echo ' );
@@ -111,29 +111,21 @@ public function ask(OutputInterface $output, $question, $default = null, array $
111
111
112
112
if ($ i === 0 ) {
113
113
$ ofs = -1 ;
114
+ $ matches = $ autocomplete ;
115
+ $ numMatches = count ($ matches );
114
116
}
115
117
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
118
119
$ ret = substr ($ ret , 0 , $ i );
119
120
120
121
$ 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?
127
123
$ c .= fread ($ inputStream , 2 );
128
124
125
+ // A = Up Arrow. B = Down Arrow
129
126
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 ;
137
129
}
138
130
139
131
if (0 === $ numMatches ) {
@@ -143,11 +135,11 @@ public function ask(OutputInterface $output, $question, $default = null, array $
143
135
$ ofs += ('A ' === $ c [2 ]) ? -1 : 1 ;
144
136
$ ofs = ($ numMatches + $ ofs ) % $ numMatches ;
145
137
}
146
- } else if (ord ($ c ) < 32 ) {
138
+ } elseif (ord ($ c ) < 32 ) {
147
139
if ("\t" === $ c || "\n" === $ c ) {
148
140
if ($ numMatches > 0 ) {
149
141
$ ret = $ matches [$ ofs ];
150
- // Echo out completed match
142
+ // Echo out remaining chars for current match
151
143
$ output ->write (substr ($ ret , $ i ));
152
144
$ i = strlen ($ ret );
153
145
}
0 commit comments