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
2 changes: 1 addition & 1 deletion src/main/java/li/cil/oc2/common/vm/terminal/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
private transient int lastSentPaletteRevision = -1;
public byte style;

public int SCROLL_BACK_COUNT = 20;
public static final int SCROLL_BACK_COUNT = 20;
public transient ByteArrayFIFOQueue input = new ByteArrayFIFOQueue(32);
// DECCOLM dynamic width; setWidth reallocates buffers. Transient: re-inits to WIDTH on load.
public transient int width = WIDTH;
Expand Down Expand Up @@ -363,7 +363,7 @@
}

/** Dirty state since the last consume: full-refresh request plus changed buffer rows. */
public record NetworkDirty(boolean fullRefresh, int[] rows) {}

Check warning on line 366 in src/main/java/li/cil/oc2/common/vm/terminal/Terminal.java

View workflow job for this annotation

GitHub Actions / build

[ArrayRecordComponent] Record components should not be arrays.

public NetworkDirty consumeNetworkDirty() {
networkDirtyLock.lock();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
private static final int PALETTE_SIZE = 256;

/**
* @param rows absolute buffer row indices (alt-buffer: screen rows 0..23)

Check warning on line 56 in src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java

View workflow job for this annotation

GitHub Actions / build

[MissingSummary] A summary line is required on public/protected Javadocs.
* @param rowData serialized cell data, one array per entry of {@code rows}
*/
public record Snapshot(
boolean reset,
int width,
boolean altBuffer,
int[] rows,

Check warning on line 63 in src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java

View workflow job for this annotation

GitHub Actions / build

[ArrayRecordComponent] Record components should not be arrays.
byte[][] rowData,

Check warning on line 64 in src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java

View workflow job for this annotation

GitHub Actions / build

[ArrayRecordComponent] Record components should not be arrays.
int cursorX,
int cursorY,
int lastRowToDisplay,
Expand All @@ -70,7 +70,7 @@
boolean cursorVisible,
boolean bell,
long inputModes,
int[] palette) {}

Check warning on line 73 in src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java

View workflow job for this annotation

GitHub Actions / build

[ArrayRecordComponent] Record components should not be arrays.

/**
* Private-mode flags that affect client-side rendering or input handling beyond the
Expand Down Expand Up @@ -176,7 +176,7 @@
}
// Main buffer: the currently displayed scrollback window.
final int first = Math.max(0, terminal.lastRowToDisplay - Terminal.HEIGHT);
final int count = Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT - first;
final int count = Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT - first;
final int[] rows = new int[Math.min(Terminal.HEIGHT, count)];
for (int i = 0; i < rows.length; i++) {
rows[i] = first + i;
Expand Down Expand Up @@ -242,7 +242,7 @@

/** Packs mode ordinal (3 bits) plus 8-bit R/G/B into a single varint-friendly value. */
private static int packColor(final ColorData color) {
return (color.mode.ordinal() & 0x7)

Check warning on line 245 in src/main/java/li/cil/oc2/common/vm/terminal/TerminalDiff.java

View workflow job for this annotation

GitHub Actions / build

[EnumOrdinal] You should almost never invoke the Enum.ordinal() method or depend on the enum values by index.
| (color.r & 0xFF) << 3
| (color.g & 0xFF) << 11
| (color.b & 0xFF) << 19;
Expand Down Expand Up @@ -360,7 +360,7 @@
private static void deserializeRow(
final Terminal terminal, final boolean alt, final int row, final byte[] data) {
if (row < 0
|| (alt ? row >= Terminal.HEIGHT : row >= Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT)) {
|| (alt ? row >= Terminal.HEIGHT : row >= Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT)) {
return;
}
final ByteBuffer buf = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void incrementLastLineToDisplay(boolean scroll) {
terminal.lastRowToDisplayMax =
Math.min(
terminal.lastRowToDisplayMax + 1,
Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT);
Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT);
} else if (terminal.lastRowToDisplay == terminal.lastRowToDisplayMax) {
return;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ public void shiftUp(int count) {
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
shiftLines(terminal.scrollFirst + 1, terminal.scrollLast, -count);
} else {
if (terminal.lastRowToDisplay == Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT
if (terminal.lastRowToDisplay == Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT
|| terminal.scrollLast != Terminal.HEIGHT - 1
|| terminal.scrollFirst != 0) {
shiftLines(
Expand All @@ -65,7 +65,7 @@ public void shiftUp(int count) {
: 1,
terminal.scrollLast != Terminal.HEIGHT - 1
? terminal.scrollLast + terminal.lastRowToDisplayMax - Terminal.HEIGHT
: (Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT) - 1,
: (Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT) - 1,
-count);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void execute(final int[] args, final int argsCount, final CSIState state)
final int n = Math.min(args[0], Terminal.HEIGHT);
for (int i = 0; i < n; i++) {
if (terminal.lastRowToDisplay
< Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT) {
< Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT) {
terminal.bufferManager.incrementLastLineToDisplay();
}
terminal.bufferManager.shiftUpOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void initialBufferState() {
assertEquals(0, terminal.y);
assertEquals(24, terminal.lastRowToDisplay);
assertEquals(24, terminal.lastRowToDisplayMax);
assertEquals(Terminal.WIDTH * Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT, terminal.buffer.length);
assertEquals(Terminal.WIDTH * Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT, terminal.buffer.length);
assertEquals(' ', charAt(0, 0));
assertEquals(' ', charAt(Terminal.WIDTH - 1, Terminal.HEIGHT - 1));
assertFalse(terminal.currentPrivateModeState.isAltBufferEnabled());
Expand Down Expand Up @@ -1442,7 +1442,7 @@ void deccolmSwitchesColumnWidthAndClearsScreen() {
write(terminal, CSI + "?3h");
assertTrue(terminal.currentPrivateModeState.DECCOLM, "?3h enables DECCOLM");
assertEquals(132, terminal.getTerminalWidth(), "DECCOLM switches to 132 columns");
final int expected132 = 132 * Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT;
final int expected132 = 132 * Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT;
assertEquals(expected132, terminal.buffer.length, "buffers reallocate to 132 columns");
assertEquals(0xFFFFFF, renderer.dirtyMask.get() & 0xFFFFFF,
"DECCOLM must redraw the whole screen");
Expand All @@ -1464,7 +1464,7 @@ void deccolmSwitchesColumnWidthAndClearsScreen() {
write(terminal, CSI + "?3l");
assertFalse(terminal.currentPrivateModeState.DECCOLM, "?3l disables DECCOLM");
assertEquals(Terminal.WIDTH, terminal.getTerminalWidth(), "reset returns to 80 columns");
final int expected80 = Terminal.WIDTH * Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT;
final int expected80 = Terminal.WIDTH * Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT;
assertEquals(expected80, terminal.buffer.length, "buffers reallocate back to 80 columns");
}

Expand Down Expand Up @@ -1590,7 +1590,7 @@ void scrollDownAtFullScrollbackDoesNotOverflow() {
// SD (CSI T) / RI used to arraycopy past the physical buffer end
// (AIOOBE under lock in putOutput -> terminal dead forever).
writeMarkers();
assertEquals(Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT, terminal.lastRowToDisplayMax,
assertEquals(Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT, terminal.lastRowToDisplayMax,
"precondition: scrollback filled to cap");
// Marker two rows above the discarded pair: survives the shift onto the last row.
final int bottomMarkerRow = Terminal.HEIGHT - 3;
Expand Down Expand Up @@ -1630,7 +1630,7 @@ void scrollUpDownWithHugeCountTerminates() {
private void writeMarkers() {
// Grow the scrollback window to its hard cap (HEIGHT * SCROLL_BACK_COUNT rows).
final StringBuilder feed = new StringBuilder();
feed.append("\n".repeat(Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT));
feed.append("\n".repeat(Terminal.HEIGHT * Terminal.SCROLL_BACK_COUNT));
write(terminal, feed.toString());
}
}
Loading