mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +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.MultiverseSVC;
|
||||
import art.arcane.iris.localization.C;
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
import art.arcane.iris.localization.ConsoleGlyphs;
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
import art.arcane.iris.pack.datapack.DatapackIngestService;
|
||||
@@ -263,7 +264,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
if (current == null) {
|
||||
Iris plugin = Iris.instance;
|
||||
current = new VolmitSender(Bukkit.getConsoleSender());
|
||||
current.setTag(IrisSafeguard.mode().logTag());
|
||||
current.setTag(logPrefix());
|
||||
sender = current;
|
||||
}
|
||||
return current;
|
||||
@@ -310,8 +311,9 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
static void msg(String string) {
|
||||
try {
|
||||
Iris plugin = Iris.instance;
|
||||
String markup = ConsoleGlyphs.console().fit(string);
|
||||
if (shadesConsole()) {
|
||||
logShaded(Level.INFO, logPrefix() + string);
|
||||
logShaded(Level.INFO, logPrefix() + markup);
|
||||
return;
|
||||
}
|
||||
ComponentLog.logMarkup(
|
||||
@@ -319,7 +321,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
Logger.getLogger("Iris"),
|
||||
logPrefix(),
|
||||
Level.INFO,
|
||||
string,
|
||||
markup,
|
||||
null);
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
@@ -632,7 +634,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
}
|
||||
|
||||
private static String logPrefix() {
|
||||
return IrisSafeguard.mode().logTag();
|
||||
return ConsoleGlyphs.console().fit(IrisSafeguard.mode().logTag());
|
||||
}
|
||||
|
||||
static int irisVersion(String input) {
|
||||
@@ -738,7 +740,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
timings.mark("datapacks");
|
||||
IrisSafeguard.execute();
|
||||
timings.mark("safeguard");
|
||||
getSender().setTag(IrisSafeguard.mode().logTag());
|
||||
getSender().setTag(logPrefix());
|
||||
// A cosmetic banner must never abort the bootstrap.
|
||||
J.attempt(this::splash);
|
||||
IrisSafeguard.printReports();
|
||||
@@ -858,7 +860,8 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
private void report() {
|
||||
String total = seconds(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startedAt));
|
||||
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);
|
||||
if (!slowServices.isEmpty()) {
|
||||
IrisLogging.notice("Slow services: " + slowServices);
|
||||
|
||||
@@ -11,18 +11,29 @@ public final class ChatReport {
|
||||
public static final int DEFAULT_ITEM_LIMIT = 8;
|
||||
private static final String ITEM_BULLET = " » ";
|
||||
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]");
|
||||
|
||||
public enum Tone {
|
||||
SUCCESS(C.IRIS),
|
||||
INFO(C.AQUA),
|
||||
WARNING(C.GOLD),
|
||||
ERROR(C.RED);
|
||||
SUCCESS(C.IRIS, ConsoleGlyphs.CHECK),
|
||||
INFO(C.AQUA, ""),
|
||||
WARNING(C.GOLD, ConsoleGlyphs.CAUTION),
|
||||
ERROR(C.RED, ConsoleGlyphs.CROSS);
|
||||
|
||||
private final C color;
|
||||
private final String mark;
|
||||
|
||||
Tone(C color) {
|
||||
Tone(C color, String mark) {
|
||||
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() {
|
||||
@@ -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() {
|
||||
for (Line line : lines()) {
|
||||
logLine(line.text());
|
||||
for (String line : consoleLines()) {
|
||||
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. */
|
||||
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 String[] CONSOLE_CHARSET_PROPERTIES = {"stdout.encoding", "native.encoding"};
|
||||
private static final ConsoleGlyphs CONSOLE = forCharset(consoleCharset());
|
||||
@@ -45,8 +52,14 @@ public final class ConsoleGlyphs {
|
||||
private static Map<String, String> asciiFallbacks() {
|
||||
Map<String, String> fallbacks = new LinkedHashMap<>();
|
||||
fallbacks.put("\u00bb", ">");
|
||||
fallbacks.put("\u2039", "<");
|
||||
fallbacks.put("\u203a", ">");
|
||||
fallbacks.put(BAR, "|");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package art.arcane.iris.world.safeguard;
|
||||
import art.arcane.iris.world.IrisStartupValidation;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.localization.C;
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -123,7 +124,7 @@ public final class IrisSafeguard {
|
||||
|
||||
public static void printFooter() {
|
||||
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 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
|
||||
// dashes renders as a [SEVERE] one. Spacing belongs to a console, not to the server log.
|
||||
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 + "Iris will continue startup normally.");
|
||||
}
|
||||
|
||||
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.");
|
||||
// No startup sleep: blocking the boot thread protected nothing — world creation and
|
||||
// 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.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.localization.C;
|
||||
import art.arcane.iris.localization.ConsoleGlyphs;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
@@ -43,7 +44,7 @@ public enum Mode {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -104,6 +104,33 @@ public class ChatReportTest {
|
||||
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) {
|
||||
return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList();
|
||||
}
|
||||
|
||||
@@ -16,11 +16,18 @@ public class ConsoleGlyphsTest {
|
||||
|
||||
@Test
|
||||
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
|
||||
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