Implement basic scrolling in emu.js
This commit is contained in:
12
emu.js
12
emu.js
@@ -142,6 +142,8 @@ class Emulator {
|
||||
this.cursor_move(1, 0);
|
||||
} else if (e.key == 'Enter') {
|
||||
this.cursor.y = this.range.end.y + 1;
|
||||
if (this.cursor.y >= ROWS)
|
||||
this.scroll();
|
||||
this.cursor.x = 0;
|
||||
this.submit_line();
|
||||
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];
|
||||
cell = prev;
|
||||
}
|
||||
if (this.next_cell(this.range.end) == null)
|
||||
this.scroll();
|
||||
this.range.end = this.next_cell(this.range.end);
|
||||
}
|
||||
|
||||
@@ -283,6 +287,14 @@ class Emulator {
|
||||
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', () => {
|
||||
|
||||
Reference in New Issue
Block a user