Skip to contentSkip to conversation

chardev/char-win-stdio: Support VT sequences on Windows 11 host

PATCH In review Zhang Huasen 2 participants 5 messages Jun 15, 2023 – Jun 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chardev/char-win-stdio: Support VT sequences on Windows 11 host

If the monitor or the serial port use STDIO as backend on Windows 11 host, e.g. -nographic options is used, the monitor or the guest Linux do not response to arrow keys.

When Windows creates a console, ENABLE_VIRTUAL_PROCESS_INPUT is disabled by default. Arrow keys cannot be retrieved by ReadFile or ReadConsoleInput functions.

Add ENABLE_VIRTUAL_PROCESS_INPUT to the flag which is passed to SetConsoleMode, when opening stdio console.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1674

---
 chardev/char-win-stdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-win-stdio.c +1 -1
index eb830eabd9..1a18999e78 100644
@@ -190,7 +190,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
         }
     }
 
-    dwMode |= ENABLE_LINE_INPUT;
+    dwMode |= ENABLE_LINE_INPUT | ENABLE_VIRTUAL_TERMINAL_INPUT;
 
     if (is_console) {
         /* set the terminal in raw mode */
Signature · 1 line
2.41.0.windows.1
#1 lore raw

Hi

Quoted 24 lines · Zhang Huasen

If the monitor or the serial port use STDIO as backend on Windows 11 host, e.g. -nographic options is used, the monitor or the guest Linux do not response to arrow keys.

When Windows creates a console, ENABLE_VIRTUAL_PROCESS_INPUT is disabled by default. Arrow keys cannot be retrieved by ReadFile or ReadConsoleInput functions.

Add ENABLE_VIRTUAL_PROCESS_INPUT to the flag which is passed to SetConsoleMode,
when opening stdio console.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1674

---
 chardev/char-win-stdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-win-stdio.c +0 -0
index eb830eabd9..1a18999e78 100644

chardev/char-win-stdio.c static void qemu_chr_open_stdio(Chardev *chr, · line 194

Quoted 6 lines
chardev/char-win-stdio.c +1 -1
@@ -190,7 +190,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
         }
     }
 
-    dwMode |= ENABLE_LINE_INPUT;
+    dwMode |= ENABLE_LINE_INPUT | ENABLE_VIRTUAL_TERMINAL_INPUT;
 

I think we should set it only when is_console (although that may not make a difference otherwise)

thanks

Quoted 6 lines
chardev/char-win-stdio.c +0 -1
     if (is_console) {
         /* set the terminal in raw mode */
--

2.41.0.windows.1

#2 lore raw

From: Huasen Zhang <[email protected]>

Hello,

Quoted 32 lines · On Thu, 15 Jun 2023 12:57:55 +0200 Marc-André Lureau…

Hi

Quoted 27 lines · Zhang Huasen

If the monitor or the serial port use STDIO as backend on Windows 11 host, e.g. -nographic options is used, the monitor or the guest Linux do not response to arrow keys.

When Windows creates a console, ENABLE_VIRTUAL_PROCESS_INPUT is disabled by default. Arrow keys cannot be retrieved by ReadFile or ReadConsoleInput functions.

Add ENABLE_VIRTUAL_PROCESS_INPUT to the flag which is passed to SetConsoleMode,
when opening stdio console.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1674

---
 chardev/char-win-stdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-win-stdio.c +0 -0
index eb830eabd9..1a18999e78 100644
@@ -190,7 +190,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
         }
     }
 
Quoted 6 lines

