From cc021a55abd172bf81fe8f0dd51329341c21c293 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 8 Mar 2023 16:39:28 +0100 Subject: [PATCH] Fix signal processing on windows, fixes #822 --- .../java/org/jline/demo/TerminalDemo.java | 40 +++++++++++++++++++ .../impl/AbstractWindowsTerminal.java | 5 ++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 demo/src/main/java/org/jline/demo/TerminalDemo.java diff --git a/demo/src/main/java/org/jline/demo/TerminalDemo.java b/demo/src/main/java/org/jline/demo/TerminalDemo.java new file mode 100644 index 000000000..1af57394e --- /dev/null +++ b/demo/src/main/java/org/jline/demo/TerminalDemo.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, the original author or authors. + * + * This software is distributable under the BSD license. See the terms of the + * BSD license in the documentation provided with this software. + * + * https://opensource.org/licenses/BSD-3-Clause + */ +package org.jline.demo; + +import org.jline.terminal.Terminal; +import org.jline.terminal.TerminalBuilder; + +public class TerminalDemo { + + public static void main(String[] args) throws Exception { + try (Terminal terminal = TerminalBuilder.terminal() ) + { + terminal.enterRawMode(); + + terminal.writer().println("Terminal: " + terminal); + terminal.writer().println("Type characters, which will be echoed to the terminal. Q will also exit this example."); + terminal.writer().println(); + terminal.writer().flush(); + + while (true) { + int c = terminal.reader().read(16); + if (c >= 0) { + terminal.writer().write(c); + terminal.writer().flush(); + + // Use "q" to quit early + if (c == 81 || c == 113) break; + } else { + if (c == -1) break; // Got EOF + } + } + } + } +} diff --git a/terminal/src/main/java/org/jline/terminal/impl/AbstractWindowsTerminal.java b/terminal/src/main/java/org/jline/terminal/impl/AbstractWindowsTerminal.java index 39c309f88..ee5bd2f10 100644 --- a/terminal/src/main/java/org/jline/terminal/impl/AbstractWindowsTerminal.java +++ b/terminal/src/main/java/org/jline/terminal/impl/AbstractWindowsTerminal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2019, the original author or authors. + * Copyright (c) 2002-2023, the original author or authors. * * This software is distributable under the BSD license. See the terms of the * BSD license in the documentation provided with this software. @@ -170,6 +170,9 @@ public void setAttributes(Attributes attr) { protected void updateConsoleMode() { int mode = ENABLE_WINDOW_INPUT; + if (attributes.getLocalFlag(Attributes.LocalFlag.ISIG)) { + mode |= ENABLE_PROCESSED_INPUT; + } if (attributes.getLocalFlag(Attributes.LocalFlag.ECHO)) { mode |= ENABLE_ECHO_INPUT; }