Skip to content

Commit

Permalink
Implement hint functionality, Release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ChAoSUnItY committed Jul 15, 2022
1 parent c83c7f4 commit 90a34fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "chaos.unity.nenggao"
version = "1.1.3"
version = "1.2.0"

repositories {
mavenCentral()
Expand Down
43 changes: 39 additions & 4 deletions src/main/java/chaos/unity/nenggao/FileReportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void print(final @NotNull PrintStream printStream) {
// Render under bars
for (Label label : appliedLabels) {
int spaceLen = label.span.startPosition.pos - insertedLen;
if (spaceLen > 0) // Prevent unnecessary appending
if (spaceLen > 0) // Prevent unnecessary padding
printStream.append(new String(new char[spaceLen]).replace('\0', ' '));

int offset = label.span.offset();
Expand Down Expand Up @@ -272,6 +272,20 @@ public void print(final @NotNull PrintStream printStream) {
if (reset) writeReset(printStream);
printStream.append(' ');
printStream.append(label.message);

if (label.hint != null) {
printStream.append('\n');

writeLineNumber(printStream, -1, maxNumbersOfDigit, true);
writeMultiLineLabel(printStream, -1, occupiedMultiLineLabels, null, characterSet.verticalBar);

printStream.append(new String(new char[mostLastPosition - insertedLen + 1]).replace('\0', ' '));
boolean resetHint = writeColor(printStream, Attribute.BRIGHT_BLUE_TEXT());
printStream.append("!hint: ");
printStream.append(label.hint);
if (resetHint) printStream.append(Ansi.RESET);
}

break;
}

Expand All @@ -296,6 +310,20 @@ public void print(final @NotNull PrintStream printStream) {
printStream.append(new String(new char[mostLastPosition]).replace('\0', characterSet.horizontalBar));
if (reset) writeReset(printStream);
printStream.format(" %s", endedLabel.message);

if (endedLabel.hint != null) {
printStream.append('\n');

writeLineNumber(printStream, -1, maxNumbersOfDigit, true);
writeMultiLineLabel(printStream, -1, occupiedMultiLineLabels, null, characterSet.verticalBar);

printStream.append(new String(new char[mostLastPosition]).replace('\0', ' '));
boolean resetHint = writeColor(printStream, Attribute.BRIGHT_BLUE_TEXT());
printStream.append("!hint: ");
printStream.append(endedLabel.hint);
if (resetHint) printStream.append(Ansi.RESET);
}

printStream.append('\n');
}
}
Expand Down Expand Up @@ -340,10 +368,17 @@ public boolean containsReport() {
return reports.isEmpty();
}

private void writeColor(final @NotNull PrintStream printStream, @Nullable Attribute... attributes) {
for (Attribute attr : attributes)
if (attr != null && enableColor)
private boolean writeColor(final @NotNull PrintStream printStream, @Nullable Attribute... attributes) {
boolean reset = false;

for (Attribute attr : attributes) {
if (attr != null && enableColor) {
printStream.append(Ansi.generateCode(attr));
reset = true;
}
}

return reset;
}

private boolean writeColor(final @NotNull PrintStream printStream, @Nullable AnsiFormat format) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/chaos/unity/nenggao/SimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public void testLongLineErrorRendering() {
FileReportBuilder.sourceFile(testFile)
.warning(Span.multipleLine(1, 0, 10, 0), "Warning No.1")
.label(Span.singleLine(1, 0, 1), "Label No.1").color(Attribute.RED_TEXT()).build()
.label(Span.singleLine(10, 0, 1), "Label No.2").color(Attribute.YELLOW_TEXT()).build()
.label(Span.singleLine(10, 0, 1), "Label No.2").color(Attribute.YELLOW_TEXT()).hint("Hint!").build()
.build()
.warning(Span.multipleLine(1, 0, 10, 0), "Warning No.2")
.label(Span.multipleLine(1, 0, 10, 1), "Label").color(Attribute.RED_TEXT()).build()
.label(Span.multipleLine(1, 0, 10, 1), "Label").color(Attribute.RED_TEXT()).hint("Hint!").build()
.build()
.print(System.out);
}
Expand Down

0 comments on commit 90a34fe

Please sign in to comment.