The Component printBuffer should only be used by Component static functions

This commit is contained in:
Jeff Parsons 2017-06-29 08:38:02 -07:00 committed by Jeff Parsons
commit 061c839a33
27 changed files with 344 additions and 265 deletions

View file

@ -60,7 +60,8 @@ l.toString=function(){return this.name?this.name:this.id||this.type};
l.da=function(a,b,c){switch(b){case "clear":return this.P[b]||(this.P[b]=c,c.onclick=function(a){return function(){a.P.print&&(a.P.print.value="")}}(this)),!0;case "print":return this.P[b]||(this.P[b]=c,this.aa=function(a){this.i(a,this.type);return!0},c.value="",this.print=function(a){return function(b){lb(a,b)}}(c),this.i=function(a,b){return function(a,c){a||(a="");if(c!=zb.kd||"..."!=a.slice(-3))c&&(a=c+": "+a),lb(b,a+"\n");else{c=b.value;var d=c.lastIndexOf(a);0>d?c+=a+"\n":c=c.substr(0,d)+(a+
".")+c.substr(d+a.length);8192<c.length&&(c=c.substr(c.length-4096));b.value=c;b.scrollTop=b.scrollHeight}}}(this,c)),!0;default:return!1}};l.log=function(){};l.print=function(){};l.i=function(){};l.status=function(a){this.i(this.type+": "+a)};l.aa=function(a,b,c){if(!b){var d=sb("Computer",this.id);if(d&&d.F.Qb)return console.log("ignoring notice during unload: "+a),!1}Za(a,b,c||this.type);return!0};function Ab(a,b){a.F.error=!0;a.aa(b)}
function Bb(a,b){b&&(a.F.ready?b():a.xb=b);return a.F.ready}function Cb(a){if(!a.F.error&&(a.F.ready=!0,a.F.ready)){var b=a.xb;a.xb=null;b&&b()}}function Db(a,b){a.F.kb&&(b?a.F.Hb=!0:void 0===b&&a.i(a.toString()+" busy"));return a.F.kb}function Eb(a,b){if(a.F.Hb)return a.F.kb=!1,a.F.Hb=!1;if(a.F.error)return a.i(a.toString()+" error"),!1;a.F.kb=b;return a.F.kb}l.va=function(){return this.F.ja=!0};l.ua=function(a,b){b&&(this.F.ja=!1);return!0};
function Fb(a,b){if(a.K){a===a.K?b|=0:b=b||a.ha;var c=a.K.ha&b;return!!b&&c===b||!!(c&a.K.xd)}return!1}function Gb(a,b){a.K&&Fb(a,0)&&a.K.message(b,void 0)}function x(a,b,c,d,e,f,g){a.K&&(!0===g?g=0:null==g&&(g=a.ha),Hb(a.K,a,b,c,d,e,f,g))}var zb={wf:"notice",Pf:"warning",ERROR:"error",kd:"progress"};window&&(window.PCjs||(window.PCjs={}),window.PCjs.Machines||(window.PCjs.Machines={}),window.PCjs.Components||(window.PCjs.Components=[]),window.PCjs.Commands||(window.PCjs.Commands={}));
function Fb(a,b){if(a.K){a===a.K?b|=0:b=b||a.ha;var c=a.K.ha&b;return!!b&&c===b||!!(c&a.K.xd)}return!1}function Gb(a,b){a.K&&Fb(a,0)&&a.K.message(b,void 0)}function x(a,b,c,d,e,f,g){a.K&&(!0===g?g=0:null==g&&(g=a.ha),Hb(a.K,a,b,c,d,e,f,g))}var zb={ERROR:"error",wf:"notice",kd:"progress",SCRIPT:"script",Pf:"warning"};
window&&(window.PCjs||(window.PCjs={}),window.PCjs.Machines||(window.PCjs.Machines={}),window.PCjs.Components||(window.PCjs.Components=[]),window.PCjs.Commands||(window.PCjs.Commands={}));
var ib=window?window.PCjs.Machines:{},gb=window?window.PCjs.Components:[],ub=window?window.PCjs.Commands:{},vb=["hold","sleep","wait"],xb={alert:function(a){r(a);return!0},sleep:function(a,b){setTimeout(a,+b);return!1}},yb={select:function(a,b,c){var d=!1;if(a=a.bindings[b])for(b=0;b<a.options.length;b++)if(a.options[b].textContent==c){a.selectedIndex!=b&&(a.selectedIndex=b);d=!0;break}return d}};
Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){b=b||0;for(var c=this.length;b<c;b++)if(this[b]===a)return b;return-1});Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)});
Function.prototype.bind||(Function.prototype.bind=function(a){function b(){return e.apply(this instanceof c&&a?this:a,d.concat(Array.prototype.slice.call(arguments)))}function c(){}if("function"!=typeof this)throw new TypeError("Function.prototype.bind: non-callable object");var d=Array.prototype.slice.call(arguments,1),e=this;c.prototype=this.prototype;b.prototype=new c;return b});

