mirror of
https://github.com/systemd/systemd.git
synced 2025-01-03 05:18:09 +03:00
ptyfwd: save the last character before the escape sequence
If we write e.g. a line break and CSI sequence, then it is not necessary to write another line break on exit.
This commit is contained in:
parent
5e6a48bf99
commit
d517427dff
@ -85,6 +85,7 @@ struct PTYForward {
|
||||
|
||||
bool last_char_set:1;
|
||||
char last_char;
|
||||
char last_char_safe;
|
||||
|
||||
char in_buffer[LINE_MAX], *out_buffer;
|
||||
size_t out_buffer_size;
|
||||
@ -439,8 +440,11 @@ static int pty_forward_ansi_process(PTYForward *f, size_t offset) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
i += r;
|
||||
f->last_char_safe = c;
|
||||
} else if (c == 0x1B) /* ESC */
|
||||
f->ansi_color_state = ANSI_COLOR_STATE_ESC;
|
||||
else if (!char_is_cc(c))
|
||||
f->last_char_safe = c;
|
||||
break;
|
||||
|
||||
case ANSI_COLOR_STATE_ESC:
|
||||
@ -705,8 +709,15 @@ static int do_shovel(PTYForward *f) {
|
||||
|
||||
} else {
|
||||
|
||||
if (k > 0) {
|
||||
if (k > 0 && f->last_char_safe != '\0') {
|
||||
if ((size_t) k == f->out_buffer_write_len)
|
||||
/* If we wrote all, then save the last safe character. */
|
||||
f->last_char = f->last_char_safe;
|
||||
else
|
||||
/* If we wrote partially, then tentatively save the last written character.
|
||||
* Hopefully, we will write more in the next loop. */
|
||||
f->last_char = f->out_buffer[k-1];
|
||||
|
||||
f->last_char_set = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user