diff --git a/src/main/java/com/googlecode/lanterna/terminal/DefaultTerminalFactory.java b/src/main/java/com/googlecode/lanterna/terminal/DefaultTerminalFactory.java index 78fbe6e6c..bf71af845 100644 --- a/src/main/java/com/googlecode/lanterna/terminal/DefaultTerminalFactory.java +++ b/src/main/java/com/googlecode/lanterna/terminal/DefaultTerminalFactory.java @@ -110,16 +110,7 @@ public Terminal createTerminal() throws IOException { // ("because we can" - unless "rather not") if (forceTextTerminal || isAwtHeadless() || (System.console() != null && !preferTerminalEmulator) ) { - // if tty but have no tty, but do have a port, then go telnet: - if( telnetPort > 0 && System.console() == null) { - return createTelnetTerminal(); - } - if(isOperatingSystemWindows()) { - return createWindowsTerminal(); - } - else { - return createUnixTerminal(outputStream, inputStream, charset); - } + return createHeadlessTerminal(); } else { // while Lanterna's TerminalEmulator lacks mouse support: @@ -133,6 +124,25 @@ public Terminal createTerminal() throws IOException { } } + /** + * Instantiates a Terminal according to the factory implementation with the exception that + * {@link DefaultTerminalFactory#preferTerminalEmulator} is always ignored. You may want to use this method when + * using tools that rely on AOT compilation such as Graal native-image to ensure AWT/Swing code paths are not hit. + * @return Terminal implementation + * @throws IOException If there was an I/O error with the underlying input/output system + */ + public Terminal createHeadlessTerminal() throws IOException { + // if tty but have no tty, but do have a port, then go telnet: + if( telnetPort > 0 && System.console() == null) { + return createTelnetTerminal(); + } + if(isOperatingSystemWindows()) { + return createWindowsTerminal(); + } + + return createUnixTerminal(outputStream, inputStream, charset); + } + /** * Creates a new terminal emulator window which will be either Swing-based or AWT-based depending on what is * available on the system