mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
Readable report layout
- Group reasons that differ only in their subject - Highlight names, keys and paths; dim the explanation - Bold report titles and tone-colored bullets - Render bold and reset codes through the gradient - Fix bold codes flagged as colors - Make the tag brackets actually bold
This commit is contained in:
1 parent
ac4bc6b96a
commit
8c9f3bd73d
6 files changed
+303
-62
No files matched your search
+8
-3
@@ -1,5 +1,6 @@
|
|||||||
package art.arcane.iris.command;
|
package art.arcane.iris.command;
|
||||||
|
|
||||||
|
import art.arcane.iris.localization.ChatReport;
|
||||||
import art.arcane.iris.pack.validation.CompatAction;
|
import art.arcane.iris.pack.validation.CompatAction;
|
||||||
import art.arcane.iris.pack.validation.CompatFinding;
|
import art.arcane.iris.pack.validation.CompatFinding;
|
||||||
import art.arcane.iris.pack.validation.CompatRegistry;
|
import art.arcane.iris.pack.validation.CompatRegistry;
|
||||||
@@ -30,9 +31,13 @@ public class CommandPackCompatTest {
|
|||||||
return new PackValidationResult("overworld", List.of(), List.of(), 1L, findings, "26.1.2");
|
return new PackValidationResult("overworld", List.of(), List.of(), 1L, findings, "26.1.2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<String> plainCompatOutput(String pack, PackValidationResult result) {
|
||||||
|
return CommandPack.compatOutput(pack, result).stream().map(ChatReport::clean).toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unknownPackIsReportedWithoutAnyCompatLines() {
|
public void unknownPackIsReportedWithoutAnyCompatLines() {
|
||||||
List<String> lines = CommandPack.compatOutput("nope", null);
|
List<String> lines = plainCompatOutput("nope", null);
|
||||||
|
|
||||||
assertEquals(1, lines.size());
|
assertEquals(1, lines.size());
|
||||||
assertTrue(lines.getFirst(), lines.getFirst().contains("No validation result for 'nope'"));
|
assertTrue(lines.getFirst(), lines.getFirst().contains("No validation result for 'nope'"));
|
||||||
@@ -40,7 +45,7 @@ public class CommandPackCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void packWithoutFindingsSaysSoAndNamesTheVersion() {
|
public void packWithoutFindingsSaysSoAndNamesTheVersion() {
|
||||||
List<String> lines = CommandPack.compatOutput("overworld", result(List.of()));
|
List<String> lines = plainCompatOutput("overworld", result(List.of()));
|
||||||
|
|
||||||
assertEquals(1, lines.size());
|
assertEquals(1, lines.size());
|
||||||
assertTrue(lines.getFirst(), lines.getFirst().contains("Pack 'overworld' uses no content"));
|
assertTrue(lines.getFirst(), lines.getFirst().contains("Pack 'overworld' uses no content"));
|
||||||
@@ -49,7 +54,7 @@ public class CommandPackCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findingsArePrintedUncappedWithTheFallbackRemedy() {
|
public void findingsArePrintedUncappedWithTheFallbackRemedy() {
|
||||||
List<String> lines = CommandPack.compatOutput("overworld", result(List.of(
|
List<String> lines = plainCompatOutput("overworld", result(List.of(
|
||||||
block(CompatAction.EXCLUDED, "cave/a"),
|
block(CompatAction.EXCLUDED, "cave/a"),
|
||||||
block(CompatAction.EXCLUDED, "cave/b"),
|
block(CompatAction.EXCLUDED, "cave/b"),
|
||||||
block(CompatAction.EXCLUDED, "cave/c"),
|
block(CompatAction.EXCLUDED, "cave/c"),
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ public enum C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
C(char code, int intCode, boolean isFormat) {
|
C(char code, int intCode, boolean isFormat) {
|
||||||
this("^", code, intCode, false);
|
this("^", code, intCode, isFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
C(String token, char code, int intCode, boolean isFormat) {
|
C(String token, char code, int intCode, boolean isFormat) {
|
||||||
@@ -384,25 +384,7 @@ public enum C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String mini(String s) {
|
public static String mini(String s) {
|
||||||
String msg = compress(s);
|
return toMarkup(s, color -> color.token);
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
boolean c = false;
|
|
||||||
|
|
||||||
for (char i : msg.toCharArray()) {
|
|
||||||
if (!c) {
|
|
||||||
if (i == C.COLOR_CHAR) {
|
|
||||||
c = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
b.append(i);
|
|
||||||
} else {
|
|
||||||
c = false;
|
|
||||||
C o = C.getByChar(i);
|
|
||||||
b.append(o.token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return b.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String aura(String s, int hrad, int srad, int vrad) {
|
public static String aura(String s, int hrad, int srad, int vrad) {
|
||||||
@@ -410,39 +392,48 @@ public enum C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String aura(String s, int hrad, int srad, int vrad, double pulse) {
|
public static String aura(String s, int hrad, int srad, int vrad, double pulse) {
|
||||||
|
if (hrad == 0 && srad == 0 && vrad == 0) {
|
||||||
|
return mini(s);
|
||||||
|
}
|
||||||
|
return toMarkup(s, color -> pulse > 0
|
||||||
|
? VolmitSender.pulse(spinToHex(color, hrad, srad, vrad), spinToHex(color, -hrad, -srad, -vrad), pulse)
|
||||||
|
: "<gradient:" + spinToHex(color, hrad, srad, vrad) + ":" + spinToHex(color, -hrad, -srad, -vrad) + ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts legacy section codes to MiniMessage. Format codes become their tags, and a color code after a format
|
||||||
|
* emits a reset first, because in legacy text a color ends bold/italic while MiniMessage tags stay open.
|
||||||
|
*/
|
||||||
|
private static String toMarkup(String s, java.util.function.Function<C, String> colorTag) {
|
||||||
String msg = compress(s);
|
String msg = compress(s);
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
boolean c = false;
|
boolean codeFollows = false;
|
||||||
|
boolean formatOpen = false;
|
||||||
|
|
||||||
for (char i : msg.toCharArray()) {
|
for (char i : msg.toCharArray()) {
|
||||||
if (c) {
|
if (!codeFollows) {
|
||||||
c = false;
|
if (i == C.COLOR_CHAR) {
|
||||||
|
codeFollows = true;
|
||||||
C o = C.getByChar(i);
|
|
||||||
|
|
||||||
if (hrad != 0 || srad != 0 || vrad != 0) {
|
|
||||||
if (pulse > 0) {
|
|
||||||
b.append(VolmitSender.pulse(spinToHex(o, hrad, srad, vrad), spinToHex(o, -hrad, -srad, -vrad), pulse));
|
|
||||||
} else {
|
|
||||||
b.append("<gradient:")
|
|
||||||
.append(spinToHex(o, hrad, srad, vrad))
|
|
||||||
.append(":")
|
|
||||||
.append(spinToHex(o, -hrad, -srad, -vrad))
|
|
||||||
.append(">");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
b.append(C.getByChar(i).token);
|
b.append(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
codeFollows = false;
|
||||||
if (i == C.COLOR_CHAR) {
|
C code = C.getByChar(i);
|
||||||
c = true;
|
if (code == RESET) {
|
||||||
continue;
|
b.append(code.token);
|
||||||
|
formatOpen = false;
|
||||||
|
} else if (code.isFormat()) {
|
||||||
|
b.append(code.token);
|
||||||
|
formatOpen = true;
|
||||||
|
} else {
|
||||||
|
if (formatOpen) {
|
||||||
|
b.append(RESET.token);
|
||||||
|
formatOpen = false;
|
||||||
|
}
|
||||||
|
b.append(colorTag.apply(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
b.append(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.toString();
|
return b.toString();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package art.arcane.iris.localization;
|
package art.arcane.iris.localization;
|
||||||
|
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -43,7 +42,7 @@ public final class ChatReport {
|
|||||||
|
|
||||||
private final Tone tone;
|
private final Tone tone;
|
||||||
private final String title;
|
private final String title;
|
||||||
private final List<String> items;
|
private final List<List<String>> entries;
|
||||||
private final int itemLimit;
|
private final int itemLimit;
|
||||||
private final String hint;
|
private final String hint;
|
||||||
private final String hintCommand;
|
private final String hintCommand;
|
||||||
@@ -51,7 +50,7 @@ public final class ChatReport {
|
|||||||
private ChatReport(Builder builder) {
|
private ChatReport(Builder builder) {
|
||||||
this.tone = builder.tone;
|
this.tone = builder.tone;
|
||||||
this.title = builder.title;
|
this.title = builder.title;
|
||||||
this.items = List.copyOf(builder.items);
|
this.entries = List.copyOf(builder.entries);
|
||||||
this.itemLimit = builder.itemLimit;
|
this.itemLimit = builder.itemLimit;
|
||||||
this.hint = builder.hint;
|
this.hint = builder.hint;
|
||||||
this.hintCommand = builder.hintCommand;
|
this.hintCommand = builder.hintCommand;
|
||||||
@@ -85,15 +84,14 @@ public final class ChatReport {
|
|||||||
|
|
||||||
public List<Line> lines() {
|
public List<Line> lines() {
|
||||||
List<Line> lines = new ArrayList<>();
|
List<Line> lines = new ArrayList<>();
|
||||||
lines.add(new Line(tone.paint(title), null));
|
lines.add(new Line(ReportText.title(tone, clean(title)), null));
|
||||||
int shown = Math.min(itemLimit, items.size());
|
int shown = Math.min(itemLimit, entries.size());
|
||||||
for (int index = 0; index < shown; index++) {
|
for (int index = 0; index < shown; index++) {
|
||||||
lines.add(new Line(C.DARK_GRAY + ITEM_BULLET + C.GRAY + items.get(index), null));
|
addEntryLines(lines, entries.get(index));
|
||||||
}
|
}
|
||||||
int hidden = items.size() - shown;
|
int hidden = entries.size() - shown;
|
||||||
if (hidden > 0) {
|
if (hidden > 0) {
|
||||||
lines.add(new Line(C.DARK_GRAY + CONTINUATION_INDENT
|
lines.add(new Line(C.DARK_GRAY + CONTINUATION_INDENT + ReportText.moreLabel(hidden), null));
|
||||||
+ clean(IrisLanguage.plain(RuntimeUiMessages.REPORT_MORE, MessageArgument.trusted("count", hidden))), null));
|
|
||||||
}
|
}
|
||||||
if (hint != null) {
|
if (hint != null) {
|
||||||
lines.add(new Line(C.GRAY + hint, hintCommand));
|
lines.add(new Line(C.GRAY + hint, hintCommand));
|
||||||
@@ -101,6 +99,13 @@ public final class ChatReport {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addEntryLines(List<Line> lines, List<String> entry) {
|
||||||
|
lines.add(new Line(tone.color() + ITEM_BULLET + C.GRAY + entry.getFirst(), null));
|
||||||
|
for (int index = 1; index < entry.size(); index++) {
|
||||||
|
lines.add(new Line(entry.get(index), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void log() {
|
public void log() {
|
||||||
for (Line line : lines()) {
|
for (Line line : lines()) {
|
||||||
logLine(line.text());
|
logLine(line.text());
|
||||||
@@ -119,7 +124,7 @@ public final class ChatReport {
|
|||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private final Tone tone;
|
private final Tone tone;
|
||||||
private final String title;
|
private final String title;
|
||||||
private final List<String> items = new ArrayList<>();
|
private final List<List<String>> entries = new ArrayList<>();
|
||||||
private int itemLimit = DEFAULT_ITEM_LIMIT;
|
private int itemLimit = DEFAULT_ITEM_LIMIT;
|
||||||
private String hint;
|
private String hint;
|
||||||
private String hintCommand;
|
private String hintCommand;
|
||||||
@@ -132,27 +137,33 @@ public final class ChatReport {
|
|||||||
public Builder item(String text) {
|
public Builder item(String text) {
|
||||||
String cleaned = clean(text);
|
String cleaned = clean(text);
|
||||||
if (!cleaned.isEmpty()) {
|
if (!cleaned.isEmpty()) {
|
||||||
items.add(cleaned);
|
entries.add(List.of(ReportText.body(cleaned)));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder styledItem(String styledText) {
|
public Builder styledItem(String styledText) {
|
||||||
if (styledText != null && !styledText.isBlank()) {
|
if (styledText != null && !styledText.isBlank()) {
|
||||||
items.add(styledText);
|
entries.add(List.of(styledText));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Adds reasons, collapsing ones that differ only in their quoted subject into a single entry. */
|
||||||
public Builder items(Collection<String> texts) {
|
public Builder items(Collection<String> texts) {
|
||||||
|
List<String> cleaned = new ArrayList<>(texts.size());
|
||||||
for (String text : texts) {
|
for (String text : texts) {
|
||||||
item(text);
|
String reason = clean(text);
|
||||||
|
if (!reason.isEmpty()) {
|
||||||
|
cleaned.add(reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
entries.addAll(ReportText.groupedBodies(cleaned, CONTINUATION_INDENT));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder entry(String label, Object value) {
|
public Builder entry(String label, Object value) {
|
||||||
items.add(label(label, String.valueOf(value)));
|
entries.add(List.of(label(label, String.valueOf(value))));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package art.arcane.iris.localization;
|
||||||
|
|
||||||
|
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Styles plain report text so long reasons scan quickly: names and keys get their own color, the explanation after
|
||||||
|
* the first sentence is dimmed, and reasons that differ only in their subject collapse into one entry.
|
||||||
|
*/
|
||||||
|
final class ReportText {
|
||||||
|
private static final int GROUP_SUBJECTS_SHOWN = 4;
|
||||||
|
private static final Pattern SENTENCE_BREAK = Pattern.compile("(?<=[.!?])\\s+(?=[A-Z\\[])");
|
||||||
|
private static final String QUOTED_NAME = "(?<![A-Za-z])'[^']+'(?![A-Za-z])";
|
||||||
|
private static final Pattern QUOTED = Pattern.compile(QUOTED_NAME);
|
||||||
|
private static final Pattern TOKEN = Pattern.compile(
|
||||||
|
"(?<quoted>" + QUOTED_NAME + ")"
|
||||||
|
+ "|(?<command>/iris(?: [\\w:=./-]+)+)"
|
||||||
|
+ "|(?<key>\\b[a-z0-9_.-]+:[a-z0-9_./-]+)"
|
||||||
|
+ "|(?<path>\\b[A-Za-z_]\\w*(?:\\.[A-Za-z_]\\w*|\\[\\d+])+)");
|
||||||
|
private static final Pattern SUBJECT_REASON = Pattern.compile("^([A-Z][\\w ]*?) '([^']+)'(.+)$", Pattern.DOTALL);
|
||||||
|
private static final Pattern LEADING_JOINER = Pattern.compile("^[.\\s]+");
|
||||||
|
|
||||||
|
private ReportText() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static String title(ChatReport.Tone tone, String plain) {
|
||||||
|
String base = tone.color().toString() + C.BOLD;
|
||||||
|
return base + highlightQuoted(plain, C.WHITE.toString() + C.BOLD, base);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String body(String plain) {
|
||||||
|
Matcher sentenceBreak = SENTENCE_BREAK.matcher(plain);
|
||||||
|
if (!sentenceBreak.find()) {
|
||||||
|
return C.GRAY + highlightTokens(plain, C.GRAY.toString());
|
||||||
|
}
|
||||||
|
String head = plain.substring(0, sentenceBreak.start());
|
||||||
|
String tail = plain.substring(sentenceBreak.end());
|
||||||
|
return C.GRAY + highlightTokens(head, C.GRAY.toString()) + " " + C.DARK_GRAY + tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Groups reasons shaped like {@code Kind 'subject' rest} that share kind and rest; other reasons stay single. */
|
||||||
|
static List<List<String>> groupedBodies(List<String> plainReasons, String continuationIndent) {
|
||||||
|
Map<String, SubjectGroup> groups = new LinkedHashMap<>();
|
||||||
|
for (String reason : plainReasons) {
|
||||||
|
Matcher matcher = SUBJECT_REASON.matcher(reason);
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
groups.put("\u0000" + groups.size(), new SubjectGroup(null, reason));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String kind = matcher.group(1);
|
||||||
|
String rest = LEADING_JOINER.matcher(matcher.group(3)).replaceFirst("");
|
||||||
|
groups.computeIfAbsent(kind + "\u0000" + rest, ignored -> new SubjectGroup(kind, rest))
|
||||||
|
.add(matcher.group(2), reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<List<String>> entries = new ArrayList<>(groups.size());
|
||||||
|
for (SubjectGroup group : groups.values()) {
|
||||||
|
entries.add(group.render(continuationIndent));
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String highlightQuoted(String plain, String highlight, String base) {
|
||||||
|
Matcher matcher = QUOTED.matcher(plain);
|
||||||
|
StringBuilder styled = new StringBuilder();
|
||||||
|
while (matcher.find()) {
|
||||||
|
matcher.appendReplacement(styled, Matcher.quoteReplacement(highlight + matcher.group() + base));
|
||||||
|
}
|
||||||
|
matcher.appendTail(styled);
|
||||||
|
return styled.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String highlightTokens(String plain, String base) {
|
||||||
|
Matcher matcher = TOKEN.matcher(plain);
|
||||||
|
StringBuilder styled = new StringBuilder();
|
||||||
|
while (matcher.find()) {
|
||||||
|
matcher.appendReplacement(styled, Matcher.quoteReplacement(tokenColor(matcher) + matcher.group() + base));
|
||||||
|
}
|
||||||
|
matcher.appendTail(styled);
|
||||||
|
return styled.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String tokenColor(Matcher matcher) {
|
||||||
|
if (matcher.group("quoted") != null) {
|
||||||
|
return C.WHITE.toString();
|
||||||
|
}
|
||||||
|
if (matcher.group("command") != null) {
|
||||||
|
return C.IRIS.toString();
|
||||||
|
}
|
||||||
|
return C.AQUA.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String moreLabel(int hidden) {
|
||||||
|
return ChatReport.clean(IrisLanguage.plain(RuntimeUiMessages.REPORT_MORE, MessageArgument.trusted("count", hidden)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String plural(String kind) {
|
||||||
|
String lower = kind.toLowerCase(Locale.ROOT);
|
||||||
|
if (lower.endsWith("s")) {
|
||||||
|
return lower;
|
||||||
|
}
|
||||||
|
if (lower.endsWith("y") && !lower.endsWith("ey")) {
|
||||||
|
return lower.substring(0, lower.length() - 1) + "ies";
|
||||||
|
}
|
||||||
|
return lower + "s";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class SubjectGroup {
|
||||||
|
private final String kind;
|
||||||
|
private final String rest;
|
||||||
|
private final List<String> subjects = new ArrayList<>();
|
||||||
|
private String singleReason;
|
||||||
|
|
||||||
|
private SubjectGroup(String kind, String reasonOrRest) {
|
||||||
|
this.kind = kind;
|
||||||
|
this.rest = reasonOrRest;
|
||||||
|
this.singleReason = kind == null ? reasonOrRest : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(String subject, String reason) {
|
||||||
|
subjects.add(subject);
|
||||||
|
singleReason = subjects.size() == 1 ? reason : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> render(String continuationIndent) {
|
||||||
|
if (singleReason != null) {
|
||||||
|
return List.of(body(singleReason));
|
||||||
|
}
|
||||||
|
String head = C.WHITE + String.valueOf(subjects.size()) + " " + plural(kind) + C.DARK_GRAY + ": " + body(rest);
|
||||||
|
return List.of(head, continuationIndent + subjectList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String subjectList() {
|
||||||
|
int shown = Math.min(GROUP_SUBJECTS_SHOWN, subjects.size());
|
||||||
|
StringBuilder list = new StringBuilder();
|
||||||
|
for (int index = 0; index < shown; index++) {
|
||||||
|
if (index > 0) {
|
||||||
|
list.append(C.DARK_GRAY).append(", ");
|
||||||
|
}
|
||||||
|
list.append(C.WHITE).append(subjects.get(index));
|
||||||
|
}
|
||||||
|
int hidden = subjects.size() - shown;
|
||||||
|
if (hidden > 0) {
|
||||||
|
list.append(C.DARK_GRAY).append(" ").append(moreLabel(hidden));
|
||||||
|
}
|
||||||
|
return list.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,7 +102,7 @@ public enum Mode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String wrap(String tag) {
|
private String wrap(String tag) {
|
||||||
return C.BOLD.toString() + C.DARK_GRAY + "[" + C.BOLD + color + tag + C.BOLD + C.DARK_GRAY + "]" + C.RESET;
|
return C.DARK_GRAY.toString() + C.BOLD + "[" + color + C.BOLD + tag + C.DARK_GRAY + C.BOLD + "]" + C.RESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getServerVersion() {
|
private String getServerVersion() {
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package art.arcane.iris.localization;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class ChatReportTest {
|
||||||
|
private static final String REMOVED_FIELD_TAIL =
|
||||||
|
" caveProfile.allowWater was removed; use caveProfile.allowFluid. Cave aquifers use the dimension fluidPalette.";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void reasonsSharingAllButTheSubjectCollapseIntoOneEntry() {
|
||||||
|
List<String> plain = plainLines(ChatReport.of(ChatReport.Tone.ERROR, "Can't open Studio")
|
||||||
|
.items(List.of(
|
||||||
|
"Biome 'dev'" + REMOVED_FIELD_TAIL,
|
||||||
|
"Biome 'vanilla/grove'" + REMOVED_FIELD_TAIL,
|
||||||
|
"Biome 'vanilla/ice_spikes'" + REMOVED_FIELD_TAIL,
|
||||||
|
"Missing dimensions/ folder."))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
assertEquals(List.of(
|
||||||
|
"Can't open Studio",
|
||||||
|
" » 3 biomes: caveProfile.allowWater was removed; use caveProfile.allowFluid. Cave aquifers use the dimension fluidPalette.",
|
||||||
|
" dev, vanilla/grove, vanilla/ice_spikes",
|
||||||
|
" » Missing dimensions/ folder."), plain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void groupedSubjectsAreCappedWithAMoreTail() {
|
||||||
|
List<String> reasons = List.of("a", "b", "c", "d", "e", "f").stream()
|
||||||
|
.map(subject -> "Biome '" + subject + "'" + REMOVED_FIELD_TAIL)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
List<String> plain = plainLines(ChatReport.of(ChatReport.Tone.ERROR, "t").items(reasons).build());
|
||||||
|
|
||||||
|
assertEquals(" a, b, c, d +2 more", plain.get(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aLoneSubjectReasonKeepsItsOriginalWording() {
|
||||||
|
List<String> plain = plainLines(ChatReport.of(ChatReport.Tone.WARNING, "t")
|
||||||
|
.items(List.of("Biome 'dev'" + REMOVED_FIELD_TAIL))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
assertEquals(" » Biome 'dev'" + REMOVED_FIELD_TAIL, plain.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bodyHighlightsNamesAndDimsTheExplanation() {
|
||||||
|
String styled = ReportText.body("Biome 'dev' uses create:limestone at wall.palette[0]. Install the mod.");
|
||||||
|
|
||||||
|
assertTrue(styled.contains(C.WHITE + "'dev'" + C.GRAY));
|
||||||
|
assertTrue(styled.contains(C.AQUA + "create:limestone" + C.GRAY));
|
||||||
|
assertTrue(styled.contains(C.AQUA + "wall.palette[0]" + C.GRAY));
|
||||||
|
assertTrue(styled.endsWith(C.DARK_GRAY + "Install the mod."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void apostrophesAreNotTreatedAsQuotedNames() {
|
||||||
|
String styled = ReportText.title(ChatReport.Tone.ERROR, "Can't open Studio for 'uitest'");
|
||||||
|
|
||||||
|
assertTrue(styled.contains("Can't open Studio for " + C.WHITE + C.BOLD + "'uitest'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void boldTitlesSurviveTheMarkupConversion() {
|
||||||
|
String markup = C.mini(ReportText.title(ChatReport.Tone.ERROR, "Title") + C.GRAY + " rest");
|
||||||
|
|
||||||
|
assertTrue(markup, markup.contains("<bold>Title<reset><gray> rest"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> plainLines(ChatReport report) {
|
||||||
|
return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user