Add a "Clear" button to clear the printer paper (#35)

Before, the printer "paper" would just keep accumulating changes. Now
the `printer-modal` dialog has a "clear" button that will the paper.
This commit is contained in:
Ian Flanigan 2020-10-11 17:48:16 +02:00 committed by GitHub
parent fb1320b9de
commit f991833d68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 4 deletions

View File

@ -348,6 +348,7 @@
<div class="paper"></div>
</main>
<footer class="modal__footer">
<button class="modal__btn" onclick="Apple2.clearPrinterPaper()" aria-label="Clear the paper">Clear</button>
<button class="modal__btn" data-micromodal-close aria-label="Close this dialog window">Close</button>
</footer>
</div>

View File

@ -353,6 +353,7 @@
<div class="paper"></div>
</main>
<footer class="modal__footer">
<button class="modal__btn" onclick="Apple2.clearPrinterPaper()" aria-label="Clear the paper">Clear</button>
<button class="modal__btn" data-micromodal-close aria-label="Close this dialog window">Close</button>
</footer>
</div>

View File

@ -105,7 +105,7 @@ var disk2 = new DiskII(io, driveLights, sectors);
var clock = new Thunderclock(io);
var smartport = new SmartPort(io, cpu, { block: true });
initUI(apple2, disk2, smartport, false);
initUI(apple2, disk2, smartport, printer, false);
io.setSlot(0, lc);
io.setSlot(1, parallel);

View File

@ -86,7 +86,7 @@ var disk2 = new DiskII(io, driveLights);
var clock = new Thunderclock(io);
var smartport = new SmartPort(io, cpu);
initUI(apple2, disk2, smartport, options.e);
initUI(apple2, disk2, smartport, printer, options.e);
io.setSlot(1, parallel);
io.setSlot(2, slinky);

View File

@ -35,6 +35,7 @@ var vm;
var tape;
var _disk2;
var _smartPort;
var _printer;
var audio;
var keyboard;
var io;
@ -769,7 +770,11 @@ export function openPrinterModal() {
MicroModal.show('printer-modal');
}
export function initUI(apple2, disk2, smartPort, e) {
export function clearPrinterPaper() {
_printer.clear();
}
export function initUI(apple2, disk2, smartPort, printer, e) {
_apple2 = apple2;
cpu = _apple2.getCPU();
io = _apple2.getIO();
@ -778,6 +783,7 @@ export function initUI(apple2, disk2, smartPort, e) {
tape = new Tape(io);
_disk2 = disk2;
_smartPort = smartPort;
_printer = printer;
keyboard = new KeyBoard(cpu, io, e);
keyboard.create('#keyboard');

View File

@ -9,6 +9,20 @@
* implied warranty.
*/
/**
* Printer UI. The "paper" is bound to the element selected by the input.
*
* Every line that is output to the printer is added as a <div> to the paper.
* The high bit of all characters is stripped and only visible characters are
* added to the output. The following characters receive special treatment:
*
* * `EOT` (ASCII 4): deletes last character
* * `HT` (ASCII 9): replaced with 8 spaces
* * `LF` (ASCII 10): silently removed
* * `CR` (ASCII 13): a newline and carriage return
*
* @param {string} el The selector of the element on which to bind the "paper".
*/
export default function Printer(el) {
var paper = document.querySelector(el);
var _lineBuffer = '';
@ -46,7 +60,7 @@ export default function Printer(el) {
clear: function() {
_lineBuffer = '';
paper.empty();
paper.innerHTML = "";
newLine();
},