46 lines
1006 B
JavaScript
46 lines
1006 B
JavaScript
var Terminal = function(uri) {
|
|
|
|
this.ui = new UserInterface(this);
|
|
this.ws = new WebSocketHandler(this, uri);
|
|
this.fs = new FileSystem();
|
|
this.session = new Session(this);
|
|
this.command = new Command(this);
|
|
this.api = new API(this);
|
|
this.fileAPI = new FileAPI(this);
|
|
|
|
this.ui.prompt.textContent = this.promptString;
|
|
|
|
this.idCount = -1;
|
|
this.callbacks = {};
|
|
this.args = {};
|
|
|
|
this.welcome();
|
|
|
|
var self = this;
|
|
|
|
this.loop = function() {
|
|
self.command.readLine(self.loop, true);
|
|
};
|
|
|
|
this.printResult = function(packet, args) {
|
|
if (packet.status == 'SUCCESS') {
|
|
self.ui.print(packet.message, self.ws.SUCCESS_COLOR);
|
|
} else {
|
|
self.ui.print(packet.message, self.ws.FAILURE_COLOR);
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
Terminal.prototype.nextID = function() {
|
|
this.idCount++;
|
|
return this.idCount;
|
|
};
|
|
|
|
Terminal.prototype.promptString = '$ ';
|
|
|
|
Terminal.prototype.welcome = function() {
|
|
this.ui.println('Welcome to RainMelt, a simple Web Terminal.');
|
|
this.ui.println('Enter \'help\' to show help message.');
|
|
};
|