From patchwork Tue May 29 12:29:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 161739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C1249B6FBD for ; Tue, 29 May 2012 22:29:41 +1000 (EST) Received: from localhost ([::1]:56848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZLYR-00023f-KI for incoming@patchwork.ozlabs.org; Tue, 29 May 2012 08:29:39 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZLYC-0001zd-08 for qemu-devel@nongnu.org; Tue, 29 May 2012 08:29:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZLY5-0000n1-5s for qemu-devel@nongnu.org; Tue, 29 May 2012 08:29:23 -0400 Received: from mail.ispras.ru ([83.149.199.43]:34864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZLY4-0000h1-P9 for qemu-devel@nongnu.org; Tue, 29 May 2012 08:29:17 -0400 Received: from PASHAISP (unknown [80.250.189.177]) by mail.ispras.ru (Postfix) with ESMTP id E313224FE71 for ; Tue, 29 May 2012 16:29:03 +0400 (MSK) From: "Pavel Dovgaluk" To: "'qemu-devel'" Date: Tue, 29 May 2012 16:29:03 +0400 Message-ID: <002f01cd3d96$a2378a30$e6a69e90$@Dovgaluk@ispras.ru> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac09lqHzq5NTPAs2QoC2U7UCQJ8j8Q== Content-Language: ru X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 83.149.199.43 Subject: [Qemu-devel] [PATCH] ANSI escape characters support for Windows console X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds support of ANSI escape characters used in readline module to impelementation of stdio character device for Windows. Signed-off-by: Pavel Dovgalyuk --- qemu-char.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 10 deletions(-) static void win_stdio_wait_func(void *opaque) @@ -1948,7 +1970,9 @@ static CharDriverState *qemu_chr_open_win_stdio(QemuOpts *opts) { CharDriverState *chr; WinStdioCharState *stdio; + HANDLE hStdOut; DWORD dwMode; + DWORD dwOutMode; int is_console = 0; if (stdio_nb_clients >= STDIO_MAX_CLIENTS @@ -1960,12 +1984,14 @@ static CharDriverState *qemu_chr_open_win_stdio(QemuOpts *opts) stdio = g_malloc0(sizeof(WinStdioCharState)); stdio->hStdIn = GetStdHandle(STD_INPUT_HANDLE); - if (stdio->hStdIn == INVALID_HANDLE_VALUE) { + if (stdio->hStdIn == INVALID_HANDLE_VALUE + || hStdOut == INVALID_HANDLE_VALUE) { fprintf(stderr, "cannot open stdio: invalid handle\n"); exit(1); } is_console = GetConsoleMode(stdio->hStdIn, &dwMode) != 0; + GetConsoleMode(hStdOut, &dwOutMode); chr->opaque = stdio; chr->chr_write = win_stdio_write; @@ -2005,9 +2031,11 @@ static CharDriverState *qemu_chr_open_win_stdio(QemuOpts *opts) /* set the terminal in raw mode */ /* ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS */ dwMode |= ENABLE_PROCESSED_INPUT; + dwOutMode |= ENABLE_PROCESSED_OUTPUT; } SetConsoleMode(stdio->hStdIn, dwMode); + SetConsoleMode(hStdOut, dwOutMode); chr->chr_set_echo = qemu_chr_set_echo_win_stdio; qemu_chr_fe_set_echo(chr, false); diff --git a/qemu-char.c b/qemu-char.c index fe1126f..6035b79 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -1810,19 +1810,41 @@ static int win_stdio_write(CharDriverState *chr, const uint8_t *buf, int len) { HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); DWORD dwSize; - int len1; + int ret = 0; + CONSOLE_SCREEN_BUFFER_INFO info; - len1 = len; - - while (len1 > 0) { - if (!WriteFile(hStdOut, buf, len1, &dwSize, NULL)) { - break; + while (len > 0) { + if (len > 2 && buf[0] == '\033' && buf[1] == '[') { + switch (buf[2]) { + case 'D': + if (!WriteFile(hStdOut, "\b", 1, &dwSize, NULL)) { + return ret; + } + break; + case 'K': + if (!GetConsoleScreenBufferInfo(hStdOut, &info)) { + return ret; + } + if (!FillConsoleOutputCharacter(hStdOut, ' ', + info.dwSize.X - info.dwCursorPosition.X, + info.dwCursorPosition, &dwSize)) { + return ret; + } + break; + } + dwSize = 3; + } else { + if (!WriteFile(hStdOut, buf, 1, &dwSize, NULL)) { + return ret; + } } - buf += dwSize; - len1 -= dwSize; + + buf += dwSize; + len -= dwSize; + ret += dwSize; } - return len - len1; + return ret; }