diff --git a/core/devmode-spi/src/main/java/io/quarkus/dev/console/BasicConsole.java b/core/devmode-spi/src/main/java/io/quarkus/dev/console/BasicConsole.java index f125065d0bccd..211e9aabc6ea0 100644 --- a/core/devmode-spi/src/main/java/io/quarkus/dev/console/BasicConsole.java +++ b/core/devmode-spi/src/main/java/io/quarkus/dev/console/BasicConsole.java @@ -29,7 +29,7 @@ protected Boolean initialValue() { public BasicConsole(boolean color, boolean inputSupport, PrintStream printStream, Console console) { this(color, inputSupport, (s) -> { - if (console != null) { + if (TerminalUtils.isTerminal(console)) { console.writer().print(s); console.writer().flush(); } else { diff --git a/core/devmode-spi/src/main/java/io/quarkus/dev/console/QuarkusConsole.java b/core/devmode-spi/src/main/java/io/quarkus/dev/console/QuarkusConsole.java index c78f741202b86..a659d4324287b 100644 --- a/core/devmode-spi/src/main/java/io/quarkus/dev/console/QuarkusConsole.java +++ b/core/devmode-spi/src/main/java/io/quarkus/dev/console/QuarkusConsole.java @@ -120,7 +120,7 @@ public static boolean hasColorSupport() { } else { // on sane operating systems having a console is a good indicator // you are attached to a TTY with colors. - return System.console() != null; + return TerminalUtils.isTerminal(System.console()); } } diff --git a/core/devmode-spi/src/main/java/io/quarkus/dev/console/TerminalUtils.java b/core/devmode-spi/src/main/java/io/quarkus/dev/console/TerminalUtils.java new file mode 100644 index 0000000000000..132b6ff13ac61 --- /dev/null +++ b/core/devmode-spi/src/main/java/io/quarkus/dev/console/TerminalUtils.java @@ -0,0 +1,27 @@ +package io.quarkus.dev.console; + +import java.io.Console; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class TerminalUtils { + + private static final Logger LOGGER = Logger.getLogger(TerminalUtils.class.getName()); + + public static boolean isTerminal(Console console) { + if (console == null) { + return false; + } + + if (Runtime.version().feature() < 22) { // isTerminal was introduced in Java 22 + return true; + } + + try { + return (boolean) Console.class.getMethod("isTerminal").invoke(console); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "Failed to invoke System.console().isTerminal() via Reflection API", e); + return false; + } + } +}