CLI
by Ryan Duffy
HTML
<script src="https://raw.github.com/silentmatt/js-expression-eval/master/parser.js"></script>
<script src="https://parse.com/downloads/javascript/parse/latest/min.js"></script>
CSS
BODY {
font-family:Courier New;
white-space:pre;
}
.cursor {
position:absolute;
top:0em;
border-bottom:2px solid black;
height:1em;
}
.cursor.insert {
border-bottom:4px solid black
}
JavaScript
enyo.machine.script = function(inSrc, onLoad, onError) {
if (!enyo.runtimeLoading) {
document.write('<scri' + 'pt src="' + inSrc + '"' + (onLoad ? ' onload="' + onLoad + '"' : '') + (onError ? ' onerror="' + onError + '"' : '') + '></scri' + 'pt>');
} else {
var script = document.createElement('script');
script.src = inSrc;
script.onload = onLoad;
script.onerror = onError;
document.getElementsByTagName('head')[0].appendChild(script);
}
};
enyo.kind({
name: "cli.Command",
kind: "Component",
events: {
onRegisterCommand:"",
onUnregisterCommand:"",
onCommandResponse: "",
onCommandError: ""
},
create:function() {
this.inherited(arguments);
if(this.command) {
this.doRegisterCommand({command:this.command, handler:this});
}
},
destroy:function() {
this.doUnregisterCommand({command:this.command});
this.inherited(arguments);
},
execute: function(sender, event) {
if (!this.command || (this.command && this.command === event.command)) {
if (enyo.isString(this.commandHandler) && this.owner[this.commandHandler]) {
this.owner[this.commandHandler](sender, event);
} else if (enyo.isFunction(this.commandHandler)) {
this.commandHandler(sender, event);
}
}
},
commandHandler: function(sender, event) {},
hasArgument:function(command, arg) {
arg = enyo.isArray(arg) ? arg : [arg];
var ok = true;
for(var i=0;i<arg.length && ok;i++) {
ok = typeof(command.args[arg[i]]) !== "undefined";
}
return ok;
},
print:function(lines, suppress) {
if(!this.outputLines) {
this.outputLines = [];
this.dataLines = [];
}
lines = enyo.isArray(lines) ? lines : [lines];
for(var i=0,l=lines.length;i<l;i++) {
...