Implement basic scrolling in emu.js

This commit is contained in:
2026-03-01 20:42:47 +00:00
parent 259aa730f7
commit 832ce55108

12
emu.js
View File

@@ -142,6 +142,8 @@ class Emulator {
this.cursor_move(1, 0); this.cursor_move(1, 0);
} else if (e.key == 'Enter') { } else if (e.key == 'Enter') {
this.cursor.y = this.range.end.y + 1; this.cursor.y = this.range.end.y + 1;
if (this.cursor.y >= ROWS)
this.scroll();
this.cursor.x = 0; this.cursor.x = 0;
this.submit_line(); this.submit_line();
Object.assign(this.range.start, this.cursor); Object.assign(this.range.start, this.cursor);
@@ -239,6 +241,8 @@ class Emulator {
this.grid[cell.y][cell.x] = this.grid[prev.y][prev.x]; this.grid[cell.y][cell.x] = this.grid[prev.y][prev.x];
cell = prev; cell = prev;
} }
if (this.next_cell(this.range.end) == null)
this.scroll();
this.range.end = this.next_cell(this.range.end); this.range.end = this.next_cell(this.range.end);
} }
@@ -283,6 +287,14 @@ class Emulator {
return c; return c;
} }
} }
scroll() {
this.grid.shift()
this.grid.push(new Array(COLS).fill(' '));
this.cursor.y -= 1;
this.range.start.y -= 1;
this.range.end.y -= 1;
}
} }
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {