Skip to content

Commit

Permalink
Use StylesOperator in public signatures of styled text methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGregory084 committed May 22, 2024
1 parent ccd1278 commit 8fe62b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/main/java/com/opencastsoftware/prettier4j/Doc.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package com.opencastsoftware.prettier4j;

import com.opencastsoftware.prettier4j.ansi.Attrs;
import com.opencastsoftware.prettier4j.ansi.Styles;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.function.BinaryOperator;
import java.util.function.LongUnaryOperator;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -221,7 +221,7 @@ public Doc bracket(int indent, Doc lineDoc, Doc left, Doc right) {
.append(lineDoc.append(right)));
}

public final Doc styled(LongUnaryOperator ...styles) {
public final Doc styled(Styles.StylesOperator...styles) {
return styled(this, styles);
}

Expand Down Expand Up @@ -638,9 +638,9 @@ public String toString() {

public static class Styled extends Doc {
private final Doc doc;
private final LongUnaryOperator[] styles;
private final Styles.StylesOperator[] styles;

Styled(Doc doc, LongUnaryOperator[] styles) {
Styled(Doc doc, Styles.StylesOperator[] styles) {
this.doc = doc;
this.styles = styles;
}
Expand All @@ -649,7 +649,7 @@ public Doc doc() {
return doc;
}

public LongUnaryOperator[] styles() {
public Styles.StylesOperator[] styles() {
return styles;
}

Expand Down Expand Up @@ -681,13 +681,13 @@ public String toString() {
}

public static class Escape extends Doc {
private final LongUnaryOperator[] styles;
private final Styles.StylesOperator[] styles;

public Escape(LongUnaryOperator[] styles) {
public Escape(Styles.StylesOperator[] styles) {
this.styles = styles;
}

public LongUnaryOperator[] styles() {
public Styles.StylesOperator[] styles() {
return this.styles;
}

Expand Down Expand Up @@ -842,7 +842,7 @@ public static Doc lineOr(String altText) {
return new LineOr(text(altText));
}

public static Doc styled(Doc doc, LongUnaryOperator...styles) {
public static Doc styled(Doc doc, Styles.StylesOperator ...styles) {
return new Styled(doc, styles);
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/opencastsoftware/prettier4j/ansi/Attrs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.opencastsoftware.prettier4j.ansi;

import java.util.Objects;
import java.util.function.LongUnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -34,9 +33,9 @@ public static Attrs empty() {
this.attrs = attrs;
}

public Attrs withStyles(LongUnaryOperator ...styles) {
public Attrs withStyles(Styles.StylesOperator ...styles) {
long attrs = this.attrs;
for (LongUnaryOperator style : styles) {
for (Styles.StylesOperator style : styles) {
attrs = style.applyAsLong(attrs);
}
return new Attrs(attrs);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/opencastsoftware/prettier4j/ansi/Styles.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@
import static com.opencastsoftware.prettier4j.ansi.Attrs.*;

public class Styles {
public static LongUnaryOperator fg(Color color) {
public static StylesOperator fg(Color color) {
return new Fg(color);
}

public static LongUnaryOperator bg(Color color) {
public static StylesOperator bg(Color color) {
return new Bg(color);
}

public static LongUnaryOperator bold() {
public static StylesOperator bold() {
return Bold.getInstance();
}

public static LongUnaryOperator faint() {
public static StylesOperator faint() {
return Faint.getInstance();
}

public static LongUnaryOperator italic() {
public static StylesOperator italic() {
return Italic.getInstance();
}

public static LongUnaryOperator underline() {
public static StylesOperator underline() {
return Underline.getInstance();
}

public static LongUnaryOperator blink() {
public static StylesOperator blink() {
return Blink.getInstance();
}

public static LongUnaryOperator inverse() {
public static StylesOperator inverse() {
return Inverse.getInstance();
}

public static LongUnaryOperator strikethrough() {
public static StylesOperator strikethrough() {
return Strikethrough.getInstance();
}

Expand Down Expand Up @@ -86,7 +86,7 @@ private static long withColor(long attrs, Color color, long maskValue, long shif
return noColor | (newColor << shiftValue);
}

interface StylesOperator extends LongUnaryOperator {}
public interface StylesOperator extends LongUnaryOperator {}

static class Fg implements StylesOperator {
private final Color color;
Expand Down

0 comments on commit 8fe62b4

Please sign in to comment.