mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
Draw console reports as a tree
This commit is contained in:
1 parent
01874b1e6f
commit
5a9abb2756
7 files changed
+117
-21
No files matched your search
@@ -49,6 +49,7 @@ import art.arcane.iris.integration.IrisPapiState;
|
|||||||
import art.arcane.iris.integration.MultiverseCoreLink;
|
import art.arcane.iris.integration.MultiverseCoreLink;
|
||||||
import art.arcane.iris.integration.MultiverseSVC;
|
import art.arcane.iris.integration.MultiverseSVC;
|
||||||
import art.arcane.iris.localization.C;
|
import art.arcane.iris.localization.C;
|
||||||
|
import art.arcane.iris.localization.ChatReport;
|
||||||
import art.arcane.iris.localization.ConsoleGlyphs;
|
import art.arcane.iris.localization.ConsoleGlyphs;
|
||||||
import art.arcane.iris.localization.IrisLanguage;
|
import art.arcane.iris.localization.IrisLanguage;
|
||||||
import art.arcane.iris.pack.datapack.DatapackIngestService;
|
import art.arcane.iris.pack.datapack.DatapackIngestService;
|
||||||
@@ -263,7 +264,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
if (current == null) {
|
if (current == null) {
|
||||||
Iris plugin = Iris.instance;
|
Iris plugin = Iris.instance;
|
||||||
current = new VolmitSender(Bukkit.getConsoleSender());
|
current = new VolmitSender(Bukkit.getConsoleSender());
|
||||||
current.setTag(IrisSafeguard.mode().logTag());
|
current.setTag(logPrefix());
|
||||||
sender = current;
|
sender = current;
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
@@ -310,8 +311,9 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
static void msg(String string) {
|
static void msg(String string) {
|
||||||
try {
|
try {
|
||||||
Iris plugin = Iris.instance;
|
Iris plugin = Iris.instance;
|
||||||
|
String markup = ConsoleGlyphs.console().fit(string);
|
||||||
if (shadesConsole()) {
|
if (shadesConsole()) {
|
||||||
logShaded(Level.INFO, logPrefix() + string);
|
logShaded(Level.INFO, logPrefix() + markup);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ComponentLog.logMarkup(
|
ComponentLog.logMarkup(
|
||||||
@@ -319,7 +321,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
Logger.getLogger("Iris"),
|
Logger.getLogger("Iris"),
|
||||||
logPrefix(),
|
logPrefix(),
|
||||||
Level.INFO,
|
Level.INFO,
|
||||||
string,
|
markup,
|
||||||
null);
|
null);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
try {
|
try {
|
||||||
@@ -632,7 +634,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String logPrefix() {
|
private static String logPrefix() {
|
||||||
return IrisSafeguard.mode().logTag();
|
return ConsoleGlyphs.console().fit(IrisSafeguard.mode().logTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int irisVersion(String input) {
|
static int irisVersion(String input) {
|
||||||
@@ -738,7 +740,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
timings.mark("datapacks");
|
timings.mark("datapacks");
|
||||||
IrisSafeguard.execute();
|
IrisSafeguard.execute();
|
||||||
timings.mark("safeguard");
|
timings.mark("safeguard");
|
||||||
getSender().setTag(IrisSafeguard.mode().logTag());
|
getSender().setTag(logPrefix());
|
||||||
// A cosmetic banner must never abort the bootstrap.
|
// A cosmetic banner must never abort the bootstrap.
|
||||||
J.attempt(this::splash);
|
J.attempt(this::splash);
|
||||||
IrisSafeguard.printReports();
|
IrisSafeguard.printReports();
|
||||||
@@ -858,7 +860,8 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
private void report() {
|
private void report() {
|
||||||
String total = seconds(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startedAt));
|
String total = seconds(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startedAt));
|
||||||
String phases = slowestFirst(phaseMillis, REPORTED_PHASE_MIN_MS);
|
String phases = slowestFirst(phaseMillis, REPORTED_PHASE_MIN_MS);
|
||||||
IrisLogging.notice(phases.isEmpty() ? "Enabled in " + total : "Enabled in " + total + " (" + phases + ")");
|
String enabled = phases.isEmpty() ? "Enabled in " + total : "Enabled in " + total + " (" + phases + ")";
|
||||||
|
IrisLogging.notice(ChatReport.Tone.SUCCESS.marked(C.RESET + enabled));
|
||||||
String slowServices = slowestFirst(serviceMillis, SLOW_SERVICE_MIN_MS);
|
String slowServices = slowestFirst(serviceMillis, SLOW_SERVICE_MIN_MS);
|
||||||
if (!slowServices.isEmpty()) {
|
if (!slowServices.isEmpty()) {
|
||||||
IrisLogging.notice("Slow services: " + slowServices);
|
IrisLogging.notice("Slow services: " + slowServices);
|
||||||
|
|||||||
@@ -11,18 +11,29 @@ public final class ChatReport {
|
|||||||
public static final int DEFAULT_ITEM_LIMIT = 8;
|
public static final int DEFAULT_ITEM_LIMIT = 8;
|
||||||
private static final String ITEM_BULLET = " » ";
|
private static final String ITEM_BULLET = " » ";
|
||||||
private static final String CONTINUATION_INDENT = " ";
|
private static final String CONTINUATION_INDENT = " ";
|
||||||
|
private static final String TREE_CONTINUATION_INDENT = " ";
|
||||||
private static final Pattern LEGACY_COLOR = Pattern.compile("(?i)[§&][0-9A-FK-ORX]");
|
private static final Pattern LEGACY_COLOR = Pattern.compile("(?i)[§&][0-9A-FK-ORX]");
|
||||||
|
|
||||||
public enum Tone {
|
public enum Tone {
|
||||||
SUCCESS(C.IRIS),
|
SUCCESS(C.IRIS, ConsoleGlyphs.CHECK),
|
||||||
INFO(C.AQUA),
|
INFO(C.AQUA, ""),
|
||||||
WARNING(C.GOLD),
|
WARNING(C.GOLD, ConsoleGlyphs.CAUTION),
|
||||||
ERROR(C.RED);
|
ERROR(C.RED, ConsoleGlyphs.CROSS);
|
||||||
|
|
||||||
private final C color;
|
private final C color;
|
||||||
|
private final String mark;
|
||||||
|
|
||||||
Tone(C color) {
|
Tone(C color, String mark) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.mark = mark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Prefixes already styled console text with this tone's status mark; a tone without one leaves it as is. */
|
||||||
|
public String marked(String styledText) {
|
||||||
|
if (mark.isEmpty()) {
|
||||||
|
return styledText;
|
||||||
|
}
|
||||||
|
return color + mark + " " + styledText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public C color() {
|
public C color() {
|
||||||
@@ -124,9 +135,42 @@ public final class ChatReport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The console layout: a status mark on the title and the body drawn as a tree under it. */
|
||||||
|
public List<String> consoleLines() {
|
||||||
|
List<String> lines = new ArrayList<>();
|
||||||
|
lines.add(tone.marked(ReportText.title(tone, clean(title))));
|
||||||
|
List<List<String>> branches = consoleBranches();
|
||||||
|
for (int index = 0; index < branches.size(); index++) {
|
||||||
|
addBranchLines(lines, branches.get(index), index == branches.size() - 1);
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<List<String>> consoleBranches() {
|
||||||
|
int shown = Math.min(itemLimit, entries.size());
|
||||||
|
List<List<String>> branches = new ArrayList<>(entries.subList(0, shown));
|
||||||
|
int hidden = entries.size() - shown;
|
||||||
|
if (hidden > 0) {
|
||||||
|
branches.add(List.of(C.DARK_GRAY + ReportText.moreLabel(hidden)));
|
||||||
|
}
|
||||||
|
if (hint != null) {
|
||||||
|
branches.add(List.of(C.GRAY + hint));
|
||||||
|
}
|
||||||
|
return branches;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBranchLines(List<String> lines, List<String> branch, boolean last) {
|
||||||
|
String connector = last ? ConsoleGlyphs.LAST_BRANCH : ConsoleGlyphs.BRANCH;
|
||||||
|
String trunk = last ? " " : ConsoleGlyphs.BAR;
|
||||||
|
lines.add(tone.color() + connector + " " + C.GRAY + branch.getFirst());
|
||||||
|
for (int index = 1; index < branch.size(); index++) {
|
||||||
|
lines.add(tone.color() + trunk + TREE_CONTINUATION_INDENT + branch.get(index).stripLeading());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void log() {
|
public void log() {
|
||||||
for (Line line : lines()) {
|
for (String line : consoleLines()) {
|
||||||
logLine(line.text());
|
logLine(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
/** Swaps the non-ASCII glyphs Iris prints for ASCII ones when the console charset cannot encode them. */
|
/** Swaps the non-ASCII glyphs Iris prints for ASCII ones when the console charset cannot encode them. */
|
||||||
public final class ConsoleGlyphs {
|
public final class ConsoleGlyphs {
|
||||||
|
public static final String BAR = "\u2502";
|
||||||
|
public static final String BRANCH = "\u251c";
|
||||||
|
public static final String LAST_BRANCH = "\u2514";
|
||||||
|
public static final String CHECK = "\u2714";
|
||||||
|
public static final String CAUTION = "\u25b2";
|
||||||
|
public static final String CROSS = "\u2716";
|
||||||
|
|
||||||
private static final Map<String, String> ASCII_FALLBACKS = asciiFallbacks();
|
private static final Map<String, String> ASCII_FALLBACKS = asciiFallbacks();
|
||||||
private static final String[] CONSOLE_CHARSET_PROPERTIES = {"stdout.encoding", "native.encoding"};
|
private static final String[] CONSOLE_CHARSET_PROPERTIES = {"stdout.encoding", "native.encoding"};
|
||||||
private static final ConsoleGlyphs CONSOLE = forCharset(consoleCharset());
|
private static final ConsoleGlyphs CONSOLE = forCharset(consoleCharset());
|
||||||
@@ -45,8 +52,14 @@ public final class ConsoleGlyphs {
|
|||||||
private static Map<String, String> asciiFallbacks() {
|
private static Map<String, String> asciiFallbacks() {
|
||||||
Map<String, String> fallbacks = new LinkedHashMap<>();
|
Map<String, String> fallbacks = new LinkedHashMap<>();
|
||||||
fallbacks.put("\u00bb", ">");
|
fallbacks.put("\u00bb", ">");
|
||||||
fallbacks.put("\u2039", "<");
|
fallbacks.put(BAR, "|");
|
||||||
fallbacks.put("\u203a", ">");
|
fallbacks.put(BRANCH, "|-");
|
||||||
|
fallbacks.put(LAST_BRANCH, "`-");
|
||||||
|
fallbacks.put(CHECK, "+");
|
||||||
|
fallbacks.put(CAUTION, "!");
|
||||||
|
fallbacks.put(CROSS, "x");
|
||||||
|
fallbacks.put("\u2039", "[");
|
||||||
|
fallbacks.put("\u203a", "]");
|
||||||
return fallbacks;
|
return fallbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package art.arcane.iris.world.safeguard;
|
|||||||
import art.arcane.iris.world.IrisStartupValidation;
|
import art.arcane.iris.world.IrisStartupValidation;
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
import art.arcane.iris.localization.C;
|
import art.arcane.iris.localization.C;
|
||||||
|
import art.arcane.iris.localization.ChatReport;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -123,7 +124,7 @@ public final class IrisSafeguard {
|
|||||||
|
|
||||||
public static void printFooter() {
|
public static void printFooter() {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case STABLE -> IrisLogging.info(C.BLUE + "Stable, 0 conflicts");
|
case STABLE -> IrisLogging.info(ChatReport.Tone.SUCCESS.marked(C.BLUE + "Stable, 0 conflicts"));
|
||||||
case WARNING -> warning();
|
case WARNING -> warning();
|
||||||
case UNSTABLE -> unstable();
|
case UNSTABLE -> unstable();
|
||||||
}
|
}
|
||||||
@@ -137,13 +138,13 @@ public final class IrisSafeguard {
|
|||||||
// A log record carries a level, so a blank record renders as an empty [WARN] line and a rule of
|
// A log record carries a level, so a blank record renders as an empty [WARN] line and a rule of
|
||||||
// dashes renders as a [SEVERE] one. Spacing belongs to a console, not to the server log.
|
// dashes renders as a [SEVERE] one. Spacing belongs to a console, not to the server log.
|
||||||
private static void warning() {
|
private static void warning() {
|
||||||
IrisLogging.warn(C.GOLD + "Iris is running in Warning Mode");
|
IrisLogging.warn(ChatReport.Tone.WARNING.marked(C.GOLD + "Iris is running in Warning Mode"));
|
||||||
IrisLogging.warn(C.GRAY + "Some startup checks need attention. Review the messages above for tuning suggestions.");
|
IrisLogging.warn(C.GRAY + "Some startup checks need attention. Review the messages above for tuning suggestions.");
|
||||||
IrisLogging.warn(C.GRAY + "Iris will continue startup normally.");
|
IrisLogging.warn(C.GRAY + "Iris will continue startup normally.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void unstable() {
|
private static void unstable() {
|
||||||
IrisLogging.error(C.DARK_RED + "Iris is running in Danger Mode");
|
IrisLogging.error(ChatReport.Tone.ERROR.marked(C.DARK_RED + "Iris is running in Danger Mode"));
|
||||||
IrisLogging.error("Critical startup checks failed. Review and resolve the errors above as soon as possible.");
|
IrisLogging.error("Critical startup checks failed. Review and resolve the errors above as soon as possible.");
|
||||||
// No startup sleep: blocking the boot thread protected nothing — world creation and
|
// No startup sleep: blocking the boot thread protected nothing — world creation and
|
||||||
// player admission are already gated by IrisStartupValidation.
|
// player admission are already gated by IrisStartupValidation.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import art.arcane.iris.diagnostics.splash.IrisSplashComposer;
|
|||||||
import art.arcane.iris.diagnostics.splash.IrisSplashRenderer;
|
import art.arcane.iris.diagnostics.splash.IrisSplashRenderer;
|
||||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||||
import art.arcane.iris.localization.C;
|
import art.arcane.iris.localization.C;
|
||||||
|
import art.arcane.iris.localization.ConsoleGlyphs;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,7 +44,7 @@ public enum Mode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String logTag() {
|
public String logTag() {
|
||||||
return color.toString() + C.BOLD + "Iris" + C.RESET + C.DARK_GRAY + " | " + C.RESET;
|
return color.toString() + C.BOLD + "Iris" + C.RESET + C.DARK_GRAY + " " + ConsoleGlyphs.BAR + " " + C.RESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String composeSplash(List<List<IrisSplashComposer.Detail>> detailRows) {
|
public String composeSplash(List<List<IrisSplashComposer.Detail>> detailRows) {
|
||||||
|
|||||||
@@ -104,6 +104,33 @@ public class ChatReportTest {
|
|||||||
assertEquals(3, report.lines().size());
|
assertEquals(3, report.lines().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consoleLayoutMarksTheTitleAndDrawsTheBodyAsATree() {
|
||||||
|
List<String> console = ChatReport.of(ChatReport.Tone.ERROR, "Pack 'uitest' failed validation")
|
||||||
|
.items(List.of(
|
||||||
|
"Biome 'dev'" + REMOVED_FIELD_TAIL,
|
||||||
|
"Biome 'vanilla/grove'" + REMOVED_FIELD_TAIL,
|
||||||
|
"Missing dimensions/ folder."))
|
||||||
|
.hint("Details: /iris pack validate uitest", null)
|
||||||
|
.build()
|
||||||
|
.consoleLines().stream().map(line -> line.replaceAll("§.", "")).toList();
|
||||||
|
|
||||||
|
assertEquals(List.of(
|
||||||
|
"\u2716 Pack 'uitest' failed validation",
|
||||||
|
"\u251c 2 biomes: caveProfile.allowWater was removed; use caveProfile.allowFluid. Cave aquifers use the dimension fluidPalette.",
|
||||||
|
"\u2502 dev, vanilla/grove",
|
||||||
|
"\u251c Missing dimensions/ folder.",
|
||||||
|
"\u2514 Details: /iris pack validate uitest"), console);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consoleLayoutLeavesInfoTitlesUnmarked() {
|
||||||
|
List<String> console = ChatReport.of(ChatReport.Tone.INFO, "Worlds").item("world").build().consoleLines();
|
||||||
|
|
||||||
|
assertEquals("Worlds", console.get(0).replaceAll("§.", ""));
|
||||||
|
assertEquals("\u2514 world", console.get(1).replaceAll("§.", ""));
|
||||||
|
}
|
||||||
|
|
||||||
private static List<String> plainLines(ChatReport report) {
|
private static List<String> plainLines(ChatReport report) {
|
||||||
return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList();
|
return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,18 @@ public class ConsoleGlyphsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void asciiConsoleGetsAsciiGlyphs() {
|
public void asciiConsoleGetsAsciiGlyphs() {
|
||||||
assertEquals(" > Biome <caves>", ConsoleGlyphs.forCharset(StandardCharsets.US_ASCII).fit(REPORT_LINE));
|
assertEquals(" > Biome [caves]", ConsoleGlyphs.forCharset(StandardCharsets.US_ASCII).fit(REPORT_LINE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void asciiConsoleGetsAnAsciiTree() {
|
||||||
|
String tree = ConsoleGlyphs.BAR + " " + ConsoleGlyphs.CROSS + " title\n" + ConsoleGlyphs.BRANCH + " item\n" + ConsoleGlyphs.LAST_BRANCH + " hint";
|
||||||
|
|
||||||
|
assertEquals("| x title\n|- item\n`- hint", ConsoleGlyphs.forCharset(StandardCharsets.US_ASCII).fit(tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void latin1ConsoleKeepsWhatItCanEncode() {
|
public void latin1ConsoleKeepsWhatItCanEncode() {
|
||||||
assertEquals(" \u00bb Biome <caves>", ConsoleGlyphs.forCharset(StandardCharsets.ISO_8859_1).fit(REPORT_LINE));
|
assertEquals(" \u00bb Biome [caves]", ConsoleGlyphs.forCharset(StandardCharsets.ISO_8859_1).fit(REPORT_LINE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user