Reputation: 5505
I have a console application I would like to react to changes in terminal size. In Linux/UNIX this is done through the SIGWITCH signal:
SIGWINCH 28 Window change. The WINCH signal is sent to a process when its controlling terminal changes size, for instance if you resize it in your window manager. 4.3 BSD, Sun Source: https://www.computerhope.com/unix/signals.htm
In the Java SE documentation I can find information relative to most common signals, but there is no reference to SIGWINCH. Source: https://docs.oracle.com/javase/10/troubleshoot/handle-signals-and-exceptions.htm
Is it possible to capture such signal?
Upvotes: 2
Views: 238
Reputation: 306
Yes.
Use sun.misc.Signal
and the static handle
function:
jshell> import sun.misc.Signal;
jshell> Signal.handle(new Signal("WINCH"), s -> System.out.println(s.getName() + "(" + s.getNumber() + ")"));
If you resize the window, you'll see this handler being called.
Note that this is JVM specific, this was tested on openjdk 16.0.1
.
Upvotes: 1