mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Add muted mode and restructure console echo
Introduce a _muted() helper to check for a WScript "quiet" argument and avoid output when muted. Replace the old _echoDefault with a unified _echoCallback(params, type) that writes messages via WScript and respects the muted flag. Refactor _echo to build a params object (including params.message and scope), prepend the optional type, invoke _echoCallback, and push the composed message to _messages. Adjust callback invocation logic (remove the previous null check and inline handling).
This commit is contained in:
parent
252da80548
commit
e0e713d975
29
app.js
29
app.js
|
|
@ -36,12 +36,21 @@ var console = {
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
_echoDefault: function(message) {
|
_muted: function() {
|
||||||
|
try {
|
||||||
|
if (typeof WScript !== "undefined")
|
||||||
|
return WScript.Arguments.Named.Exists("quiet");
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
_echoCallback: function(params, type) {
|
||||||
|
if (this._muted()) return;
|
||||||
|
|
||||||
if (typeof WScript !== "undefined") {
|
if (typeof WScript !== "undefined") {
|
||||||
WScript.StdOut.WriteLine("[*] " + message);
|
WScript.StdOut.WriteLine("[*] " + params.message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_echoCallback: null,
|
|
||||||
_echo: function(args, type) {
|
_echo: function(args, type) {
|
||||||
var messages = [];
|
var messages = [];
|
||||||
var params = {
|
var params = {
|
||||||
|
|
@ -80,19 +89,15 @@ var console = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = messages.join(' ');
|
params.message = messages.join(' ');
|
||||||
if (typeof type !== "undefined") {
|
if (typeof type !== "undefined") {
|
||||||
message = type + ": " + message;
|
params.message = type + ": " + params.message;
|
||||||
}
|
}
|
||||||
this._echoDefault(message);
|
this._echoCallback(params);
|
||||||
this._messages.push(message);
|
this._messages.push(params.message);
|
||||||
|
|
||||||
if (params.scope.length > 0 && this._echoCallback != null) {
|
if (params.scope.length > 0) {
|
||||||
try {
|
|
||||||
this._echoCallback(params, type);
|
this._echoCallback(params, type);
|
||||||
} catch (e) {
|
|
||||||
this._echoDefault("Exception:" + e.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
assert: function(assertion) {
|
assert: function(assertion) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user