read-line appears to be doing something

This commit is contained in:
Danny Yoo 2011-09-25 16:09:27 -04:00
parent 98ea5bfc13
commit 1a63f418ac
5 changed files with 20 additions and 12 deletions

View File

@ -67,20 +67,20 @@
var isInputPort = baselib.makeClassPredicate(InputPort); var isInputPort = baselib.makeClassPredicate(InputPort);
var DefaultInputPort = function() { var StandardInputPort = function() {
this.content = []; this.content = [];
this.closed = false; this.closed = false;
}; };
DefaultInputPort.prototype = baselib.heir(InputPort.prototype); StandardInputPort.prototype = baselib.heir(InputPort.prototype);
DefaultInputPort.prototype.readByte = function(MACHINE) { StandardInputPort.prototype.readByte = function(MACHINE) {
if (this.content.length !== 0) { if (this.content.length !== 0) {
return this.content.shift(); return this.content.shift();
} }
return baselib.constants.EOF_VALUE; return baselib.constants.EOF_VALUE;
}; };
DefaultInputPort.prototype.callWhenReady = function(MACHINE, k) { StandardInputPort.prototype.callWhenReady = function(MACHINE, k) {
if (this.content.length > 0) { if (this.content.length > 0) {
return k(); return k();
} }
@ -89,8 +89,8 @@
} }
var that = this; var that = this;
var textFieldDiv = $("<div>" + var textFieldDiv = $("<div>" +
" <input class='readline' type='text' size='80'/>" + " <input class='readline' type='text' size='80%'/>" +
" <input class='eofread' type='button'/>"+ " <input class='eofread' type='button' value='EOF'/>"+
"</div>"); "</div>");
var readLine = textFieldDiv.find(".readline"); var readLine = textFieldDiv.find(".readline");
var eofRead = textFieldDiv.find(".eofread"); var eofRead = textFieldDiv.find(".eofread");
@ -101,14 +101,14 @@
return k(); return k();
}; };
readLine.find(".readline").keypress( readLine.keypress(
function(e) { function(e) {
var val, i; var val, i;
// On return, send the text content into that.content; // On return, send the text content into that.content;
if (e.which === 13) { if (e.which === 13) {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
val = textFieldDiv.val(); val = readLine.val();
for (i = 0; i < val.length; i++) { for (i = 0; i < val.length; i++) {
that.content.push(val.charCodeAt(i)); that.content.push(val.charCodeAt(i));
} }
@ -116,8 +116,10 @@
cleanupAndContinue(); cleanupAndContinue();
} }
}); });
eofRead.find(".eofread").click( eofRead.click(
function(e) { function(e) {
e.stopPropagation();
e.preventDefault();
that.closed = true; that.closed = true;
cleanupAndContinue(); cleanupAndContinue();
}); });
@ -135,5 +137,7 @@
exports.InputPort = InputPort; exports.InputPort = InputPort;
exports.isInputPort = isInputPort; exports.isInputPort = isInputPort;
exports.StandardInputPort = StandardInputPort;
}(this.plt.baselib, $)); }(this.plt.baselib, $));

View File

@ -334,7 +334,7 @@
inputPort = checkInputPort(M, 'read-byte', 0); inputPort = checkInputPort(M, 'read-byte', 0);
} }
plt.runtime.PAUSE(function(restart) { plt.runtime.PAUSE(function(restart) {
inputPort.callWhenReady(function() { inputPort.callWhenReady(M, function() {
restart(function(MACHINE) { restart(function(MACHINE) {
plt.runtime.finalizeClosureCall(MACHINE, plt.runtime.finalizeClosureCall(MACHINE,
inputPort.readByte(MACHINE)); inputPort.readByte(MACHINE));

View File

@ -93,6 +93,7 @@
var isOutputPort = baselib.ports.isOutputPort; var isOutputPort = baselib.ports.isOutputPort;
var StandardOutputPort = baselib.ports.StandardOutputPort; var StandardOutputPort = baselib.ports.StandardOutputPort;
var StandardErrorPort = baselib.ports.StandardErrorPort; var StandardErrorPort = baselib.ports.StandardErrorPort;
var StandardInputPort = baselib.ports.StandardInputPort;
var isOutputStringPort = baselib.ports.isOutputStringPort; var isOutputStringPort = baselib.ports.isOutputStringPort;
@ -247,6 +248,7 @@
'currentOutputPort': new StandardOutputPort(), 'currentOutputPort': new StandardOutputPort(),
'currentErrorPort': new StandardErrorPort(), 'currentErrorPort': new StandardErrorPort(),
'currentInputPort': new StandardInputPort(),
'currentSuccessHandler': function(MACHINE) {}, 'currentSuccessHandler': function(MACHINE) {},
'currentErrorHandler': function(MACHINE, exn) { 'currentErrorHandler': function(MACHINE, exn) {
MACHINE.params.currentErrorDisplayer( MACHINE.params.currentErrorDisplayer(

View File

@ -467,9 +467,11 @@ char=?
make-reader-graph make-reader-graph
make-placeholder make-placeholder
placeholder-set!) placeholder-set!
read-byte)

View File

@ -6,4 +6,4 @@
(provide version) (provide version)
(: version String) (: version String)
(define version "1.40") (define version "1.41")