From 8d6bf5f03357cf4bf219c7e4d9337cadebc2a019 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 25 Apr 2024 15:48:49 +0200 Subject: [PATCH] Fix terminal usage in mvnd (#1486) mvnd needs to set its own terminal, so we need to open the door for that --- .../org/apache/maven/jline/MessageUtils.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/maven-jline/src/main/java/org/apache/maven/jline/MessageUtils.java b/maven-jline/src/main/java/org/apache/maven/jline/MessageUtils.java index 878d773a75..164d4bee84 100644 --- a/maven-jline/src/main/java/org/apache/maven/jline/MessageUtils.java +++ b/maven-jline/src/main/java/org/apache/maven/jline/MessageUtils.java @@ -18,8 +18,6 @@ */ package org.apache.maven.jline; -import java.io.PrintStream; - import org.apache.maven.api.services.MessageBuilder; import org.apache.maven.api.services.MessageBuilderFactory; import org.jline.jansi.AnsiConsole; @@ -37,18 +35,24 @@ public class MessageUtils { static Thread shutdownHook; static final Object STARTUP_SHUTDOWN_MONITOR = new Object(); - static PrintStream prevOut; - static PrintStream prevErr; + public static void systemInstall(Terminal terminal) { + MessageUtils.terminal = terminal; + MessageUtils.reader = createReader(terminal); + } public static void systemInstall() { - terminal = new FastTerminal( - () -> TerminalBuilder.builder().name("Maven").dumb(true).build(), t -> { - reader = LineReaderBuilder.builder().terminal(t).build(); - AnsiConsole.setTerminal(t); + MessageUtils.terminal = new FastTerminal( + () -> TerminalBuilder.builder().name("Maven").dumb(true).build(), terminal -> { + MessageUtils.reader = createReader(terminal); + AnsiConsole.setTerminal(terminal); AnsiConsole.systemInstall(); }); } + private static LineReader createReader(Terminal terminal) { + return LineReaderBuilder.builder().terminal(terminal).build(); + } + public static void registerShutdownHook() { if (shutdownHook == null) { shutdownHook = new Thread(() -> {