Move most of the specification of terminal API client-side, so that the terminal can be changed without restarting the core. Add descriptions to some packages. Other minor improvements.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3222 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
9668723200
commit
25d97e5e3b
@ -133,18 +133,18 @@ function receive(data) {
|
||||
if (window.Notification) {
|
||||
new Notification(line[0].title, line[0].options);
|
||||
}
|
||||
} else if (line && line[0] && line[0].action == "title") {
|
||||
} else if (line && line[0] && line[0].action == "setTitle") {
|
||||
window.document.title = line[0].value;
|
||||
} else if (line && line[0] && line[0].action == "prompt") {
|
||||
} else if (line && line[0] && line[0].action == "setPrompt") {
|
||||
var prompt = document.getElementById("prompt");
|
||||
while (prompt.firstChild) {
|
||||
prompt.removeChild(prompt.firstChild);
|
||||
}
|
||||
prompt.appendChild(document.createTextNode(line[0].value));
|
||||
} else if (line && line[0] && line[0].action == "password") {
|
||||
} else if (line && line[0] && line[0].action == "setPassword") {
|
||||
var prompt = document.getElementById("input");
|
||||
prompt.setAttribute("type", line[0].value ? "password" : "text");
|
||||
} else if (line && line[0] && line[0].action == "hash") {
|
||||
} else if (line && line[0] && line[0].action == "setHash") {
|
||||
window.location.hash = line[0].value;
|
||||
} else if (line && line[0] && line[0].action == "update") {
|
||||
document.getElementById("update").setAttribute("Style", "display: inline");
|
||||
@ -436,6 +436,16 @@ window.addEventListener("load", function() {
|
||||
gSocket.send(JSON.stringify({
|
||||
action: "hello",
|
||||
path: window.location.pathname,
|
||||
terminalApi: [
|
||||
['clear'],
|
||||
['notify', 'title', 'options'],
|
||||
['postMessageToIframe', 'name', 'message'],
|
||||
['setHash', 'value'],
|
||||
['setPassword', 'value'],
|
||||
['setPrompt', 'value'],
|
||||
['setTitle', 'value'],
|
||||
['split', 'options'],
|
||||
],
|
||||
}));
|
||||
}
|
||||
gSocket.onmessage = function(event) {
|
||||
|
16
core/core.js
16
core/core.js
@ -289,20 +289,18 @@ function getProcess(packageOwner, packageName, key, options) {
|
||||
if (options.terminal) {
|
||||
imports.terminal = {
|
||||
'print': process.terminal.print.bind(process.terminal),
|
||||
'clear': process.terminal.clear.bind(process.terminal),
|
||||
'readLine': process.terminal.readLine.bind(process.terminal),
|
||||
'notify': process.terminal.notify.bind(process.terminal),
|
||||
'setEcho': process.terminal.setEcho.bind(process.terminal),
|
||||
'setTitle': process.terminal.setTitle.bind(process.terminal),
|
||||
'setPrompt': process.terminal.setPrompt.bind(process.terminal),
|
||||
'setPassword': process.terminal.setPassword.bind(process.terminal),
|
||||
'setHash': process.terminal.setHash.bind(process.terminal),
|
||||
'split': process.terminal.split.bind(process.terminal),
|
||||
'select': process.terminal.select.bind(process.terminal),
|
||||
'postMessageToIframe': process.terminal.postMessageToIframe.bind(process.terminal),
|
||||
'cork': process.terminal.cork.bind(process.terminal),
|
||||
'uncork': process.terminal.uncork.bind(process.terminal),
|
||||
};
|
||||
if (options.terminalApi) {
|
||||
for (let i in options.terminalApi) {
|
||||
let api = options.terminalApi[i];
|
||||
imports.terminal[api[0]] = process.terminal.makeFunction(api);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (manifest
|
||||
&& manifest.permissions
|
||||
@ -416,6 +414,8 @@ httpd.all("", function(request, response) {
|
||||
return terminal.handler(request, response, null, null, match[1]);
|
||||
} else if (match = /^\/\~([^\/]+)\/([^\/]+)(.*)/.exec(request.uri)) {
|
||||
return terminal.handler(request, response, match[1], match[2], match[3]);
|
||||
} else if (request.uri == "/robots.txt") {
|
||||
return terminal.handler(request, response, null, null, request.uri);
|
||||
} else {
|
||||
var data = "File not found.";
|
||||
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": data.length.toString()});
|
||||
|
@ -8,6 +8,7 @@ var kStaticFiles = [
|
||||
{uri: '/client.js', path: 'client.js', type: 'text/javascript; charset=utf-8'},
|
||||
{uri: '/editor.js', path: 'editor.js', type: 'text/javascript; charset=utf-8'},
|
||||
{uri: '/agplv3-88x31.png', path: 'agplv3-88x31.png', type: 'image/png'},
|
||||
{uri: '/robots.txt', path: 'robots.txt', type: 'text/plain; charset=utf-8'},
|
||||
];
|
||||
|
||||
var auth = require('auth');
|
||||
@ -69,46 +70,14 @@ Terminal.prototype.print = function() {
|
||||
this._lastWrite = new Date();
|
||||
}
|
||||
|
||||
Terminal.prototype.notify = function(title, options) {
|
||||
this.print({action: "notify", title: title, options: options});
|
||||
}
|
||||
|
||||
Terminal.prototype.setTitle = function(value) {
|
||||
this.print({action: "title", value: value});
|
||||
}
|
||||
|
||||
Terminal.prototype.setPrompt = function(value) {
|
||||
this.print({action: "prompt", value: value});
|
||||
}
|
||||
|
||||
Terminal.prototype.setPassword = function(value) {
|
||||
this.print({action: "password", value: value});
|
||||
}
|
||||
|
||||
Terminal.prototype.setHash = function(value) {
|
||||
this.print({action: "hash", value: value});
|
||||
}
|
||||
|
||||
Terminal.prototype.notifyUpdate = function() {
|
||||
this.print({action: "update"});
|
||||
}
|
||||
|
||||
Terminal.prototype.split = function(options) {
|
||||
this.print({action: "split", options: options});
|
||||
}
|
||||
|
||||
Terminal.prototype.select = function(name) {
|
||||
this._selected = name;
|
||||
}
|
||||
|
||||
Terminal.prototype.postMessageToIframe = function(name, message) {
|
||||
this.print({action: "postMessageToIframe", name: name, message: message});
|
||||
}
|
||||
|
||||
Terminal.prototype.clear = function() {
|
||||
this.print({action: "clear"});
|
||||
}
|
||||
|
||||
Terminal.prototype.ping = function() {
|
||||
this.dispatch({action: "ping"});
|
||||
}
|
||||
@ -137,6 +106,17 @@ Terminal.prototype.uncork = function() {
|
||||
}
|
||||
}
|
||||
|
||||
Terminal.prototype.makeFunction = function(api) {
|
||||
let self = this;
|
||||
return function() {
|
||||
let message = {action: api[0]};
|
||||
for (let i = 1; i < api.length; i++) {
|
||||
message[api[i]] = arguments[i - 1];
|
||||
}
|
||||
self.print(message);
|
||||
}
|
||||
}
|
||||
|
||||
function invoke(handlers, argv) {
|
||||
var promises = [];
|
||||
if (handlers) {
|
||||
@ -177,6 +157,7 @@ function socket(request, response, client) {
|
||||
var sessionId = makeSessionId();
|
||||
response.send(JSON.stringify({lines: [{action: "session", sessionId: sessionId, credentials: credentials}]}), 0x1);
|
||||
|
||||
options.terminalApi = message.terminalApi || [];
|
||||
process = getSessionProcess(packageOwner, packageName, sessionId, options);
|
||||
process.terminal.readOutput(function(message) {
|
||||
response.send(JSON.stringify(message), 0x1);
|
||||
|
@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
//! {"description": "A list of all packages and connected users"}
|
||||
|
||||
core.register("onSessionBegin", index);
|
||||
core.register("onSessionEnd", index);
|
||||
|
||||
@ -64,7 +66,8 @@ function index() {
|
||||
terminal.print(
|
||||
"* ",
|
||||
{href: "/~" + app.owner + "/" + app.name},
|
||||
message);
|
||||
message,
|
||||
app.manifest && app.manifest.description ? " - " + app.manifest.description.toString() : "");
|
||||
});
|
||||
terminal.uncork();
|
||||
});
|
||||
|
@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
//! {"description": "Massively multiplayer online Turtle Graphics"}
|
||||
|
||||
// This script runs server-side, once for each client session.
|
||||
|
||||
if (imports.terminal) {
|
||||
|
@ -118,12 +118,12 @@ function testEdit(event) {
|
||||
});
|
||||
}
|
||||
|
||||
if (imports.terminal) {
|
||||
/*if (imports.terminal) {
|
||||
fileList({
|
||||
title: "Test File List",
|
||||
prefix: "fileList_",
|
||||
edit: testEdit,
|
||||
});
|
||||
}
|
||||
}*/
|
||||
|
||||
exports.fileList = fileList;
|
@ -783,7 +783,7 @@ function schedulePing(socket) {
|
||||
terminal.split([
|
||||
{type: "horizontal", children: [
|
||||
{name: "terminal", grow: 1},
|
||||
{name: "users", basis: "2in", grow: 0, shrink: 0},
|
||||
{name: "users", basis: "2in", grow: "0", shrink: "0"},
|
||||
]},
|
||||
]);
|
||||
terminal.select("terminal");
|
||||
|
Loading…
Reference in New Issue
Block a user