mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 19:14:58 -06:00
ui/console-vc: add support for cursor DECSC and DECRC commands
There are aliases for save and restore cursor commands: * save cursor `ESC 7` (DEC Save Cursor [1], older VT100) `ESC [ s` (CSI Save Cursor, standard ANSI) * load cursor `ESC 8` (DEC Restore Cursor [2], older VT100) `ESC [ u` (CSI Restore Cursor, standard ANSI) This change introduces older DEC sequencies for compatibility with some scripts (for example [3]) and tools. This change also adds saving and restoring of character attributes, which is according to the VT spec [1][2] [1] https://vt100.net/docs/vt510-rm/DECSC.html [2] https://vt100.net/docs/vt510-rm/DECRC.html [3] https://wiki.archlinux.org/title/Working_with_the_serial_console#Resizing_a_terminal Signed-off-by: Roman Penyaev <r.peniaev@gmail.com> Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com> Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20250226075913.353676-5-r.peniaev@gmail.com>
This commit is contained in:
parent
40339871da
commit
1a0fd7838a
1 changed files with 34 additions and 6 deletions
|
@ -90,6 +90,7 @@ struct VCChardev {
|
||||||
int esc_params[MAX_ESC_PARAMS];
|
int esc_params[MAX_ESC_PARAMS];
|
||||||
int nb_esc_params;
|
int nb_esc_params;
|
||||||
TextAttributes t_attrib; /* currently active text attributes */
|
TextAttributes t_attrib; /* currently active text attributes */
|
||||||
|
TextAttributes t_attrib_saved;
|
||||||
int x_saved, y_saved;
|
int x_saved, y_saved;
|
||||||
};
|
};
|
||||||
typedef struct VCChardev VCChardev;
|
typedef struct VCChardev VCChardev;
|
||||||
|
@ -644,6 +645,31 @@ static void vc_set_cursor(VCChardev *vc, int x, int y)
|
||||||
s->y = y;
|
s->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vc_save_cursor() - saves cursor position and character attributes.
|
||||||
|
*/
|
||||||
|
static void vc_save_cursor(VCChardev *vc)
|
||||||
|
{
|
||||||
|
QemuTextConsole *s = vc->console;
|
||||||
|
|
||||||
|
vc->x_saved = s->x;
|
||||||
|
vc->y_saved = s->y;
|
||||||
|
vc->t_attrib_saved = vc->t_attrib;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vc_restore_cursor() - restores cursor position and character
|
||||||
|
* attributes from saved state.
|
||||||
|
*/
|
||||||
|
static void vc_restore_cursor(VCChardev *vc)
|
||||||
|
{
|
||||||
|
QemuTextConsole *s = vc->console;
|
||||||
|
|
||||||
|
s->x = vc->x_saved;
|
||||||
|
s->y = vc->y_saved;
|
||||||
|
vc->t_attrib = vc->t_attrib_saved;
|
||||||
|
}
|
||||||
|
|
||||||
static void vc_putchar(VCChardev *vc, int ch)
|
static void vc_putchar(VCChardev *vc, int ch)
|
||||||
{
|
{
|
||||||
QemuTextConsole *s = vc->console;
|
QemuTextConsole *s = vc->console;
|
||||||
|
@ -699,6 +725,12 @@ static void vc_putchar(VCChardev *vc, int ch)
|
||||||
vc->state = TTY_STATE_G0;
|
vc->state = TTY_STATE_G0;
|
||||||
} else if (ch == ')') {
|
} else if (ch == ')') {
|
||||||
vc->state = TTY_STATE_G1;
|
vc->state = TTY_STATE_G1;
|
||||||
|
} else if (ch == '7') {
|
||||||
|
vc_save_cursor(vc);
|
||||||
|
vc->state = TTY_STATE_NORM;
|
||||||
|
} else if (ch == '8') {
|
||||||
|
vc_restore_cursor(vc);
|
||||||
|
vc->state = TTY_STATE_NORM;
|
||||||
} else {
|
} else {
|
||||||
vc->state = TTY_STATE_NORM;
|
vc->state = TTY_STATE_NORM;
|
||||||
}
|
}
|
||||||
|
@ -833,14 +865,10 @@ static void vc_putchar(VCChardev *vc, int ch)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
/* save cursor position */
|
vc_save_cursor(vc);
|
||||||
vc->x_saved = s->x;
|
|
||||||
vc->y_saved = s->y;
|
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
/* restore cursor position */
|
vc_restore_cursor(vc);
|
||||||
s->x = vc->x_saved;
|
|
||||||
s->y = vc->y_saved;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
trace_console_putchar_unhandled(ch);
|
trace_console_putchar_unhandled(ch);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue