You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 15:36:17 +00:00
fix(console): install jansi for forced ansi startup
This commit is contained in:
@@ -19,6 +19,7 @@ import com.eu.habbo.plugin.events.emulator.EmulatorStoppedEvent;
|
|||||||
import com.eu.habbo.threading.ThreadPooling;
|
import com.eu.habbo.threading.ThreadPooling;
|
||||||
import com.eu.habbo.util.imager.badges.BadgeImager;
|
import com.eu.habbo.util.imager.badges.BadgeImager;
|
||||||
import com.eu.habbo.util.logback.ConsoleStyle;
|
import com.eu.habbo.util.logback.ConsoleStyle;
|
||||||
|
import org.fusesource.jansi.AnsiConsole;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -110,14 +111,12 @@ public final class Emulator {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
try {
|
try {
|
||||||
if (OS_NAME.startsWith("Windows") && !CLASS_PATH.contains("idea_rt.jar")) {
|
boolean styledConsole = shouldStyleConsole(
|
||||||
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
System.getenv(),
|
||||||
ConsoleAppender<ILoggingEvent> appender = (ConsoleAppender<ILoggingEvent>) root.getAppender("Console");
|
System.console() != null,
|
||||||
|
OS_NAME,
|
||||||
appender.stop();
|
System.getProperty("habbo.console.style", "auto"));
|
||||||
appender.setWithJansi(true);
|
configureAnsiConsole(styledConsole);
|
||||||
appender.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
Locale.setDefault(Locale.of("en"));
|
Locale.setDefault(Locale.of("en"));
|
||||||
setBuild();
|
setBuild();
|
||||||
@@ -125,11 +124,7 @@ public final class Emulator {
|
|||||||
ConsoleCommand.load();
|
ConsoleCommand.load();
|
||||||
Emulator.logging = new Logging();
|
Emulator.logging = new Logging();
|
||||||
|
|
||||||
System.out.println(startupHero(shouldStyleConsole(
|
System.out.println(startupHero(styledConsole));
|
||||||
System.getenv(),
|
|
||||||
System.console() != null,
|
|
||||||
OS_NAME,
|
|
||||||
System.getProperty("habbo.console.style", "auto"))));
|
|
||||||
|
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
|
|
||||||
@@ -372,6 +367,26 @@ public final class Emulator {
|
|||||||
return ConsoleStyle.isEnabled(environment, interactiveConsole, osName, styleProperty);
|
return ConsoleStyle.isEnabled(environment, interactiveConsole, osName, styleProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void configureAnsiConsole(boolean styledConsole) {
|
||||||
|
if (!styledConsole || !OS_NAME.startsWith("Windows") || CLASS_PATH.contains("idea_rt.jar")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
AnsiConsole.systemInstall();
|
||||||
|
|
||||||
|
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||||
|
ConsoleAppender<ILoggingEvent> appender = (ConsoleAppender<ILoggingEvent>) root.getAppender("Console");
|
||||||
|
if (appender != null) {
|
||||||
|
appender.stop();
|
||||||
|
appender.setWithJansi(true);
|
||||||
|
appender.start();
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
LOGGER.debug("Unable to install Jansi console bridge; continuing with raw console output.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String fit(String value, int width) {
|
private static String fit(String value, int width) {
|
||||||
String safe = value == null ? "" : value;
|
String safe = value == null ? "" : value;
|
||||||
if (safe.length() > width) {
|
if (safe.length() > width) {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.eu.habbo;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
@@ -55,4 +57,16 @@ class EmulatorStartupConsoleTest {
|
|||||||
"Windows 11",
|
"Windows 11",
|
||||||
"plain"));
|
"plain"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void windowsAnsiModeInstallsJansiBeforePrintingStartupHero() throws Exception {
|
||||||
|
String source = Files.readString(Path.of("src/main/java/com/eu/habbo/Emulator.java"));
|
||||||
|
|
||||||
|
assertTrue(source.contains("AnsiConsole.systemInstall()"),
|
||||||
|
"forced ANSI mode must install the Jansi bridge for Windows CMD/System.out");
|
||||||
|
assertTrue(source.contains("configureAnsiConsole(styledConsole)"),
|
||||||
|
"console bridge must be configured before startupHero is printed");
|
||||||
|
assertTrue(source.indexOf("configureAnsiConsole(styledConsole)") < source.indexOf("startupHero(styledConsole)"),
|
||||||
|
"Jansi must be installed before writing ANSI startup output");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user