chardev/char-win-stdio.c static void qemu_chr_open_stdio(Chardev *chr, · line 194

Quoted 3 lines
chardev/char-win-stdio.c +1 -1
-    dwMode |= ENABLE_LINE_INPUT;
+    dwMode |= ENABLE_LINE_INPUT | ENABLE_VIRTUAL_TERMINAL_INPUT;
 

I think we should set it only when is_console (although that may not make a difference otherwise)

It is okay to set ENABLE_VIRTUAL_TERMINAL_INPUT only when is_console is TRUE.

I do not understand some points of original code.
If the stdin is not a console, i.e. GetConsoleMode fails, we still call SetConsoleMode and set ENABLE_LINE_INPUT.
Could you please tell what the purpose is?

Quoted 9 lines

thanks

Quoted 6 lines
chardev/char-win-stdio.c +0 -1
     if (is_console) {
         /* set the terminal in raw mode */
--

2.41.0.windows.1

#3 lore raw

Hi

Quoted 50 lines · Zhang Huasen

From: Huasen Zhang <[email protected]>

Hello,

Quoted 6 lines · On Thu, 15 Jun 2023 12:57:55 +0200 Marc-André Lureau <…

Hi

Quoted 1 line · Zhang Huasen

If the monitor or the serial port use STDIO as backend on Windows 11

host,

Quoted 4 lines
Quoted 4 lines

e.g. -nographic options is used, the monitor or the guest Linux do not response to arrow keys.

When Windows creates a console, ENABLE_VIRTUAL_PROCESS_INPUT is

disabled

Quoted 1 line
Quoted 1 line

by default. Arrow keys cannot be retrieved by ReadFile or

ReadConsoleInput

Quoted 21 lines
Quoted 21 lines

functions.

Add ENABLE_VIRTUAL_PROCESS_INPUT to the flag which is passed to SetConsoleMode,
when opening stdio console.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1674

---
 chardev/char-win-stdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-win-stdio.c +0 -0
index eb830eabd9..1a18999e78 100644
@@ -190,7 +190,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
         }
     }
 
Quoted 5 lines

chardev/char-win-stdio.c static void qemu_chr_open_stdio(Chardev *chr, · line 194

Quoted 3 lines
chardev/char-win-stdio.c +1 -1
-    dwMode |= ENABLE_LINE_INPUT;
+    dwMode |= ENABLE_LINE_INPUT | ENABLE_VIRTUAL_TERMINAL_INPUT;
 

I think we should set it only when is_console (although that may not

make a

Quoted 1 line

difference otherwise)

Quoted 8 lines

It is okay to set ENABLE_VIRTUAL_TERMINAL_INPUT only when is_console is TRUE.

I do not understand some points of original code.
If the stdin is not a console, i.e. GetConsoleMode fails, we still call SetConsoleMode and set ENABLE_LINE_INPUT.
Could you please tell what the purpose is?

I have no clue. It has been this way since the beginning (commit db418a0a7).

The code doesn't check SetConsoleMode() return value, so I'd just go with your patch for now.

#4 lore raw

From: Huasen Zhang <[email protected]>

Hello,

On Sat, 17 Jun 2023 11:42:06 +0200 Marc-André Lureau < [email protected]> wrote:
Hi

Quoted 62 lines
Quoted 50 lines · Zhang Huasen

From: Huasen Zhang <[email protected]>

Hello,

Quoted 35 lines · On Thu, 15 Jun 2023 12:57:55 +0200 Marc-André Lureau <…

Hi

Quoted 30 lines · Zhang Huasen

If the monitor or the serial port use STDIO as backend on Windows 11 host,
e.g. -nographic options is used, the monitor or the guest Linux do not response to arrow keys.

When Windows creates a console, ENABLE_VIRTUAL_PROCESS_INPUT is disabled
by default. Arrow keys cannot be retrieved by ReadFile or ReadConsoleInput
functions.

Add ENABLE_VIRTUAL_PROCESS_INPUT to the flag which is passed to SetConsoleMode,
when opening stdio console.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1674

---
 chardev/char-win-stdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
chardev/char-win-stdio.c +0 -0
index eb830eabd9..1a18999e78 100644
@@ -190,7 +190,7 @@ static void qemu_chr_open_stdio(Chardev *chr,
         }
     }
 
Quoted 7 lines

chardev/char-win-stdio.c static void qemu_chr_open_stdio(Chardev *chr, · line 194

Quoted 3 lines
chardev/char-win-stdio.c +1 -1
-    dwMode |= ENABLE_LINE_INPUT;
+    dwMode |= ENABLE_LINE_INPUT | ENABLE_VIRTUAL_TERMINAL_INPUT;
 

I think we should set it only when is_console (although that may not make a
difference otherwise)

Quoted 8 lines

It is okay to set ENABLE_VIRTUAL_TERMINAL_INPUT only when is_console is TRUE.

I do not understand some points of original code.
If the stdin is not a console, i.e. GetConsoleMode fails, we still call SetConsoleMode and set ENABLE_LINE_INPUT.
Could you please tell what the purpose is?

Quoted 4 lines

I have no clue. It has been this way since the beginning (commit db418a0a7).

The code doesn't check SetConsoleMode() return value, so I'd just go with your patch for now.

Thanks for your review and comments.