diff --git a/core/client.js b/core/client.js index 4acd34ce..bbd52fbc 100644 --- a/core/client.js +++ b/core/client.js @@ -52,7 +52,14 @@ function split(container, children) { var shrink = children[i].shrink || "1"; var basis = children[i].basis || "auto"; node.setAttribute("style", "flex: " + grow + " " + shrink + " " + basis); - node.setAttribute("class", "terminal"); + + var classes = ["terminal"]; + if (children[i].type == "vertical") { + classes.push("vbox"); + } else if (children[i].type == "horizontal") { + classes.push("hbox"); + } + node.setAttribute("class", classes.join(" ")); container.appendChild(node); } else if (children[i].type) { node = document.createElement("div"); @@ -177,7 +184,7 @@ function printStructured(container, data) { } else if (data.iframe) { node = document.createElement("iframe"); node.setAttribute("srcdoc", data.iframe); - node.setAttribute("sandbox", "allow-forms allow-scripts"); + node.setAttribute("sandbox", "allow-forms allow-scripts allow-top-navigation"); node.setAttribute("width", data.width || 320); node.setAttribute("height", data.height || 240); if (data.name) { diff --git a/packages/cory/mmoturtle/mmoturtle.js b/packages/cory/mmoturtle/mmoturtle.js index f1b9d603..5178862c 100644 --- a/packages/cory/mmoturtle/mmoturtle.js +++ b/packages/cory/mmoturtle/mmoturtle.js @@ -5,8 +5,13 @@ if (imports.terminal) { terminal.setEcho(false); terminal.split([ - {name: "graphics", basis: "520px", shrink: "0", grow: "0"}, - {name: "text"}, + { + type: "horizontal", + children: [ + {name: "graphics", basis: "700px", shrink: "0", grow: "0"}, + {name: "text"}, + ], + }, ]); // Request a callback every time the user hits enter at the terminal prompt. @@ -31,7 +36,13 @@ if (imports.terminal) { }); core.register("onWindowMessage", function(data) { - terminal.print(data.message); + if (data.message.ready) { + core.getService("turtle").then(function(service) { + return service.postMessage("sync"); + }); + } else { + terminal.print(data.message); + } }); terminal.select("graphics"); @@ -39,7 +50,7 @@ if (imports.terminal) { // Add an iframe to the terminal. This is how we sandbox code running on the client. var contents = ` - + ` terminal.print({iframe: contents, width: 640, height: 480, name: "turtle"}); terminal.select("text"); terminal.print("Supported commands: ", ["fd ", "bk ", "rt ", "lt ", "pu", "pd", "home", "reset", "clear"].join(", ")); - - // Get the party started by asking for the history of commands (the turtle party). - setTimeout(function() { - core.getService("turtle").then(function(service) { - return service.postMessage("sync"); - }); - }, 1000); } else { var gHistory = null; diff --git a/packages/cory/turtle/turtle.js b/packages/cory/turtle/turtle.js index 7a8894e9..22483293 100644 --- a/packages/cory/turtle/turtle.js +++ b/packages/cory/turtle/turtle.js @@ -1,41 +1,180 @@ "use strict"; -// Start at bottom left facing up. -// Height = 20. Width = 10. -// 10 between. +terminal.setEcho(false); +terminal.setTitle("Live TurtleScript"); -var letters = { - A: 'fd(20); rt(90); fd(10); rt(90); fd(10); rt(90); fd(10); pu(); bk(10); lt(90); pd(); fd(10); pu(); lt(90); fd(10); lt(90); pd();', - D: 'fd(20); rt(90); fd(10); rt(70); fd(11); rt(40); fd(11); rt(70); fd(10); pu(); bk(20); rt(90); pd();', - E: 'pu(); fd(20); rt(90); fd(10); lt(180); pd(); fd(10); lt(90); fd(10); lt(90); fd(8); pu(); rt(180); fd(8); lt(90); pd(); fd(10); lt(90); fd(10); pu(); fd(10); lt(90); pd()', - H: 'fd(20); pu(); bk(10); pd(); rt(90); fd(10); lt(90); pu(); fd(10); rt(180); pd(); fd(20); pu(); lt(90); fd(10); lt(90); pd();', - L: 'pu(); fd(20); rt(180); pd(); fd(20); lt(90); fd(10); pu(); fd(10); lt(90); pd();', - O: 'fd(20); rt(90); fd(10); rt(90); fd(20); rt(90); fd(10); pu(); bk(20); rt(90); pd();', - R: 'fd(20); rt(90); fd(10); rt(90); fd(10); rt(90); fd(10); pu(); bk(8); lt(90); pd(); fd(10); pu(); lt(90); fd(12); lt(90); pd();', - W: 'pu(); fd(20); rt(180); pd(); fd(20); lt(90); fd(5); lt(90); fd(12); rt(180); pu(); fd(12); pd(); lt(90); fd(5); lt(90); fd(20); pu(); bk(20); rt(90); fd(10); lt(90); pd();', - ' ': 'pu(); rt(90); fd(20); lt(90); pd();', -}; - -function render(text) { - terminal.clear(); - terminal.print(text, " using ", {href: "http://codeheartjs.com/turtle/"}, "."); - var contents = '\n"; - terminal.print({iframe: contents, width: 640, height: 480}); - terminal.print("Type text and the letters ", {style: "color: #ff0", value: Object.keys(letters).join("")}, " in it will be drawn."); +}); + +function renderIndex() { + terminal.split([{name: "terminal"}]); + terminal.clear(); + terminal.print("Live TurtleScript"); + if (core.user.credentials.permissions.authenticated) { + terminal.print({command: "new page"}); + } + + database.getAll().then(function(entries) { + for (var i = 0; i < entries.length; i++) { + if (core.user.credentials.permissions.authenticated) { + terminal.print( + "* ", + {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}, + " (", + {command: "delete:" + entries[i], value: "x"}, + ")"); + } else { + terminal.print( + "* ", + {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i]}}); + } + } + }); } -render("Hello, world!"); +var gPage = null; -core.register("onInput", render); \ No newline at end of file +core.register("hashChange", function(event) { + var title = event.hash.substring(1); + database.get(title).then(function(contents) { + editPage(title, contents); + }); +}); + +core.register("onWindowMessage", function(event) { + if (event.message.ready) { + terminal.postMessageToIframe("iframe", {title: gPage.title, contents: gPage.contents}); + } else if (event.message.index) { + renderIndex(); + } else { + database.set(event.message.title, event.message.contents).then(function() { + renderIndex(); + }); + } +}); + +function editPage(title, contents) { + gPage = {title: title, contents: contents}; + terminal.split([{name: "terminal", type: "vertical"}]); + terminal.clear(); + terminal.print({iframe: ` + + + + + + + + + +
+
+
+
+ + `, name: "iframe", style: "flex: 1 1 auto; border: 0; width: 100%"}); +} + +renderIndex(); \ No newline at end of file diff --git a/packages/cory/wiki/wiki.js b/packages/cory/wiki/wiki.js index c4df8319..b8ed984e 100644 --- a/packages/cory/wiki/wiki.js +++ b/packages/cory/wiki/wiki.js @@ -1,6 +1,7 @@ "use strict"; terminal.setEcho(false); +terminal.setTitle("Live Markdeep Editor"); core.register("onInput", function(input) { if (input == "new page") { @@ -27,8 +28,9 @@ core.register("onInput", function(input) { }); function renderIndex() { + terminal.split([{name: "terminal"}]); terminal.clear(); - terminal.print("Editor Test"); + terminal.print("Live Markdeep Editor"); if (core.user.credentials.permissions.authenticated) { terminal.print({command: "new page"}); } @@ -53,6 +55,13 @@ function renderIndex() { var gPage = null; +core.register("hashChange", function(event) { + var title = event.hash.substring(1); + database.get(title).then(function(contents) { + editPage(title, contents); + }); +}); + core.register("onWindowMessage", function(event) { if (event.message.ready) { terminal.postMessageToIframe("iframe", {title: gPage.title, contents: gPage.contents}); @@ -67,37 +76,47 @@ core.register("onWindowMessage", function(event) { function editPage(title, contents) { gPage = {title: title, contents: contents}; + terminal.split([{name: "terminal", type: "vertical"}]); terminal.clear(); terminal.print({iframe: ` - - - +
- -
+
+
- `, name: "iframe", style: "width: 100%; border: 0; height: 600px"}); + `, name: "iframe", style: "flex: 1 1 auto; border: 0; width: 100%"}); } renderIndex(); \ No newline at end of file