+ case 0x1B: // Esc / Escape codes
+ // Check for other escape sequence
+
+ // \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 )
+ {
+ // Arrow Keys: A (0x41) = Up, B (0x42) = Down, C (0x43) = Right, D (0x44) = Left
+
+ if ( CLILineBuffer[ prev_buf_pos + 2 ] == 0x41 ) // Hist prev
+ {
+ if ( CLIHistoryCurrent == CLIHistoryTail )
+ {
+ // Is first time pressing arrow. Save the current buffer
+ CLILineBuffer[ prev_buf_pos ] = '\0';
+ CLI_saveHistory( CLILineBuffer );
+ }
+
+ // Grab the previus item from the history if there is one
+ if ( RING_PREV( CLIHistoryCurrent ) != RING_PREV( CLIHistoryHead ) )
+ CLIHistoryCurrent = RING_PREV( CLIHistoryCurrent );
+ CLI_retreiveHistory( CLIHistoryCurrent );
+ }
+ if ( CLILineBuffer[ prev_buf_pos + 2 ] == 0x42 ) // Hist next
+ {
+ // Grab the next item from the history if it exists
+ if ( RING_NEXT( CLIHistoryCurrent ) != RING_NEXT( CLIHistoryTail ) )
+ CLIHistoryCurrent = RING_NEXT( CLIHistoryCurrent );
+ CLI_retreiveHistory( CLIHistoryCurrent );
+ }
+ }