Skip to content

Instantly share code, notes, and snippets.

@kenwebb kenwebb/SumTwo.xml
Last active Aug 29, 2015

Embed
What would you like to do?
Rosetta Code - Take notes on the command line
<SumTwo>
<!--
To create a new console-line mini-app,
append the contents of this file as the last child of the CommandlineApps node.
sample usage: cmd(SumTwo,17 23)
-->
<SumTwobehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var sum2;
var beh = {
postConfigure: function() {
sum2 = this.cnode.parent();
},
processReceivedMessage: function(msg) {
if (msg.data) {
var dataArr = msg.data.trim().split(" ");
if (dataArr.length == 2) {
var x = dataArr[0];
var y = dataArr[1];
var sum = Number(x) + Number(y);
$wnd.alert(x + " + " + y + " = " + sum);
}
}
}
}
]]></SumTwobehavior>
</SumTwo>
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Thu Mar 13 2014 17:12:10 GMT-0400 (EDT)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Rosetta Code - Take notes on the command line
Description:
Url: http://www.primordion.com/Xholon/gwt/wb/editwb.html?app=9500085&src=gist
InternalName: 9500085
Keywords:
My Notes
--------
Rosetta Code specifies tasks that can be solved using programming languages.
Anyone can edit the wiki page for a task, and write solutions using their own favorite languages.
It's a good way to compare different languages, learn about a new language,
find implementations of an algorithm, and work through how to implement something.
I want to implement some of the tasks using Xholon. I'll start with the "Take notes on the command line" task.
Here's the task description:
"Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists.
If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline.
Then all the arguments, joined with spaces, prepended with a tab,
and appended with a trailing newline, are written to NOTES.TXT.
If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created."
To run the app:
- Load the app
Click the "clsc" button above,
or go to following URL
http://www.primordion.com/Xholon/gwt/Xholon.html?app=9500085&src=gist&gui=clsc
- Click the Start button
- Right-click the Commandline node in the Composite Structure Hierarchy, and select XholonConsole.
- For each of the following commands, type it into the command line console and click Submit
cmd(NOTES,one two three four,English)
cmd(NOTES,un deux trois,quatre,French)
cmd(NOTES,uno dos,tres,cuatro,Spanish)
cmd(NOTES,один,два,три,чотири,Ukrainian)
cmd(NOTES,один два три четыре,Russian)
cmd(NOTES)
cmd(HelloWorld)
When you submit `cmd(NOTES)`, the notes are saved to a file on your hard disk,
probably in your Downloads directory. As you can see from the NOTESbehavior editor
further down on this page, the HTML5 FileSaver.js library does this.
This XholonWorkbook also contains a second command-line mini-app called HelloWorld,
to demonstrate how simple it is to do this.
You can create your own mini-apps. For an example, see:
https://gist.github.com/kenwebb/9500085#file-sumtwo-xml
http://rosettacode.org/wiki/Rosetta_Code
http://rosettacode.org/wiki/Take_notes_on_the_command_line
https://github.com/eligrey/FileSaver.js
]]></Notes>
<_-.XholonClass>
<CommandlineSystem/>
<Commandline/>
<CommandlineApp/>
<!--
all children of CommandlineApps in the Composite Structure Hierarchy,
will be subclasses of CommandlineApp
-->
<CommandlineApps childSuperClass="CommandlineApp"/>
</_-.XholonClass>
<xholonClassDetails>
<Commandline>
<port name="apps" connector="../CommandlineApps"/>
</Commandline>
</xholonClassDetails>
<CommandlineSystem>
<Commandline/>
<CommandlineApps>
<HelloWorld/>
<NOTES/>
<!-- other apps can be added here -->
</CommandlineApps>
<InteractionsViewer/>
</CommandlineSystem>
<Commandlinebehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var cmdline;
var beh = {
postConfigure: function() {
cmdline = this.cnode.parent();
},
// variable number of arguments
cmd: function(appName, varargs) {
var app = cmdline.apps.xpath(appName);
if (app) {
var argsStr = "";
for (var i = 1; i < arguments.length; i++) {
argsStr += arguments[i] + " ";
}
app.msg(101, argsStr, cmdline);
}
else {
$wnd.alert("No such app: " + appName);
}
}
}
]]></Commandlinebehavior>
<NOTESbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var notes, NOTES_TXT;
var beh = {
postConfigure: function() {
notes = this.cnode.parent();
NOTES_TXT = "";
$wnd.xh.require("FileSaver.js");
},
processReceivedMessage: function(msg) {
if (msg.data) {
NOTES_TXT += new Date() + "\n";
NOTES_TXT += "\t" + msg.data + "\n";
}
else {
// save all notes to file NOTES.txt in a standard place,
// such as the Downloads directory on your hard disk
var blob = new Blob([NOTES_TXT], {type: "text/plain;charset=utf-8"});
$wnd.saveAs(blob, "NOTES.txt");
// display all notes temporarily on the screen
$wnd.alert(NOTES_TXT);
}
}
}
]]></NOTESbehavior>
<HelloWorldbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var hw;
var beh = {
postConfigure: function() {
hw = this.cnode.parent();
},
processReceivedMessage: function(msg) {
$wnd.alert("Hello World");
}
}
]]></HelloWorldbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Commandline</title>
<rect id="CommandlineSystem/Commandline" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>CommandlineApps</title>
<rect id="CommandlineSystem/CommandlineApps" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.