Fix terminal usage in mvnd (#1486)

mvnd needs to set its own terminal, so we need to open the door for that
This commit is contained in:
Guillaume Nodet 2024-04-25 15:48:49 +02:00 committed by GitHub
parent 854589b131
commit 8d6bf5f033
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 8 deletions

View File

@ -18,8 +18,6 @@
*/ */
package org.apache.maven.jline; package org.apache.maven.jline;
import java.io.PrintStream;
import org.apache.maven.api.services.MessageBuilder; import org.apache.maven.api.services.MessageBuilder;
import org.apache.maven.api.services.MessageBuilderFactory; import org.apache.maven.api.services.MessageBuilderFactory;
import org.jline.jansi.AnsiConsole; import org.jline.jansi.AnsiConsole;
@ -37,18 +35,24 @@ public class MessageUtils {
static Thread shutdownHook; static Thread shutdownHook;
static final Object STARTUP_SHUTDOWN_MONITOR = new Object(); static final Object STARTUP_SHUTDOWN_MONITOR = new Object();
static PrintStream prevOut; public static void systemInstall(Terminal terminal) {
static PrintStream prevErr; MessageUtils.terminal = terminal;
MessageUtils.reader = createReader(terminal);
}
public static void systemInstall() { public static void systemInstall() {
terminal = new FastTerminal( MessageUtils.terminal = new FastTerminal(
() -> TerminalBuilder.builder().name("Maven").dumb(true).build(), t -> { () -> TerminalBuilder.builder().name("Maven").dumb(true).build(), terminal -> {
reader = LineReaderBuilder.builder().terminal(t).build(); MessageUtils.reader = createReader(terminal);
AnsiConsole.setTerminal(t); AnsiConsole.setTerminal(terminal);
AnsiConsole.systemInstall(); AnsiConsole.systemInstall();
}); });
} }
private static LineReader createReader(Terminal terminal) {
return LineReaderBuilder.builder().terminal(terminal).build();
}
public static void registerShutdownHook() { public static void registerShutdownHook() {
if (shutdownHook == null) { if (shutdownHook == null) {
shutdownHook = new Thread(() -> { shutdownHook = new Thread(() -> {