Skip to content

Commit

Permalink
Rename Color256 to ColorXterm
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGregory084 committed May 24, 2024
1 parent 7a70df2 commit 83d1d97
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private Color color(ColorType colorType, long shiftValue) {
case COLOR_16:
return Color16.withCode(colorBits);
case COLOR_256:
return new Color256(colorBits);
return new ColorXterm(colorBits);
case COLOR_RGB:
return ColorRgb.fromPacked(colorBits);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/opencastsoftware/prettier4j/ansi/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ static Color brightWhite() {
return Color16.BRIGHT_WHITE;
}

static Color xterm256(int color) {
return new Color256(color);
static Color xterm(int color) {
return new ColorXterm(color);
}

static Color rgb(int r, int g, int b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import java.util.Objects;

class Color256 implements Color {
class ColorXterm implements Color {
public final int color;

Color256(int color) {
ColorXterm(int color) {
this.color = color & 0xFF;
}

Expand All @@ -36,8 +36,8 @@ public ColorType colorType() {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Color256 color256 = (Color256) o;
return color == color256.color;
ColorXterm colorXterm = (ColorXterm) o;
return color == colorXterm.color;
}

@Override
Expand All @@ -47,7 +47,7 @@ public int hashCode() {

@Override
public String toString() {
return "Color256 [" +
return "ColorXterm [" +
"color=" + color +
']';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private static long withColor(long attrs, Color color, long maskValue, long shif
newColor = color16.code();
break;
case COLOR_256:
Color256 color256 = (Color256) color;
newColor = color256.color();
ColorXterm colorXterm = (ColorXterm) color;
newColor = colorXterm.color();
break;
case COLOR_RGB:
ColorRgb colorRgb = (ColorRgb) color;
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/com/opencastsoftware/prettier4j/DocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void testNested16ColorFgStyleFlattening() {
@Test
void test256ColorFgStyle() {
String expected = xtermFgCode(128) + "a" + Ansi.RESET;
String actual = text("a").styled(Styles.fg(Color.xterm256(128))).render(80);
String actual = text("a").styled(Styles.fg(Color.xterm(128))).render(80);
char[] expectedChars = expected.toCharArray();
char[] actualChars = actual.toCharArray();
assertThat(actualChars, is(equalTo(expectedChars)));
Expand All @@ -579,11 +579,11 @@ void testNested256ColorFgStyle() {
xtermFgCode(37) + 'b' +
xtermFgCode(255) + ')' + Ansi.RESET;

String actual = text("a").styled(Styles.fg(Color.xterm256(128)))
String actual = text("a").styled(Styles.fg(Color.xterm(128)))
.append(text(","))
.appendSpace(text("b").styled(Styles.fg(Color.xterm256(37))))
.appendSpace(text("b").styled(Styles.fg(Color.xterm(37))))
.bracket(2, Doc.lineOrEmpty(), text("("), text(")"))
.styled(Styles.fg(Color.xterm256(255)))
.styled(Styles.fg(Color.xterm(255)))
.render(6);

char[] expectedChars = expected.toCharArray();
Expand All @@ -601,11 +601,11 @@ void testNested256ColorFgStyleFlattening() {
')' + Ansi.RESET;

// expanded layout should still break over multiple lines
String actual = text("a").styled(Styles.fg(Color.xterm256(128)))
String actual = text("a").styled(Styles.fg(Color.xterm(128)))
.append(text(","))
.appendLineOrSpace(text("b").styled(Styles.fg(Color.xterm256(37))))
.appendLineOrSpace(text("b").styled(Styles.fg(Color.xterm(37))))
.bracket(2, Doc.lineOrEmpty(), text("("), text(")"))
.styled(Styles.fg(Color.xterm256(255)))
.styled(Styles.fg(Color.xterm(255)))
.render(1);

char[] expectedChars = expected.toCharArray();
Expand Down Expand Up @@ -797,7 +797,7 @@ void testNested16ColorBgStyleFlattening() {
@Test
void test256ColorBgStyle() {
String expected = xtermBgCode(128) + "a" + Ansi.RESET;
String actual = text("a").styled(Styles.bg(Color.xterm256(128))).render(80);
String actual = text("a").styled(Styles.bg(Color.xterm(128))).render(80);
char[] expectedChars = expected.toCharArray();
char[] actualChars = actual.toCharArray();
assertThat(actualChars, is(equalTo(expectedChars)));
Expand All @@ -812,11 +812,11 @@ void testNested256ColorBgStyle() {
xtermBgCode(37) + 'b' +
xtermBgCode(255) + ')' + Ansi.RESET;

String actual = text("a").styled(Styles.bg(Color.xterm256(128)))
String actual = text("a").styled(Styles.bg(Color.xterm(128)))
.append(text(","))
.appendSpace(text("b").styled(Styles.bg(Color.xterm256(37))))
.appendSpace(text("b").styled(Styles.bg(Color.xterm(37))))
.bracket(2, Doc.lineOrEmpty(), text("("), text(")"))
.styled(Styles.bg(Color.xterm256(255)))
.styled(Styles.bg(Color.xterm(255)))
.render(6);

char[] expectedChars = expected.toCharArray();
Expand All @@ -834,11 +834,11 @@ void testNested256ColorBgStyleFlattening() {
')' + Ansi.RESET;

// expanded layout should still break over multiple lines
String actual = text("a").styled(Styles.fg(Color.xterm256(128)))
String actual = text("a").styled(Styles.fg(Color.xterm(128)))
.append(text(","))
.appendLineOrSpace(text("b").styled(Styles.fg(Color.xterm256(37))))
.appendLineOrSpace(text("b").styled(Styles.fg(Color.xterm(37))))
.bracket(2, Doc.lineOrEmpty(), text("("), text(")"))
.styled(Styles.fg(Color.xterm256(255)))
.styled(Styles.fg(Color.xterm(255)))
.render(1);

char[] expectedChars = expected.toCharArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Arbitrary<Color> colors() {
Arbitraries.create(Color::brightWhite),

Arbitraries.integers().between(0, 255)
.map(Color::xterm256),
.map(Color::xterm),

Arbitraries.integers().between(0, 255)
.tuple3().map(t -> Color.rgb(t.get1(), t.get2(), t.get3()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class ColorTest {
void testEquals() {
EqualsVerifier.forClasses(
Color.class, Color16.class,
Color256.class, ColorRgb.class)
ColorXterm.class, ColorRgb.class)
.usingGetClass().verify();
}

@Test
void testToString() {
ToStringVerifier.forClasses(Color16.class, Color256.class, ColorRgb.class).verify();
ToStringVerifier.forClasses(Color16.class, ColorXterm.class, ColorRgb.class).verify();
}

@Property
Expand Down

0 comments on commit 83d1d97

Please sign in to comment.