Fix local echo in line mode

This commit is contained in:
Martin Lund 2024-04-17 16:16:01 +02:00
parent 1e20948d83
commit a605533213

View file

@ -1866,36 +1866,41 @@ int tty_connect(void)
case '\b': case '\b':
case 127: // Backspace case 127: // Backspace
if (line_index) if (line_index)
{
if ((option.output_mode == OUTPUT_MODE_HEX) && (option.local_echo))
{
printf("\b\b\b \b\b\b"); // Destructive backspace
}
else
{ {
printf("\b \b"); // Destructive backspace printf("\b \b"); // Destructive backspace
}
line_index--; line_index--;
} }
forward = false; forward = false;
break; break;
case 13: // Carriage return case '\r': // Carriage return
// Write buffered line to tty device if (option.local_echo == false)
tty_write(device_fd, line_buffer, line_index); {
tty_write(device_fd, "\r", 1); // Delete line
optional_local_echo('\r'); int i = line_index;
tty_sync(device_fd); while (i--)
{
printf("\b \b"); // Destructive backspace
}
}
else
{
// Preserve line, go to next line
putchar('\r'); putchar('\r');
putchar('\n'); putchar('\n');
}
// Write buffered line to tty device
tty_write(device_fd, line_buffer, line_index);
tty_sync(device_fd);
line_index = 0; line_index = 0;
forward = false;
break; break;
default: default:
if (line_index < BUFSIZ) if (line_index < BUFSIZ)
{ {
optional_local_echo(input_char); putchar(input_char);
print_tainted_set();
line_buffer[line_index++] = input_char; line_buffer[line_index++] = input_char;
} }
else else
@ -1908,7 +1913,6 @@ int tty_connect(void)
// Save 2 latest stdin input characters // Save 2 latest stdin input characters
previous_char[1] = previous_char[0]; previous_char[1] = previous_char[0];
previous_char[0] = input_char; previous_char[0] = input_char;
break; break;
default: default: