posix main shell: do not update the prompt for unprintable chars (#8704)

This commit is contained in:
Beat Küng
2018-01-16 23:45:28 -05:00
committed by Daniel Agar
parent 0e65753568
commit 094fa92de0
+7 -2
View File
@@ -502,7 +502,6 @@ int main(int argc, char **argv)
if (!daemon_mode) { if (!daemon_mode) {
string mystr; string mystr;
string add_string;
string string_buffer[CMD_BUFF_SIZE]; string string_buffer[CMD_BUFF_SIZE];
int buf_ptr_write = 0; int buf_ptr_write = 0;
int buf_ptr_read = 0; int buf_ptr_read = 0;
@@ -522,7 +521,8 @@ int main(int argc, char **argv)
while (!_ExitFlag) { while (!_ExitFlag) {
char c = getchar(); char c = getchar();
add_string = ""; // reset string to add string add_string; // string to add at current cursor position
bool update_prompt = true;
switch (c) { switch (c) {
case 127: // backslash case 127: // backslash
@@ -622,11 +622,15 @@ int main(int argc, char **argv)
default: // any other input default: // any other input
if (c > 3) { if (c > 3) {
add_string += c; add_string += c;
} else {
update_prompt = false;
} }
break; break;
} }
if (update_prompt) {
// reprint prompt with mystr // reprint prompt with mystr
mystr.insert(mystr.length() - cursor_position, add_string); mystr.insert(mystr.length() - cursor_position, add_string);
printf("%c[2K", 27); printf("%c[2K", 27);
@@ -638,6 +642,7 @@ int main(int argc, char **argv)
if (cursor_position > 0) { if (cursor_position > 0) {
printf("\033[%dD", cursor_position); printf("\033[%dD", cursor_position);
} }
}
} }