File diff suppressed because one or more lines are too long

View file

@ -950,7 +950,7 @@ class Str {
}
/**
* replace(sFind, sReplace, s)
* replace(sSearch, sReplace, s)
*
* The JavaScript replace() function ALWAYS interprets "$" specially in replacement strings, even when
* the search string is NOT a RegExp; specifically:
@ -965,36 +965,36 @@ class Str {
* So, if a replacement string containing dollar signs passes through a series of replace() calls, untold
* problems could result. Hence, this function, which simply uses the replacement string as-is.
*
* Similar to the JavaScript replace() method, this replaces only one occurrence (ie, the FIRST occurrence);
* it might be nice to add options to replace the LAST occurrence and/or ALL occurrences, but we'll revisit
* that later.
* Similar to the JavaScript replace() method (when sSearch is a string), this replaces only ONE occurrence
* (ie, the FIRST occurrence); it might be nice to add options to replace the LAST occurrence and/or ALL
* occurrences, but we'll revisit that later.
*
* @param {string} sFind
* @param {string} sSearch
* @param {string} sReplace
* @param {string} s
* @return {string}
*/
static replace(sFind, sReplace, s)
static replace(sSearch, sReplace, s)
{
var i = s.indexOf(sFind);
var i = s.indexOf(sSearch);
if (i >= 0) {
s = s.substr(0, i) + sReplace + s.substr(i + sFind.length);
s = s.substr(0, i) + sReplace + s.substr(i + sSearch.length);
}
return s;
}
/**
* replaceAll(sFind, sReplace, s)
* replaceAll(sSearch, sReplace, s)
*
* @param {string} sFind
* @param {string} sSearch
* @param {string} sReplace
* @param {string} s
* @return {string}
*/
static replaceAll(sFind, sReplace, s)
static replaceAll(sSearch, sReplace, s)
{
var a = {};
a[sFind] = sReplace;
a[sSearch] = sReplace;
return Str.replaceArray(a, s);
}
@ -2692,14 +2692,34 @@ class Component {
}
}
/**
* Component.print(s)
*
* Components that inherit from this class should use this.print(), rather than Component.print(), because
* if a Control Panel is loaded, it will override only the instance method, not the class method (overriding the
* class method would improperly affect any other machines loaded on the same page).
*
* @this {Component}
* @param {string} s
*/
static print(s)
{
if (!COMPILED) {
var i = s.lastIndexOf('\n');
if (i >= 0) {
Component.println(s.substr(0, i));
s = s.substr(i + 1);
}
Component.printBuffer += s;
}
}
/**
* Component.println(s, type, id)
*
* For non-diagnostic messages, which components may override to control the destination/appearance of their output.
*
* Components that inherit from this class should use the instance method, this.println(), rather than Component.println(),
* because if a Control Panel is loaded, it will override only the instance method, not the class method (overriding the class
* method would improperly affect any other machines loaded on the same page).
* Components that inherit from this class should use this.println(), rather than Component.println(), because
* if a Control Panel is loaded, it will override only the instance method, not the class method (overriding the
* class method would improperly affect any other machines loaded on the same page).
*
* @param {string} [s] is the message text
* @param {string} [type] is the message type
@ -2708,7 +2728,9 @@ class Component {
static println(s, type, id)
{
if (!COMPILED) {
s = Component.printBuffer + (s || "");
Component.log((id? (id + ": ") : "") + (s? ("\"" + s + "\"") : ""), type);
Component.printBuffer = "";
}
}
@ -2830,9 +2852,6 @@ class Component {
*/
static replaceControl(control, sSearch, sReplace)
{
/*
* Prevent the <textarea> from getting too large; otherwise, printing becomes slower and slower.
*/
var sText = control.value;
var i = sText.lastIndexOf(sSearch);
if (i < 0) {
@ -2840,6 +2859,9 @@ class Component {
} else {
sText = sText.substr(0, i) + sReplace + sText.substr(i + sSearch.length);
}
/*
* Prevent the <textarea> from getting too large; otherwise, printing becomes slower and slower.
*/
if (COMPILED && sText.length > 8192) sText = sText.substr(sText.length - 4096);
control.value = sText;
control.scrollTop = control.scrollHeight;
@ -3104,7 +3126,7 @@ class Component {
* ^J ^M ^K ^I ^H ^L
*
* To support any other non-printable 8-bit character, such as ESC, you should use \xXX, where XX
* is the ASCII code in hex. For ESC, that would \x1B.
* is the ASCII code in hex. For ESC, that would be \x1B.
*
* @param {string} sScript
* @return {Array}
@ -3202,7 +3224,7 @@ class Component {
* instead, but it's a bit too confusing mingling script output in a window that
* already mingles Debugger and machine output.
*/
Component.println('script: ' + aTokens.join(' '));
Component.println(aTokens.join(' '), Component.TYPE.SCRIPT);
var fnCallReady = null;
if (Component.asyncCommands.indexOf(sCommand) >= 0) {
@ -3484,8 +3506,6 @@ class Component {
/**
* print(s)
*
* For non-diagnostic messages, which components may override to control the destination/appearance of their output.
*
* Components using this.print() should wait until after their constructor has run to display any messages, because
* if a Control Panel has been loaded, its override will not take effect until its own constructor has run.
*
@ -3494,19 +3514,12 @@ class Component {
*/
print(s)
{
var i = s.lastIndexOf('\n');
if (i >= 0) {
Component.println(s.substr(0, i));
s = s.substr(i + 1);
}
Component.printBuffer += s;
Component.print(s);
}
/**
* println(s, type, id)
*
* For non-diagnostic messages, which components may override to control the destination/appearance of their output.
*
* Components using this.println() should wait until after their constructor has run to display any messages, because
* if a Control Panel has been loaded, its override will not take effect until its own constructor has run.
*
@ -3517,8 +3530,7 @@ class Component {
*/
println(s, type, id)
{
Component.println(Component.printBuffer + s, type, id || this.id);
Component.printBuffer = "";
Component.println(s, type, id || this.id);
}
/**
@ -3796,15 +3808,16 @@ class Component {
}
/*
* These are the standard TYPE values you can pass as the second argument to println(); in reality,
* you can pass anything you want, because they are just tacked onto the message as a prefix, with the
* exception of PROGRESS, which will suppress the message unless we're in DEBUG or INIT mode.
* These are the standard TYPE values you can pass as an optional argument to println(); in reality,
* you can pass anything you want, because they are simply prepended to the message, although PROGRESS
* messages may also be merged with earlier similar messages to keep the output buffer under control.
*/
Component.TYPE = {
NOTICE: "notice",
WARNING: "warning",
ERROR: "error",
PROGRESS: "progress"
NOTICE: "notice",
PROGRESS: "progress",
SCRIPT: "script",
WARNING: "warning"
};
/*

View file

@ -57,7 +57,7 @@ function Ya(a){for(var b=!0,c=Za[a];c&&c.length;){var d=c.splice(0,1)[0],e=d[0],
k.toString=function(){return this.name?this.name:this.id||this.type};
k.S=function(a,b,c){switch(b){case "clear":return this.w[b]||(this.w[b]=c,c.onclick=function(a){return function(){a.w.print&&(a.w.print.value="")}}(this)),!0;case "print":return this.w[b]||(this.w[b]=c,this.G=function(a){this.aa(a,this.type);return!0},c.value="",this.print=function(a){return function(b){Sa(a,b)}}(c),this.aa=function(a,b){return function(a,c){a||(a="");if(c!=cb.Jc||"..."!=a.slice(-3))c&&(a=c+": "+a),Sa(b,a+"\n");else{c=b.value;var d=c.lastIndexOf(a);0>d?c+=a+"\n":c=c.substr(0,d)+(a+
".")+c.substr(d+a.length);8192<c.length&&(c=c.substr(c.length-4096));b.value=c;b.scrollTop=b.scrollHeight}}}(this,c)),!0;default:return!1}};k.log=function(){};k.print=function(){};k.aa=function(){};k.status=function(a){this.aa(this.type+": "+a)};k.G=function(a,b,c){if(!b){var d=Xa("Computer",this.id);if(d&&d.i.pb)return console.log("ignoring notice during unload: "+a),!1}Ja(a,b,c||this.type);return!0};function db(a,b){b&&(a.i.ready?b():a.bb=b);return a.i.ready}
function B(a){if(!a.i.error&&(a.i.ready=!0,a.i.ready)){var b=a.bb;a.bb=null;b&&b()}}function eb(a,b){if(a.i.lb)return a.i.Za=!1,a.i.lb=!1;if(a.i.error)return a.aa(a.toString()+" error"),!1;a.i.Za=b;return a.i.Za}k.ca=function(){return this.i.V=!0};k.ba=function(a,b){b&&(this.i.V=!1);return!0};var cb={Qe:"notice",kf:"warning",ERROR:"error",Jc:"progress"};
function B(a){if(!a.i.error&&(a.i.ready=!0,a.i.ready)){var b=a.bb;a.bb=null;b&&b()}}function eb(a,b){if(a.i.lb)return a.i.Za=!1,a.i.lb=!1;if(a.i.error)return a.aa(a.toString()+" error"),!1;a.i.Za=b;return a.i.Za}k.ca=function(){return this.i.V=!0};k.ba=function(a,b){b&&(this.i.V=!1);return!0};var cb={ERROR:"error",Qe:"notice",Jc:"progress",SCRIPT:"script",kf:"warning"};
window&&(window.PCjs||(window.PCjs={}),window.PCjs.Machines||(window.PCjs.Machines={}),window.PCjs.Components||(window.PCjs.Components=[]),window.PCjs.Commands||(window.PCjs.Commands={}));
var Pa=window?window.PCjs.Machines:{},u=window?window.PCjs.Components:[],Za=window?window.PCjs.Commands:{},$a=["hold","sleep","wait"],ab={alert:function(a){r(a);return!0},sleep:function(a,b){setTimeout(a,+b);return!1}},bb={select:function(a,b,c){var d=!1;if(a=a.bindings[b])for(b=0;b<a.options.length;b++)if(a.options[b].textContent==c){a.selectedIndex!=b&&(a.selectedIndex=b);d=!0;break}return d}};
Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){b=b||0;for(var c=this.length;b<c;b++)if(this[b]===a)return b;return-1});Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)});

File diff suppressed because one or more lines are too long