Mercurial > louis > kiibohd-controller
changeset 329:f6b7c1f0f8a1
Merge pull request #48 from mattventura/master
Avoid putting blank entries in history, allow linefeed for enter
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Fri, 12 Jun 2015 18:33:23 -0700 |
parents | f7b14e25ca5b (current diff) 9dd55aa71d76 (diff) |
children | f4d4cad283c6 |
files | |
diffstat | 1 files changed, 27 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Debug/cli/cli.c Fri Jun 12 18:31:55 2015 -0700 +++ b/Debug/cli/cli.c Fri Jun 12 18:33:23 2015 -0700 @@ -149,32 +149,42 @@ // Check for control characters switch ( CLILineBuffer[prev_buf_pos] ) { - case 0x0D: // Enter + // Enter + case 0x0A: // LF + case 0x0D: // CR CLILineBuffer[CLILineBufferCurrent - 1] = ' '; // Replace Enter with a space (resolves a bug in args) // Remove the space if there is no command if ( CLILineBufferCurrent == 1 ) + { CLILineBufferCurrent--; + } + else + { + // Only do command-related stuff if there was actually a command + // Avoids clogging command history with blanks - // Process the current line buffer - CLI_commandLookup(); + // Process the current line buffer + CLI_commandLookup(); - // Add the command to the history - CLI_saveHistory( CLILineBuffer ); + // Add the command to the history + CLI_saveHistory( CLILineBuffer ); - // Keep the array circular, discarding the older entries - if ( CLIHistoryTail < CLIHistoryHead ) - CLIHistoryHead = ( CLIHistoryHead + 1 ) % CLIMaxHistorySize; - CLIHistoryTail++; - if ( CLIHistoryTail == CLIMaxHistorySize ) - { - CLIHistoryTail = 0; - CLIHistoryHead = 1; + // Keep the array circular, discarding the older entries + if ( CLIHistoryTail < CLIHistoryHead ) + CLIHistoryHead = ( CLIHistoryHead + 1 ) % CLIMaxHistorySize; + CLIHistoryTail++; + if ( CLIHistoryTail == CLIMaxHistorySize ) + { + CLIHistoryTail = 0; + CLIHistoryHead = 1; + } + + CLIHistoryCurrent = CLIHistoryTail; // 'Up' starts at the last item + CLI_saveHistory( NULL ); // delete the old temp buffer + } - CLIHistoryCurrent = CLIHistoryTail; // 'Up' starts at the last item - CLI_saveHistory( NULL ); // delete the old temp buffer - // Reset the buffer CLILineBufferCurrent = 0; @@ -199,7 +209,7 @@ case 0x1B: // Esc / Escape codes // Check for other escape sequence - // \e[ is an escape code in vt100 compatable terminals + // \e[ is an escape code in vt100 compatible terminals if ( CLILineBufferCurrent >= prev_buf_pos + 3 && CLILineBuffer[ prev_buf_pos ] == 0x1B && CLILineBuffer[ prev_buf_pos + 1] == 0x5B )