gnodet-bot commented on code in PR #14142:
URL: https://github.com/apache/maven/pull/14142#discussion_r4722087726
##########
compat/maven-embedder/src/main/java/org/fusesource/jansi/Ansi.java:
##########
@@ -350,6 +350,54 @@ public Ansi restoreCursorPosition() {
public Ansi reset() {
return this;
}
+
+ @Override
+ public Ansi render(final String text) {
+ return a(renderPlain(text));
+ }
+
+ @Override
+ public Ansi render(final String text, Object... args) {
+ return a(String.format(renderPlain(text), args));
+ }
+ }
+
+ private static String renderPlain(final String text) {
Review Comment:
`renderPlain` is exclusively used by `NoAnsi`, but it's placed as a `private
static` method on the outer `Ansi` class. It would be cleaner to move it inside
`NoAnsi`:
```java
private static class NoAnsi extends Ansi {
// ... existing overrides ...
@Override
public Ansi render(final String text) { ... }
@Override
public Ansi render(final String text, Object... args) { ... }
private static String renderPlain(final String text) { ... }
}
```
As written it works fine (private so no API leakage), but keeping
implementation details with the type that uses them avoids implying it has
broader applicability.
##########
compat/maven-embedder/src/main/java/org/fusesource/jansi/Ansi.java:
##########
@@ -350,6 +350,54 @@ public Ansi restoreCursorPosition() {
public Ansi reset() {
return this;
}
+
+ @Override
+ public Ansi render(final String text) {
+ return a(renderPlain(text));
+ }
+
+ @Override
+ public Ansi render(final String text, Object... args) {
+ return a(String.format(renderPlain(text), args));
+ }
+ }
+
+ private static String renderPlain(final String text) {
+ int j = text.indexOf(org.jline.jansi.AnsiRenderer.BEGIN_TOKEN);
+ if (j == -1) {
+ return text;
+ }
+ StringBuilder sb = new StringBuilder(text.length());
+ int idx = 0;
+ while (true) {
+ sb.append(text, idx, j);
+ int k = text.indexOf(org.jline.jansi.AnsiRenderer.END_TOKEN, j);
+ if (k == -1) {
+ sb.append(text, j, text.length());
+ return sb.toString();
+ }
+ int contentStart = j +
org.jline.jansi.AnsiRenderer.BEGIN_TOKEN.length();
+ if (k < contentStart) {
+ throw new IllegalArgumentException("Invalid input string
found.");
+ }
+ String spec = text.substring(contentStart, k);
+ int spaceIdx = spec.indexOf(' ');
+ if (spaceIdx == -1) {
+ sb.append(text, j, text.length());
+ return sb.toString();
+ }
+ String codes = spec.substring(0, spaceIdx);
+ for (String code : codes.split(",")) {
+
org.jline.jansi.AnsiRenderer.Code.valueOf(code.toUpperCase(java.util.Locale.ENGLISH));
Review Comment:
The return value of `Code.valueOf(...)` is discarded — it's called purely
for the `IllegalArgumentException` it throws on unknown codes. This looks like
dead code at first glance. A short comment would clarify intent:
```java
// Validate: throws IllegalArgumentException for unknown codes, matching
enabled-path behaviour
org.jline.jansi.AnsiRenderer.Code.valueOf(code.toUpperCase(java.util.Locale.ENGLISH));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]