Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import com.google.gson.annotations.SerializedName;

public final class TerminalColors {
public static final int[] BRIGHT_COLORS = {

Check warning on line 6 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[MutablePublicArray] Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.
0x555555, 0xFF5555, 0x55FF55, 0xFFFF55,
0x5555FF, 0xFF55FF, 0x55FFFF, 0xFFFFFF,
};

public static final int[] COLORS = {

Check warning on line 11 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[MutablePublicArray] Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.
0x000000, 0xAA0000, 0x00AA00, 0xAAAA00,
0x0000AA, 0xAA00AA, 0x00AAAA, 0xAAAAAA,
};

public static final int[] DIM_COLORS = {

Check warning on line 16 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[MutablePublicArray] Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.
0x000000, 0x550000, 0x005500, 0x555500,
0x000055, 0x550055, 0x005555, 0x555555,
};

public static final int[] COLORS_256 = {

Check warning on line 21 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[MutablePublicArray] Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.
// 0-7: Normal ANSI colors (must match COLORS)
0x000000, 0xAA0000, 0x00AA00, 0xAAAA00, 0x0000AA, 0xAA00AA, 0x00AAAA, 0xAAAAAA,
// 8-15: Bright ANSI colors (must match BRIGHT_COLORS)
Expand All @@ -43,13 +43,13 @@
0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff,
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f,
0xd75f87, 0xd75faf, 0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af,
0xd787d7, 0xd787ff, 0xdfaf00, 0xdfaf5f, 0xdfaf87, 0xdfafaf, 0xdfafdf, 0xdfafff,
0xdfdf00, 0xdfdf5f, 0xdfdf87, 0xdfdfaf, 0xdfdfdf, 0xdfdfff, 0xdfff00, 0xdfff5f,
0xdfff87, 0xdfffaf, 0xdfffdf, 0xdfffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
0xff00df, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fdf, 0xff5fff,
0xff8700, 0xff875f, 0xff8787, 0xff87af, 0xff87df, 0xff87ff, 0xffaf00, 0xffaf5f,
0xffaf87, 0xffafaf, 0xffafdf, 0xffafff, 0xffdf00, 0xffdf5f, 0xffdf87, 0xffdfaf,
0xffdfdf, 0xffdfff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffdf, 0xffffff,
0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f, 0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff,
0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff, 0xd7ff00, 0xd7ff5f,
0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fd7, 0xff5fff,
0xff8700, 0xff875f, 0xff8787, 0xff87af, 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f,
0xffaf87, 0xffafaf, 0xffafd7, 0xffafff, 0xffd700, 0xffd75f, 0xffd787, 0xffd7af,
0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffd7, 0xffffff,
0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e,
0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
Expand Down Expand Up @@ -128,7 +128,7 @@
Mode = ColorMode.SIXTEEN_COLOR;
}

public ColorData(final int r, final int g, final int b, final ColorMode mode) {

Check warning on line 131 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[InconsistentCapitalization] Found the field 'Mode' with the same name as the parameter 'mode' but with different capitalization.

Check warning on line 131 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[InconsistentCapitalization] Found the field 'B' with the same name as the parameter 'b' but with different capitalization.

Check warning on line 131 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[InconsistentCapitalization] Found the field 'G' with the same name as the parameter 'g' but with different capitalization.

Check warning on line 131 in src/main/java/li/cil/oc2/common/vm/terminal/color/TerminalColors.java

View workflow job for this annotation

GitHub Actions / build

[InconsistentCapitalization] Found the field 'R' with the same name as the parameter 'r' but with different capitalization.
R = r;
G = g;
B = b;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package li.cil.oc2.common.vm.terminal.color;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class TerminalColorsTest {

@Test
void xterm256PaletteMatchesCanonicalFormula() {
// §36 m7: xterm-256 color cube is (16 + 36*r + 6*g + b) with per-channel levels [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff].
// The COLORS_256 array had 29 mis-typed entries using 0xdf instead of 0xd7 for the level-4 component.
// This test checks a few key canonical indices.

// Level-4 (0xd7) red, level-4 green, level-4 blue (not level-5): index 188 = 16 + 36*4 + 6*4 + 4
assertEquals(0xd7d7d7, TerminalColors.COLORS_256[188],
"index 188 (R=4,G=4,B=4) should be 0xd7d7d7 (was mis-typed as 0xdfdfdf)");

// R=4, G=3, B=0: index 178 = 16 + 36*4 + 6*3 + 0
assertEquals(0xd7af00, TerminalColors.COLORS_256[178],
"index 178 (R=4,G=3,B=0) should be 0xd7af00 (was mis-typed as 0xdfaf00)");

// R=5, G=5, B=4: index 230 = 16 + 36*5 + 6*5 + 4
assertEquals(0xffffd7, TerminalColors.COLORS_256[230],
"index 230 (R=5,G=5,B=4) should be 0xffffd7 (was mis-typed as 0xffffdf)");

// R=5, G=4, B=0: index 220 = 16 + 36*5 + 6*4 + 0
assertEquals(0xffd700, TerminalColors.COLORS_256[220],
"index 220 (R=5,G=4,B=0) should be 0xffd700 (was mis-typed as 0xffdf00)");

// Verify no 0xdf entries exist in the cube region (16-231)
for (int i = 16; i < 232; i++) {
String hex = String.format("%06x", TerminalColors.COLORS_256[i]);
assertFalse(hex.contains("df"),
"index " + i + " should not contain 'df' (0xdf is not a valid xterm-256 level component)");
}
}
}
Loading