Skip to content

Commit

Permalink
Implemented terminal back-scroll buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Nov 2, 2024
1 parent 078a357 commit 3995194
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
package com.maccasoft.propeller;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Event;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
Expand All @@ -23,13 +23,12 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

import com.maccasoft.propeller.SerialTerminal.Cell;

@TestInstance(Lifecycle.PER_CLASS)
class SerialTerminalTest {

Display display;
SerialTerminal instance;
int screenStart;

@BeforeAll
void initialize() {
Expand All @@ -38,26 +37,26 @@ void initialize() {

@BeforeEach
void setUp() {
instance = new SerialTerminal();
instance.display = display;
instance.shell = new Shell(display);
instance.screenWidth = 80;
instance.screenHeight = 25;
instance.screen = new Cell[instance.screenHeight][instance.screenWidth];
instance.canvas = new Canvas(instance.shell, SWT.NONE);
for (int y = 0; y < 25; y++) {
for (int x = 0; x < 80; x++) {
instance.screen[y][x] = instance.new Cell(null, null);
}
Preferences preferences = new Preferences();
preferences.setTerminalWindow(new Rectangle(0, 0, 80, 25));

instance = new SerialTerminal(display, preferences);
instance.create();
instance.shell.pack();

instance.canvas.notifyListeners(SWT.Resize, new Event());
while (display.readAndDispatch()) {

}
screenStart = instance.topRow;
}

@AfterEach
void tearDown() {
while (display.readAndDispatch()) {

}
instance.shell.dispose();
instance.dispose();
while (display.readAndDispatch()) {

}
Expand All @@ -69,71 +68,34 @@ void terminate() {
}

@Test
void testANSINoArguments() {
SerialTerminal.ANSI subject = instance.new ANSI();
subject.write((char) 0x1B);
subject.write('[');
subject.write('X');
Assertions.assertEquals(0, subject.argc);
}
void testTTYWrite() {
SerialTerminal.TTY subject = instance.new TTY();
Assertions.assertEquals(0, instance.cx);
Assertions.assertEquals(instance.topRow, instance.cy);

@Test
void testANSISingleArgument() {
SerialTerminal.ANSI subject = instance.new ANSI();
subject.write((char) 0x1B);
subject.write('[');
subject.write('1');
subject.write('2');
subject.write('X');
Assertions.assertEquals(1, subject.argc);
Assertions.assertEquals(12, subject.args[0]);
}

@Test
void testANSIMultipleArguments() {
SerialTerminal.ANSI subject = instance.new ANSI();
subject.write((char) 0x1B);
subject.write('[');
subject.write('1');
subject.write('2');
subject.write(';');
subject.write('3');
subject.write('4');
subject.write('X');
Assertions.assertEquals(2, subject.argc);
Assertions.assertEquals(12, subject.args[0]);
Assertions.assertEquals(34, subject.args[1]);
Assertions.assertEquals(1, instance.cx);
Assertions.assertEquals(screenStart, instance.cy);
Assertions.assertEquals('X', instance.screen[instance.cy][instance.cx - 1].character);
}

@Test
void testANSICursorPosition() {
SerialTerminal.ANSI subject = instance.new ANSI();
subject.write((char) 0x1B);
subject.write('[');
subject.write('1');
subject.write('2');
subject.write(';');
subject.write('2');
subject.write('H');
Assertions.assertEquals(12 - 1, instance.cy);
Assertions.assertEquals(2 - 1, instance.cx);
subject.write("\033[12;20H");
Assertions.assertEquals(screenStart + 12 - 1, instance.cy);
Assertions.assertEquals(19, instance.cx);
}

@Test
void testANSIColor() {
SerialTerminal.ANSI subject = instance.new ANSI();
subject.write((char) 0x1B);
subject.write('[');
subject.write('3');
subject.write('1');
subject.write(';');
subject.write('4');
subject.write('2');
subject.write('m');
subject.write('A');
Assertions.assertEquals('A', instance.screen[0][0].character);
Assertions.assertEquals(subject.colors[1], instance.screen[0][0].foreground.getRGB());
Assertions.assertEquals(subject.colors[2], instance.screen[0][0].background.getRGB());
subject.write("\033[31;42mA");
SerialTerminal.Cell cell = instance.screen[instance.cy][instance.cx - 1];
Assertions.assertEquals('A', cell.character);
Assertions.assertEquals(instance.colors[1], cell.foreground);
Assertions.assertEquals(instance.colors[2], cell.background);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ public void save() throws IOException {
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
mapper.setSerializationInclusion(Include.NON_DEFAULT);
mapper.writeValue(preferencesFile, preferences);
if (instance == this) {
mapper.writeValue(preferencesFile, preferences);
}
}
}
Loading

0 comments on commit 3995194

Please sign in to comment.