reverted cli line editing stuff - was more trouble than its worth, and caused issues with hercules

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@358 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop@gmail.com 2013-06-29 15:48:43 +00:00
parent d442c9dfb6
commit e4ea700fe0
2 changed files with 3075 additions and 3155 deletions

File diff suppressed because it is too large Load Diff

View File

@ -915,35 +915,6 @@ void cliProcess(void)
while (isUartAvailable()) { while (isUartAvailable()) {
uint8_t c = uartRead(); uint8_t c = uartRead();
/* first step: translate "ESC[" -> "CSI" */
if (c == '\033') {
c = uartReadPoll();
if (c == '[')
c = 0x9b;
else
/* ignore unknown sequences */
c = 0;
}
/* second step: translate known CSI sequence into singlebyte control sequences */
if (c == 0x9b) {
c = uartReadPoll();
if (c == 'A') //up
c = 0x0b;
else if (c == 'B') //down
c = 0x0a;
else if (c == 'C') //right
c = 0x0c;
else if (c == 'D') //left
c = 0x08;
else if (c == 0x33 && uartReadPoll() == 0x7e) //delete
c = 0xff; // nonstandard, borrowing 0xff for the delete key
else
c = 0;
}
/* from here on everything is a single byte */
if (c == '\t' || c == '?') { if (c == '\t' || c == '?') {
// do tab completion // do tab completion
const clicmd_t *cmd, *pstart = NULL, *pend = NULL; const clicmd_t *cmd, *pstart = NULL, *pend = NULL;
@ -983,37 +954,16 @@ void cliProcess(void)
} else if (!bufferIndex && c == 4) { } else if (!bufferIndex && c == 4) {
cliExit(cliBuffer); cliExit(cliBuffer);
return; return;
} else if (c == 0x15) {
// ctrl+u == delete line
uartPrint("\033[G\033[K# ");
bufferIndex = 0;
*cliBuffer = '\0';
} else if (c == 0x0b) {
//uartPrint("up unimplemented");
} else if (c == 0x0a) {
//uartPrint("down unimplemend");
} else if (c == 0x08) {
if (bufferIndex > 0) {
bufferIndex--;
uartPrint("\033[D");
}
} else if (c == 12) { } else if (c == 12) {
if (cliBuffer[bufferIndex]) { // clear screen
bufferIndex++; uartPrint("\033[2J\033[1;1H");
uartPrint("\033[C"); cliPrompt();
} } else if (bufferIndex && (c == '\n' || c == '\r')) {
} else if (c == 0xff) {
// delete key
if (cliBuffer[bufferIndex]) {
int len = strlen(cliBuffer + bufferIndex);
memmove(cliBuffer + bufferIndex, cliBuffer + bufferIndex + 1, len + 1);
printf("%s \033[%dD", cliBuffer + bufferIndex, len);
}
} else if (*cliBuffer && (c == '\n' || c == '\r')) {
// enter pressed // enter pressed
clicmd_t *cmd = NULL; clicmd_t *cmd = NULL;
clicmd_t target; clicmd_t target;
uartPrint("\r\n"); uartPrint("\r\n");
cliBuffer[bufferIndex] = 0; // null terminate
target.name = cliBuffer; target.name = cliBuffer;
target.param = NULL; target.param = NULL;
@ -1033,25 +983,15 @@ void cliProcess(void)
cliPrompt(); cliPrompt();
} else if (c == 127) { } else if (c == 127) {
// backspace // backspace
if (bufferIndex && *cliBuffer) { if (bufferIndex) {
int len = strlen(cliBuffer + bufferIndex); cliBuffer[--bufferIndex] = 0;
uartPrint("\010 \010");
--bufferIndex;
memmove(cliBuffer + bufferIndex, cliBuffer + bufferIndex + 1, len + 1);
printf("\033[D%s \033[%dD", cliBuffer + bufferIndex, len + 1);
} }
} else if (strlen(cliBuffer) + 1 < sizeof(cliBuffer) && c >= 32 && c <= 126) { } else if (bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126) {
int len;
if (!bufferIndex && c == 32) if (!bufferIndex && c == 32)
continue; continue;
cliBuffer[bufferIndex++] = c;
len = strlen(cliBuffer + bufferIndex); uartWrite(c);
memmove(cliBuffer + bufferIndex + 1, cliBuffer + bufferIndex, len + 1);
cliBuffer[bufferIndex] = c;
printf("%s \033[%dD", cliBuffer + bufferIndex, len + 1);
++bufferIndex;
} }
} }
} }