Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:57
What would you like to do?
Rosetta Code - Take notes on the command line
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 ( {
var dataArr =" ");
if (dataArr.length == 2) {
var x = dataArr[0];
var y = dataArr[1];
var sum = Number(x) + Number(y);
$wnd.alert(x + " + " + y + " = " + sum);
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook MIT License, Copyright (C) Ken Webb, Thu Mar 13 2014 17:12:10 GMT-0400 (EDT)-->
Title: Rosetta Code - Take notes on the command line
InternalName: 9500085
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
- 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,один два три четыре,Russian)
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:
all children of CommandlineApps in the Composite Structure Hierarchy,
will be subclasses of CommandlineApp
<CommandlineApps childSuperClass="CommandlineApp"/>
<port name="apps" connector="../CommandlineApps"/>
<!-- other apps can be added here -->
<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);
<NOTESbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var notes, NOTES_TXT;
var beh = {
postConfigure: function() {
notes = this.cnode.parent();
processReceivedMessage: function(msg) {
if ( {
NOTES_TXT += new Date() + "\n";
NOTES_TXT += "\t" + + "\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
<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");
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="">
<rect id="CommandlineSystem/Commandline" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<rect id="CommandlineSystem/CommandlineApps" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment