mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 05:33:33 +08:00
posix main shell: do not update the prompt for unprintable chars (#8704)
This commit is contained in:
@@ -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
|
||||||
@@ -533,7 +533,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case'\n': // user hit enter
|
case '\n': // user hit enter
|
||||||
if (buf_ptr_write == CMD_BUFF_SIZE) {
|
if (buf_ptr_write == CMD_BUFF_SIZE) {
|
||||||
buf_ptr_write = 0;
|
buf_ptr_write = 0;
|
||||||
}
|
}
|
||||||
@@ -622,21 +622,26 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reprint prompt with mystr
|
if (update_prompt) {
|
||||||
mystr.insert(mystr.length() - cursor_position, add_string);
|
// reprint prompt with mystr
|
||||||
printf("%c[2K", 27);
|
mystr.insert(mystr.length() - cursor_position, add_string);
|
||||||
cout << (char)13;
|
printf("%c[2K", 27);
|
||||||
print_prompt();
|
cout << (char)13;
|
||||||
cout << mystr;
|
print_prompt();
|
||||||
|
cout << mystr;
|
||||||
|
|
||||||
// Move the cursor to its position
|
// Move the cursor to its position
|
||||||
if (cursor_position > 0) {
|
if (cursor_position > 0) {
|
||||||
printf("\033[%dD", cursor_position);
|
printf("\033[%dD", cursor_position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user