Skip to content

Commit

Permalink
Fix signal processing on windows, fixes #822
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 8, 2023
1 parent 6fa8b78 commit cc021a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
40 changes: 40 additions & 0 deletions demo/src/main/java/org/jline/demo/TerminalDemo.java
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit cc021a5

Please sign in to comment.