Mercurial > louis > kiibohd-controller
comparison Debug/cli/cli.c @ 328:9dd55aa71d76
Avoid putting blank entries in history, allow linefeed for enter
author | Matt Ventura <mattventura@mattventura.net> |
---|---|
date | Thu, 04 Jun 2015 17:42:58 -0700 |
parents | 18c3c4924f20 |
children | 32dfab699fc0 |
comparison
equal
deleted
inserted
replaced
325:b2c8581307bc | 328:9dd55aa71d76 |
---|---|
147 while ( CLILineBufferCurrent > prev_buf_pos ) | 147 while ( CLILineBufferCurrent > prev_buf_pos ) |
148 { | 148 { |
149 // Check for control characters | 149 // Check for control characters |
150 switch ( CLILineBuffer[prev_buf_pos] ) | 150 switch ( CLILineBuffer[prev_buf_pos] ) |
151 { | 151 { |
152 case 0x0D: // Enter | 152 // Enter |
153 case 0x0A: // LF | |
154 case 0x0D: // CR | |
153 CLILineBuffer[CLILineBufferCurrent - 1] = ' '; // Replace Enter with a space (resolves a bug in args) | 155 CLILineBuffer[CLILineBufferCurrent - 1] = ' '; // Replace Enter with a space (resolves a bug in args) |
154 | 156 |
155 // Remove the space if there is no command | 157 // Remove the space if there is no command |
156 if ( CLILineBufferCurrent == 1 ) | 158 if ( CLILineBufferCurrent == 1 ) |
159 { | |
157 CLILineBufferCurrent--; | 160 CLILineBufferCurrent--; |
158 | 161 } |
159 // Process the current line buffer | 162 else |
160 CLI_commandLookup(); | |
161 | |
162 // Add the command to the history | |
163 CLI_saveHistory( CLILineBuffer ); | |
164 | |
165 // Keep the array circular, discarding the older entries | |
166 if ( CLIHistoryTail < CLIHistoryHead ) | |
167 CLIHistoryHead = ( CLIHistoryHead + 1 ) % CLIMaxHistorySize; | |
168 CLIHistoryTail++; | |
169 if ( CLIHistoryTail == CLIMaxHistorySize ) | |
170 { | 163 { |
171 CLIHistoryTail = 0; | 164 // Only do command-related stuff if there was actually a command |
172 CLIHistoryHead = 1; | 165 // Avoids clogging command history with blanks |
166 | |
167 // Process the current line buffer | |
168 CLI_commandLookup(); | |
169 | |
170 // Add the command to the history | |
171 CLI_saveHistory( CLILineBuffer ); | |
172 | |
173 // Keep the array circular, discarding the older entries | |
174 if ( CLIHistoryTail < CLIHistoryHead ) | |
175 CLIHistoryHead = ( CLIHistoryHead + 1 ) % CLIMaxHistorySize; | |
176 CLIHistoryTail++; | |
177 if ( CLIHistoryTail == CLIMaxHistorySize ) | |
178 { | |
179 CLIHistoryTail = 0; | |
180 CLIHistoryHead = 1; | |
181 } | |
182 | |
183 CLIHistoryCurrent = CLIHistoryTail; // 'Up' starts at the last item | |
184 CLI_saveHistory( NULL ); // delete the old temp buffer | |
185 | |
173 } | 186 } |
174 | |
175 CLIHistoryCurrent = CLIHistoryTail; // 'Up' starts at the last item | |
176 CLI_saveHistory( NULL ); // delete the old temp buffer | |
177 | 187 |
178 // Reset the buffer | 188 // Reset the buffer |
179 CLILineBufferCurrent = 0; | 189 CLILineBufferCurrent = 0; |
180 | 190 |
181 // Reset the prompt after processing has finished | 191 // Reset the prompt after processing has finished |
197 return; | 207 return; |
198 | 208 |
199 case 0x1B: // Esc / Escape codes | 209 case 0x1B: // Esc / Escape codes |
200 // Check for other escape sequence | 210 // Check for other escape sequence |
201 | 211 |
202 // \e[ is an escape code in vt100 compatable terminals | 212 // \e[ is an escape code in vt100 compatible terminals |
203 if ( CLILineBufferCurrent >= prev_buf_pos + 3 | 213 if ( CLILineBufferCurrent >= prev_buf_pos + 3 |
204 && CLILineBuffer[ prev_buf_pos ] == 0x1B | 214 && CLILineBuffer[ prev_buf_pos ] == 0x1B |
205 && CLILineBuffer[ prev_buf_pos + 1] == 0x5B ) | 215 && CLILineBuffer[ prev_buf_pos + 1] == 0x5B ) |
206 { | 216 { |
207 // Arrow Keys: A (0x41) = Up, B (0x42) = Down, C (0x43) = Right, D (0x44) = Left | 217 // Arrow Keys: A (0x41) = Up, B (0x42) = Down, C (0x43) = Right, D (0x44) = Left |