Make a parsed spacer a value
So a frontend comparing snapshots of the tree sees an unchanged spacer as unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,15 +14,12 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class Spacers {
|
||||
|
||||
/** Result of parsing a spacer name. */
|
||||
public static final class Spacer {
|
||||
public final char align; // 'l', 'c', 'r', or '*' (repeat/fill)
|
||||
public final String caption;
|
||||
|
||||
Spacer(char align, String caption) {
|
||||
this.align = align;
|
||||
this.caption = caption;
|
||||
}
|
||||
/**
|
||||
* A parsed spacer name.
|
||||
*
|
||||
* @param align 'l', 'c', 'r', or '*' (repeat the caption to fill)
|
||||
*/
|
||||
public record Spacer(char align, String caption) {
|
||||
}
|
||||
|
||||
/** The tag's identifying part, which is what keeps two spacers' names apart. */
|
||||
@@ -66,18 +63,18 @@ public final class Spacers {
|
||||
|
||||
/** Builds the visible label for a spacer at roughly the given character width. */
|
||||
public static String render(Spacer s, int width) {
|
||||
String caption = s.caption == null ? "" : s.caption;
|
||||
if (s.align == '*') {
|
||||
String caption = s.caption() == null ? "" : s.caption();
|
||||
if (s.align() == '*') {
|
||||
if (caption.isEmpty()) return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (sb.length() < width) sb.append(caption);
|
||||
return sb.substring(0, Math.max(caption.length(), Math.min(sb.length(), width)));
|
||||
}
|
||||
if (s.align == 'c') {
|
||||
if (s.align() == 'c') {
|
||||
int pad = Math.max(0, (width - caption.length()) / 2);
|
||||
return " ".repeat(pad) + caption;
|
||||
}
|
||||
if (s.align == 'r') {
|
||||
if (s.align() == 'r') {
|
||||
int pad = Math.max(0, width - caption.length());
|
||||
return " ".repeat(pad) + caption;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user