+inline int CLI_wrap( int kX, int const kLowerBound, int const kUpperBound )
+{
+ int range_size = kUpperBound - kLowerBound + 1;
+
+ if ( kX < kLowerBound )
+ kX += range_size * ((kLowerBound - kX) / range_size + 1);
+
+ return kLowerBound + (kX - kLowerBound) % range_size;
+}
+
+inline void CLI_saveHistory( char *buff )
+{
+ if ( buff == NULL )
+ {
+ //clear the item
+ CLIHistoryBuffer[ CLIHistoryTail ][ 0 ] = '\0';
+ return;
+ }
+
+ // Don't write empty lines to the history
+ const char *cursor = buff;
+ while (*cursor == ' ') { cursor++; } // advance past the leading whitespace
+ if (*cursor == '\0') { return ; }
+
+ // Copy the line to the history
+ int i;
+ for (i = 0; i < CLILineBufferCurrent; i++)
+ {
+ CLIHistoryBuffer[ CLIHistoryTail ][ i ] = CLILineBuffer[ i ];
+ }
+}
+
+void CLI_retreiveHistory( int index )
+{
+ char *histMatch = CLIHistoryBuffer[ index ];
+
+ // Reset the buffer
+ CLILineBufferCurrent = 0;
+
+ // Reprint the prompt (automatically clears the line)
+ prompt();
+
+ // Display the command
+ dPrint( histMatch );
+
+ // There are no index counts, so just copy the whole string to the input buffe
+ CLILineBufferCurrent = 0;
+ while ( *histMatch != '\0' )
+ {
+ CLILineBuffer[ CLILineBufferCurrent++ ] = *histMatch++;
+ }
+}
+