From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adNfs-00044W-Gu for qemu-devel@nongnu.org; Tue, 08 Mar 2016 14:52:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adNfq-0000mB-Is for qemu-devel@nongnu.org; Tue, 08 Mar 2016 14:52:08 -0500 Received: from mail-pa0-x244.google.com ([2607:f8b0:400e:c03::244]:33951) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adNfq-0000m0-B7 for qemu-devel@nongnu.org; Tue, 08 Mar 2016 14:52:06 -0500 Received: by mail-pa0-x244.google.com with SMTP id hj7so1778373pac.1 for ; Tue, 08 Mar 2016 11:52:06 -0800 (PST) From: Ren Kimura Date: Wed, 9 Mar 2016 04:51:21 +0900 Message-Id: <1457466681-7714-2-git-send-email-rkx1209dev@gmail.com> In-Reply-To: <1457466681-7714-1-git-send-email-rkx1209dev@gmail.com> References: <1457466681-7714-1-git-send-email-rkx1209dev@gmail.com> Subject: [Qemu-devel] [PATCH v3 1/1] ui/console: add escape sequence \e[5, 6n List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kraxel@redhat.com Cc: qemu-devel@nongnu.org Add support of escape sequence "\e[5n" and "\e[6n" to console. "\e[5n" reports status of console and it always succeed in virtual console. "\e[6n" reports now cursor position in console. Signed-off-by: Ren Kimura --- ui/console.c | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/ui/console.c b/ui/console.c index ae61382..8027ba7 100644 --- a/ui/console.c +++ b/ui/console.c @@ -757,6 +757,31 @@ static void console_clear_xy(QemuConsole *s, int x, int y) update_xy(s, x, y); } +static void console_put_one(QemuConsole *s, int ch) +{ + TextCell *c; + int y1; + if (s->x >= s->width) { + /* line wrap */ + s->x = 0; + console_put_lf(s); + } + y1 = (s->y_base + s->y) % s->total_height; + c = &s->cells[y1 * s->width + s->x]; + c->ch = ch; + c->t_attrib = s->t_attrib; + update_xy(s, s->x, s->y); + s->x++; +} + +static void console_respond_str(QemuConsole *s, const char *buf) +{ + while (*buf) { + console_put_one(s, *buf); + buf++; + } +} + /* set cursor, checking bounds */ static void set_cursor(QemuConsole *s, int x, int y) { @@ -779,9 +804,9 @@ static void set_cursor(QemuConsole *s, int x, int y) static void console_putchar(QemuConsole *s, int ch) { - TextCell *c; - int y1, i; + int i; int x, y; + char response[40]; switch(s->state) { case TTY_STATE_NORM: @@ -817,17 +842,7 @@ static void console_putchar(QemuConsole *s, int ch) s->state = TTY_STATE_ESC; break; default: - if (s->x >= s->width) { - /* line wrap */ - s->x = 0; - console_put_lf(s); - } - y1 = (s->y_base + s->y) % s->total_height; - c = &s->cells[y1 * s->width + s->x]; - c->ch = ch; - c->t_attrib = s->t_attrib; - update_xy(s, s->x, s->y); - s->x++; + console_put_one(s, ch); break; } break; @@ -956,8 +971,19 @@ static void console_putchar(QemuConsole *s, int ch) console_handle_escape(s); break; case 'n': - /* report cursor position */ - /* TODO: send ESC[row;colR */ + switch (s->esc_params[0]) { + case 5: + /* report console status (always succeed)*/ + console_respond_str(s, "\033[0n"); + break; + case 6: + /* report cursor position */ + sprintf(response, "\033[%d;%dR", + (s->y_base + s->y) % s->total_height + 1, + s->x + 1); + console_respond_str(s, response); + break; + } break; case 's': /* save cursor position */ -- 2.5.0