changeset 6496:03b02a7bcfb9

RT-36216 - Open-source the WebTerminal app See README.txt for more information.
author Per Bothner <Per.Bothner@Oracle.COM>
date Mon, 17 Mar 2014 09:33:56 -0700
parents 7339a5bb9864
children c66b3066b41e
files apps/experiments/WebTerminal/.ant-targets-build.xml apps/experiments/WebTerminal/README.txt apps/experiments/WebTerminal/build.xml apps/experiments/WebTerminal/manifest.mf apps/experiments/WebTerminal/nbproject/build-impl.xml apps/experiments/WebTerminal/nbproject/genfiles.properties apps/experiments/WebTerminal/nbproject/project.properties apps/experiments/WebTerminal/nbproject/project.xml apps/experiments/WebTerminal/src/webterminal/NodeWriter.java apps/experiments/WebTerminal/src/webterminal/RunInConsole.java apps/experiments/WebTerminal/src/webterminal/ShellConsole.java apps/experiments/WebTerminal/src/webterminal/WTDebug.java apps/experiments/WebTerminal/src/webterminal/WebOutputStream.java apps/experiments/WebTerminal/src/webterminal/WebTerminal.java apps/experiments/WebTerminal/src/webterminal/WebWriter.java apps/experiments/WebTerminal/src/webterminal/repl.html apps/experiments/WebTerminal/src/webterminal/repl.xml apps/experiments/WebTerminal/terminfo/j/jfxterm apps/experiments/WebTerminal/terminfo/j/jfxterm.ti apps/experiments/WebTerminal/terminfo/j/xjfxterm.ti apps/experiments/WebTerminal/util/hcat apps/experiments/WebTerminal/util/myemacs
diffstat 22 files changed, 3953 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/.ant-targets-build.xml	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,12 @@
+clean
+compile
+debug
+default
+jar
+javadoc
+profile
+profile-single
+run
+run-main
+test
+test-single
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/README.txt	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,51 @@
+WebTerminal implements a general-purpose interactive console:
+Users can type commands which get sent to a command handler,
+which evaluates the command, and displays the results, typically
+in some kind of type-script format.
+
+Applications of WebTerminal include:
++ A chat/talk window.
++ A read-eval-print-loop for an interactive scripting language.
++ A command console.
++ A terminal emulator.
+
+WebTerminal used as a terminal emulator recognizes a subset of the
+standard ANSI/xterm terminal escape sequences for repositioning the
+cursor, erasing previous text, changing style, etc.  A large enough
+subset is recognized that you can run programs like the emacs text
+editor, with styling.  This requires you specify the correct terminal
+type (TERM), which is done automatically by the PtyTerminal
+application.  A matching terminfo entry is provided, but it also
+should work ok to specify TERM to a standard terminal name, like
+eterm-color, vte, gnome, konsole, and xterm (all with color),
+or vt100 or vt220 (both non-color).
+
+The terminfo directory defines the escape sequences supported by the
+"jfxterm" terminal type, using a terminfo descriptor.  The terminal emulation
+is a subset of the standard xterm/ansi/vt100 ones.
+
+There is an escape sequence to send HTML to WebTerminal.
+This allows you to embed images, forms, and other HTML elements
+in the console output.
+
+The primary class is webterminal.WebTerminal, which is
+an abstract (overridable) control you embed in your scenegraph.
+
+The utility class webterminal.RunInConsole make it easy to
+run an old-fashioned console-based Java application in a WebTerminal.
+It re-binds System.in, System.out, and System.err to the WebTerminal.
+
+For example, the jrunscript tool is a wrapper around the class
+com.sun.tools.script.shell.Main in tools.jar.  So to start up
+a JavaScript read-elavl-print-tool, do:
+
+  $ ant run-main -Drunmain.classpath=$JAVA_HOME/lib/tools.jar \
+  -Drunmain.class="com.sun.tools.script.shell.Main" \
+  -Drunmain.args="-l javascript"
+
+The application webterminal.ShellConsole uses java.lang.Process
+to run a process inside a WebTerminal.  Currently, it is hard-wired to
+run /bin/bash.  (It does work under Cygwin if you edit the
+commandWithArgs field.)
+
+Other example applications are in the separate WebTerminalApps directory.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/build.xml	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See commented blocks below for -->
+<!-- some examples of how to customize the build. -->
+<!-- (If you delete it and reopen the project it will be recreated.) -->
+<!-- By default, only the Clean and Build commands use this build script. -->
+<!-- Commands such as Run, Debug, and Test only use this build script if -->
+<!-- the Compile on Save feature is turned off for the project. -->
+<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
+<!-- in the project's Project Properties dialog box.-->
+<project name="WebTerminal" default="default" basedir=".">
+    <description>Builds, tests, and runs the project WebTerminal.</description>
+    <import file="nbproject/build-impl.xml"/>
+    <!--
+
+    There exist several targets which are by default empty and which can be 
+    used for execution of your tasks. These targets are usually executed 
+    before and after some main targets. They are: 
+
+      -pre-init:                 called before initialization of project properties
+      -post-init:                called after initialization of project properties
+      -pre-compile:              called before javac compilation
+      -post-compile:             called after javac compilation
+      -pre-compile-single:       called before javac compilation of single file
+      -post-compile-single:      called after javac compilation of single file
+      -pre-compile-test:         called before javac compilation of JUnit tests
+      -post-compile-test:        called after javac compilation of JUnit tests
+      -pre-compile-test-single:  called before javac compilation of single JUnit test
+      -post-compile-test-single: called after javac compilation of single JUunit test
+      -pre-jar:                  called before JAR building
+      -post-jar:                 called after JAR building
+      -post-clean:               called after cleaning build products
+
+    (Targets beginning with '-' are not intended to be called on their own.)
+
+    Example of inserting an obfuscator after compilation could look like this:
+
+        <target name="-post-compile">
+            <obfuscate>
+                <fileset dir="${build.classes.dir}"/>
+            </obfuscate>
+        </target>
+
+    For list of available properties check the imported 
+    nbproject/build-impl.xml file. 
+
+
+    Another way to customize the build is by overriding existing main targets.
+    The targets of interest are: 
+
+      -init-macrodef-javac:     defines macro for javac compilation
+      -init-macrodef-junit:     defines macro for junit execution
+      -init-macrodef-debug:     defines macro for class debugging
+      -init-macrodef-java:      defines macro for class execution
+      -do-jar-with-manifest:    JAR building (if you are using a manifest)
+      -do-jar-without-manifest: JAR building (if you are not using a manifest)
+      run:                      execution of project 
+      -javadoc-build:           Javadoc generation
+      test-report:              JUnit report generation
+
+    An example of overriding the target for project execution could look like this:
+
+        <target name="run" depends="WebTerminal-impl.jar">
+            <exec dir="bin" executable="launcher.exe">
+                <arg file="${dist.jar}"/>
+            </exec>
+        </target>
+
+    Notice that the overridden target depends on the jar target and not only on 
+    the compile target as the regular run target does. Again, for a list of available 
+    properties which you can use, check the target you are overriding in the
+    nbproject/build-impl.xml file. 
+
+    -->
+
+   <target depends="init,compile" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" description="Run a main class." name="run-main">
+     <!-- Run an application (i.e. a class with a "main" method in a
+     WebTerminal, redirecting System.in, System.out, and System.err.
+
+     Set -Drunmain.classpath=EXTRA_PATH to expand the classpath.
+     -->
+     <j2seproject1:java classname="webterminal.RunInConsole"
+                        classpath="${run.classpath}:${runmain.classpath}">
+       <customize>
+         <arg line="${runmain.class} ${runmain.args}"/>
+       </customize>
+     </j2seproject1:java>
+    </target>
+ 
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/manifest.mf	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/nbproject/build-impl.xml	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,1042 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+*** GENERATED FROM project.xml - DO NOT EDIT  ***
+***         EDIT ../build.xml INSTEAD         ***
+
+For the purpose of easier reading the script
+is divided into following sections:
+
+  - initialization
+  - compilation
+  - jar
+  - execution
+  - debugging
+  - javadoc
+  - junit compilation
+  - junit execution
+  - junit debugging
+  - applet
+  - cleanup
+
+        -->
+<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="WebTerminal-impl">
+    <fail message="Please build using Ant 1.8.0 or higher.">
+        <condition>
+            <not>
+                <antversion atleast="1.8.0"/>
+            </not>
+        </condition>
+    </fail>
+    <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
+    <!-- 
+                ======================
+                INITIALIZATION SECTION 
+                ======================
+            -->
+    <target name="-pre-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="-pre-init" name="-init-private">
+        <property file="nbproject/private/config.properties"/>
+        <property file="nbproject/private/configs/${config}.properties"/>
+        <property file="nbproject/private/private.properties"/>
+    </target>
+    <target depends="-pre-init,-init-private" name="-init-user">
+        <property file="${user.properties.file}"/>
+        <!-- The two properties below are usually overridden -->
+        <!-- by the active platform. Just a fallback. -->
+        <property name="default.javac.source" value="1.4"/>
+        <property name="default.javac.target" value="1.4"/>
+    </target>
+    <target depends="-pre-init,-init-private,-init-user" name="-init-project">
+        <property file="nbproject/configs/${config}.properties"/>
+        <property file="nbproject/project.properties"/>
+    </target>
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
+        <available file="${manifest.file}" property="manifest.available"/>
+        <condition property="splashscreen.available">
+            <and>
+                <not>
+                    <equals arg1="${application.splash}" arg2="" trim="true"/>
+                </not>
+                <available file="${application.splash}"/>
+            </and>
+        </condition>
+        <condition property="main.class.available">
+            <and>
+                <isset property="main.class"/>
+                <not>
+                    <equals arg1="${main.class}" arg2="" trim="true"/>
+                </not>
+            </and>
+        </condition>
+        <condition property="manifest.available+main.class">
+            <and>
+                <isset property="manifest.available"/>
+                <isset property="main.class.available"/>
+            </and>
+        </condition>
+        <condition property="do.archive">
+            <not>
+                <istrue value="${jar.archive.disabled}"/>
+            </not>
+        </condition>
+        <condition property="do.mkdist">
+            <and>
+                <isset property="do.archive"/>
+                <isset property="libs.CopyLibs.classpath"/>
+                <not>
+                    <istrue value="${mkdist.disabled}"/>
+                </not>
+            </and>
+        </condition>
+        <condition property="manifest.available+main.class+mkdist.available">
+            <and>
+                <istrue value="${manifest.available+main.class}"/>
+                <isset property="do.mkdist"/>
+            </and>
+        </condition>
+        <condition property="do.archive+manifest.available">
+            <and>
+                <isset property="manifest.available"/>
+                <istrue value="${do.archive}"/>
+            </and>
+        </condition>
+        <condition property="do.archive+main.class.available">
+            <and>
+                <isset property="main.class.available"/>
+                <istrue value="${do.archive}"/>
+            </and>
+        </condition>
+        <condition property="do.archive+splashscreen.available">
+            <and>
+                <isset property="splashscreen.available"/>
+                <istrue value="${do.archive}"/>
+            </and>
+        </condition>
+        <condition property="do.archive+manifest.available+main.class">
+            <and>
+                <istrue value="${manifest.available+main.class}"/>
+                <istrue value="${do.archive}"/>
+            </and>
+        </condition>
+        <condition property="manifest.available-mkdist.available">
+            <or>
+                <istrue value="${manifest.available}"/>
+                <isset property="do.mkdist"/>
+            </or>
+        </condition>
+        <condition property="manifest.available+main.class-mkdist.available">
+            <or>
+                <istrue value="${manifest.available+main.class}"/>
+                <isset property="do.mkdist"/>
+            </or>
+        </condition>
+        <condition property="have.tests">
+            <or/>
+        </condition>
+        <condition property="have.sources">
+            <or>
+                <available file="${src.dir}"/>
+            </or>
+        </condition>
+        <condition property="netbeans.home+have.tests">
+            <and>
+                <isset property="netbeans.home"/>
+                <isset property="have.tests"/>
+            </and>
+        </condition>
+        <condition property="no.javadoc.preview">
+            <and>
+                <isset property="javadoc.preview"/>
+                <isfalse value="${javadoc.preview}"/>
+            </and>
+        </condition>
+        <property name="run.jvmargs" value=""/>
+        <property name="javac.compilerargs" value=""/>
+        <property name="work.dir" value="${basedir}"/>
+        <condition property="no.deps">
+            <and>
+                <istrue value="${no.dependencies}"/>
+            </and>
+        </condition>
+        <property name="javac.debug" value="true"/>
+        <property name="javadoc.preview" value="true"/>
+        <property name="application.args" value=""/>
+        <property name="source.encoding" value="${file.encoding}"/>
+        <property name="runtime.encoding" value="${source.encoding}"/>
+        <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
+            <and>
+                <isset property="javadoc.encoding"/>
+                <not>
+                    <equals arg1="${javadoc.encoding}" arg2=""/>
+                </not>
+            </and>
+        </condition>
+        <property name="javadoc.encoding.used" value="${source.encoding}"/>
+        <property name="includes" value="**"/>
+        <property name="excludes" value=""/>
+        <property name="do.depend" value="false"/>
+        <condition property="do.depend.true">
+            <istrue value="${do.depend}"/>
+        </condition>
+        <path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
+        <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
+            <length length="0" string="${endorsed.classpath}" when="greater"/>
+        </condition>
+        <condition else="false" property="jdkBug6558476">
+            <and>
+                <matches pattern="1\.[56]" string="${java.specification.version}"/>
+                <not>
+                    <os family="unix"/>
+                </not>
+            </and>
+        </condition>
+        <property name="javac.fork" value="${jdkBug6558476}"/>
+        <property name="jar.index" value="false"/>
+        <property name="jar.index.metainf" value="${jar.index}"/>
+        <property name="copylibs.rebase" value="true"/>
+        <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/>
+    </target>
+    <target name="-post-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
+        <fail unless="src.dir">Must set src.dir</fail>
+        <fail unless="build.dir">Must set build.dir</fail>
+        <fail unless="dist.dir">Must set dist.dir</fail>
+        <fail unless="build.classes.dir">Must set build.classes.dir</fail>
+        <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
+        <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
+        <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
+        <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
+        <fail unless="dist.jar">Must set dist.jar</fail>
+    </target>
+    <target name="-init-macrodef-property">
+        <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
+            <attribute name="name"/>
+            <attribute name="value"/>
+            <sequential>
+                <property name="@{name}" value="${@{value}}"/>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
+        <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${src.dir}" name="srcdir"/>
+            <attribute default="${build.classes.dir}" name="destdir"/>
+            <attribute default="${javac.classpath}" name="classpath"/>
+            <attribute default="${javac.processorpath}" name="processorpath"/>
+            <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="${javac.debug}" name="debug"/>
+            <attribute default="${empty.dir}" name="sourcepath"/>
+            <attribute default="${empty.dir}" name="gensrcdir"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <property location="${build.dir}/empty" name="empty.dir"/>
+                <mkdir dir="${empty.dir}"/>
+                <mkdir dir="@{apgeneratedsrcdir}"/>
+                <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
+                    <src>
+                        <dirset dir="@{gensrcdir}" erroronmissingdir="false">
+                            <include name="*"/>
+                        </dirset>
+                    </src>
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                    <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <compilerarg line="${javac.compilerargs}"/>
+                    <compilerarg value="-processorpath"/>
+                    <compilerarg path="@{processorpath}:${empty.dir}"/>
+                    <compilerarg line="${ap.processors.internal}"/>
+                    <compilerarg line="${annotation.processing.processor.options}"/>
+                    <compilerarg value="-s"/>
+                    <compilerarg path="@{apgeneratedsrcdir}"/>
+                    <compilerarg line="${ap.proc.none.internal}"/>
+                    <customize/>
+                </javac>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
+        <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${src.dir}" name="srcdir"/>
+            <attribute default="${build.classes.dir}" name="destdir"/>
+            <attribute default="${javac.classpath}" name="classpath"/>
+            <attribute default="${javac.processorpath}" name="processorpath"/>
+            <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="${javac.debug}" name="debug"/>
+            <attribute default="${empty.dir}" name="sourcepath"/>
+            <attribute default="${empty.dir}" name="gensrcdir"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <property location="${build.dir}/empty" name="empty.dir"/>
+                <mkdir dir="${empty.dir}"/>
+                <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
+                    <src>
+                        <dirset dir="@{gensrcdir}" erroronmissingdir="false">
+                            <include name="*"/>
+                        </dirset>
+                    </src>
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                    <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <compilerarg line="${javac.compilerargs}"/>
+                    <customize/>
+                </javac>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
+        <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${src.dir}" name="srcdir"/>
+            <attribute default="${build.classes.dir}" name="destdir"/>
+            <attribute default="${javac.classpath}" name="classpath"/>
+            <sequential>
+                <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                </depend>
+            </sequential>
+        </macrodef>
+        <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${build.classes.dir}" name="destdir"/>
+            <sequential>
+                <fail unless="javac.includes">Must set javac.includes</fail>
+                <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
+                    <path>
+                        <filelist dir="@{destdir}" files="${javac.includes}"/>
+                    </path>
+                    <globmapper from="*.java" to="*.class"/>
+                </pathconvert>
+                <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
+                <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
+                <delete>
+                    <files includesfile="${javac.includesfile.binary}"/>
+                </delete>
+                <delete>
+                    <fileset file="${javac.includesfile.binary}"/>
+                </delete>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-macrodef-junit">
+        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${includes}" name="includes"/>
+            <attribute default="${excludes}" name="excludes"/>
+            <attribute default="**" name="testincludes"/>
+            <sequential>
+                <property name="junit.forkmode" value="perTest"/>
+                <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
+                    <batchtest todir="${build.test.results.dir}"/>
+                    <classpath>
+                        <path path="${run.test.classpath}"/>
+                    </classpath>
+                    <syspropertyset>
+                        <propertyref prefix="test-sys-prop."/>
+                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <formatter type="brief" usefile="false"/>
+                    <formatter type="xml"/>
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <jvmarg value="-ea"/>
+                    <jvmarg line="${run.jvmargs}"/>
+                </junit>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" name="profile-init"/>
+    <target name="-profile-pre-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target name="-profile-post-init">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target name="-profile-init-macrodef-profile">
+        <macrodef name="resolve">
+            <attribute name="name"/>
+            <attribute name="value"/>
+            <sequential>
+                <property name="@{name}" value="${env.@{value}}"/>
+            </sequential>
+        </macrodef>
+        <macrodef name="profile">
+            <attribute default="${main.class}" name="classname"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <property environment="env"/>
+                <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
+                <java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}">
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <jvmarg value="${profiler.info.jvmargs.agent}"/>
+                    <jvmarg line="${profiler.info.jvmargs}"/>
+                    <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
+                    <arg line="${application.args}"/>
+                    <classpath>
+                        <path path="${run.classpath}"/>
+                    </classpath>
+                    <syspropertyset>
+                        <propertyref prefix="run-sys-prop."/>
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <customize/>
+                </java>
+            </sequential>
+        </macrodef>
+    </target>
+    <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" name="-profile-init-check">
+        <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
+        <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
+    </target>
+    <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
+        <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
+            <attribute default="${main.class}" name="name"/>
+            <attribute default="${debug.classpath}" name="classpath"/>
+            <attribute default="" name="stopclassname"/>
+            <sequential>
+                <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                </nbjpdastart>
+            </sequential>
+        </macrodef>
+        <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
+            <attribute default="${build.classes.dir}" name="dir"/>
+            <sequential>
+                <nbjpdareload>
+                    <fileset dir="@{dir}" includes="${fix.classes}">
+                        <include name="${fix.includes}*.class"/>
+                    </fileset>
+                </nbjpdareload>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-debug-args">
+        <property name="version-output" value="java version &quot;${ant.java.version}"/>
+        <condition property="have-jdk-older-than-1.4">
+            <or>
+                <contains string="${version-output}" substring="java version &quot;1.0"/>
+                <contains string="${version-output}" substring="java version &quot;1.1"/>
+                <contains string="${version-output}" substring="java version &quot;1.2"/>
+                <contains string="${version-output}" substring="java version &quot;1.3"/>
+            </or>
+        </condition>
+        <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
+            <istrue value="${have-jdk-older-than-1.4}"/>
+        </condition>
+        <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
+            <os family="windows"/>
+        </condition>
+        <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
+            <isset property="debug.transport"/>
+        </condition>
+    </target>
+    <target depends="-init-debug-args" name="-init-macrodef-debug">
+        <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${main.class}" name="classname"/>
+            <attribute default="${debug.classpath}" name="classpath"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <java classname="@{classname}" dir="${work.dir}" fork="true">
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <jvmarg line="${debug-args-line}"/>
+                    <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
+                    <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
+                    <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
+                    <jvmarg line="${run.jvmargs}"/>
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                    <syspropertyset>
+                        <propertyref prefix="run-sys-prop."/>
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <customize/>
+                </java>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-macrodef-java">
+        <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
+            <attribute default="${main.class}" name="classname"/>
+            <attribute default="${run.classpath}" name="classpath"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <java classname="@{classname}" dir="${work.dir}" fork="true">
+                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+                    <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
+                    <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
+                    <jvmarg line="${run.jvmargs}"/>
+                    <classpath>
+                        <path path="@{classpath}"/>
+                    </classpath>
+                    <syspropertyset>
+                        <propertyref prefix="run-sys-prop."/>
+                        <mapper from="run-sys-prop.*" to="*" type="glob"/>
+                    </syspropertyset>
+                    <customize/>
+                </java>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-macrodef-copylibs">
+        <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3">
+            <attribute default="${manifest.file}" name="manifest"/>
+            <element name="customize" optional="true"/>
+            <sequential>
+                <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
+                <pathconvert property="run.classpath.without.build.classes.dir">
+                    <path path="${run.classpath}"/>
+                    <map from="${build.classes.dir.resolved}" to=""/>
+                </pathconvert>
+                <pathconvert pathsep=" " property="jar.classpath">
+                    <path path="${run.classpath.without.build.classes.dir}"/>
+                    <chainedmapper>
+                        <flattenmapper/>
+                        <globmapper from="*" to="lib/*"/>
+                    </chainedmapper>
+                </pathconvert>
+                <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
+                <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
+                    <fileset dir="${build.classes.dir}"/>
+                    <manifest>
+                        <attribute name="Class-Path" value="${jar.classpath}"/>
+                        <customize/>
+                    </manifest>
+                </copylibs>
+            </sequential>
+        </macrodef>
+    </target>
+    <target name="-init-presetdef-jar">
+        <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
+            <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
+                <j2seproject1:fileset dir="${build.classes.dir}"/>
+            </jar>
+        </presetdef>
+    </target>
+    <target name="-init-ap-cmdline-properties">
+        <property name="annotation.processing.enabled" value="true"/>
+        <property name="annotation.processing.processors.list" value=""/>
+        <property name="annotation.processing.processor.options" value=""/>
+        <property name="annotation.processing.run.all.processors" value="true"/>
+        <property name="javac.processorpath" value="${javac.classpath}"/>
+        <property name="javac.test.processorpath" value="${javac.test.classpath}"/>
+        <condition property="ap.supported.internal" value="true">
+            <not>
+                <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/>
+            </not>
+        </condition>
+    </target>
+    <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported">
+        <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}">
+            <isfalse value="${annotation.processing.run.all.processors}"/>
+        </condition>
+        <condition else="" property="ap.proc.none.internal" value="-proc:none">
+            <isfalse value="${annotation.processing.enabled}"/>
+        </condition>
+    </target>
+    <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
+        <property name="ap.cmd.line.internal" value=""/>
+    </target>
+    <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
+    <!--
+                ===================
+                COMPILATION SECTION
+                ===================
+            -->
+    <target name="-deps-jar-init" unless="built-jar.properties">
+        <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
+        <delete file="${built-jar.properties}" quiet="true"/>
+    </target>
+    <target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
+        <echo level="warn" message="Cycle detected: WebTerminal was already built"/>
+    </target>
+    <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
+        <mkdir dir="${build.dir}"/>
+        <touch file="${built-jar.properties}" verbose="false"/>
+        <property file="${built-jar.properties}" prefix="already.built.jar."/>
+        <antcall target="-warn-already-built-jar"/>
+        <propertyfile file="${built-jar.properties}">
+            <entry key="${basedir}" value=""/>
+        </propertyfile>
+    </target>
+    <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
+    <target depends="init" name="-check-automatic-build">
+        <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
+    </target>
+    <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
+        <antcall target="clean"/>
+    </target>
+    <target depends="init,deps-jar" name="-pre-pre-compile">
+        <mkdir dir="${build.classes.dir}"/>
+    </target>
+    <target name="-pre-compile">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target if="do.depend.true" name="-compile-depend">
+        <pathconvert property="build.generated.subdirs">
+            <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+                <include name="*"/>
+            </dirset>
+        </pathconvert>
+        <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
+    </target>
+    <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
+        <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
+        <copy todir="${build.classes.dir}">
+            <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+        </copy>
+    </target>
+    <target if="has.persistence.xml" name="-copy-persistence-xml">
+        <mkdir dir="${build.classes.dir}/META-INF"/>
+        <copy todir="${build.classes.dir}/META-INF">
+            <fileset dir="${meta.inf.dir}" includes="persistence.xml"/>
+        </copy>
+    </target>
+    <target name="-post-compile">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
+    <target name="-pre-compile-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
+        <j2seproject3:force-recompile/>
+        <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
+    </target>
+    <target name="-post-compile-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
+    <!--
+                ====================
+                JAR BUILDING SECTION
+                ====================
+            -->
+    <target depends="init" name="-pre-pre-jar">
+        <dirname file="${dist.jar}" property="dist.jar.dir"/>
+        <mkdir dir="${dist.jar.dir}"/>
+    </target>
+    <target name="-pre-jar">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available-mkdist.available">
+        <j2seproject1:jar/>
+    </target>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class-mkdist.available">
+        <j2seproject1:jar manifest="${manifest.file}"/>
+    </target>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
+        <j2seproject1:jar manifest="${manifest.file}">
+            <j2seproject1:manifest>
+                <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
+            </j2seproject1:manifest>
+        </j2seproject1:jar>
+        <echo level="info">To run this application from the command line without Ant, try:</echo>
+        <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
+        <pathconvert property="run.classpath.with.dist.jar">
+            <path path="${run.classpath}"/>
+            <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
+        </pathconvert>
+        <echo level="info">java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
+    </target>
+    <target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available">
+        <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
+        <touch file="${tmp.manifest.file}" verbose="false"/>
+    </target>
+    <target depends="init" if="do.archive+manifest.available" name="-do-jar-with-libraries-copy-manifest">
+        <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
+        <copy file="${manifest.file}" tofile="${tmp.manifest.file}"/>
+    </target>
+    <target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+main.class.available" name="-do-jar-with-libraries-set-main">
+        <manifest file="${tmp.manifest.file}" mode="update">
+            <attribute name="Main-Class" value="${main.class}"/>
+        </manifest>
+    </target>
+    <target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-with-libraries-set-splashscreen">
+        <basename file="${application.splash}" property="splashscreen.basename"/>
+        <mkdir dir="${build.classes.dir}/META-INF"/>
+        <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
+        <manifest file="${tmp.manifest.file}" mode="update">
+            <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
+        </manifest>
+    </target>
+    <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen" if="do.mkdist" name="-do-jar-with-libraries-pack">
+        <j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
+        <echo level="info">To run this application from the command line without Ant, try:</echo>
+        <property location="${dist.jar}" name="dist.jar.resolved"/>
+        <echo level="info">java -jar "${dist.jar.resolved}"</echo>
+    </target>
+    <target depends="-do-jar-with-libraries-pack" if="do.archive" name="-do-jar-with-libraries-delete-manifest">
+        <delete>
+            <fileset file="${tmp.manifest.file}"/>
+        </delete>
+    </target>
+    <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen,-do-jar-with-libraries-pack,-do-jar-with-libraries-delete-manifest" name="-do-jar-with-libraries"/>
+    <target name="-post-jar">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
+    <!--
+                =================
+                EXECUTION SECTION
+                =================
+            -->
+    <target depends="init,compile" description="Run a main class." name="run">
+        <j2seproject1:java>
+            <customize>
+                <arg line="${application.args}"/>
+            </customize>
+        </j2seproject1:java>
+    </target>
+    <target name="-do-not-recompile">
+        <property name="javac.includes.binary" value=""/>
+    </target>
+    <target depends="init,compile-single" name="run-single">
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+        <j2seproject1:java classname="${run.class}"/>
+    </target>
+    <target depends="init,compile-test-single" name="run-test-with-main">
+        <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+        <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
+    </target>
+    <!--
+                =================
+                DEBUGGING SECTION
+                =================
+            -->
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger">
+        <j2seproject1:nbjpdastart name="${debug.class}"/>
+    </target>
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
+        <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
+    </target>
+    <target depends="init,compile" name="-debug-start-debuggee">
+        <j2seproject3:debug>
+            <customize>
+                <arg line="${application.args}"/>
+            </customize>
+        </j2seproject3:debug>
+    </target>
+    <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
+    <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
+        <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
+    </target>
+    <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
+    <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
+        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
+        <j2seproject3:debug classname="${debug.class}"/>
+    </target>
+    <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
+    <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
+        <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
+        <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
+    </target>
+    <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
+    <target depends="init" name="-pre-debug-fix">
+        <fail unless="fix.includes">Must set fix.includes</fail>
+        <property name="javac.includes" value="${fix.includes}.java"/>
+    </target>
+    <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
+        <j2seproject1:nbjpdareload/>
+    </target>
+    <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
+    <!--
+                =================
+                PROFILING SECTION
+                =================
+            -->
+    <target depends="profile-init,compile" description="Profile a project in the IDE." if="netbeans.home" name="profile">
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <profile/>
+    </target>
+    <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="netbeans.home" name="profile-single">
+        <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <profile classname="${profile.class}"/>
+    </target>
+    <!--
+                =========================
+                APPLET PROFILING  SECTION
+                =========================
+            -->
+    <target depends="profile-init,compile-single" if="netbeans.home" name="profile-applet">
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <profile classname="sun.applet.AppletViewer">
+            <customize>
+                <arg value="${applet.url}"/>
+            </customize>
+        </profile>
+    </target>
+    <!--
+                =========================
+                TESTS PROFILING  SECTION
+                =========================
+            -->
+    <target depends="profile-init,compile-test-single" if="netbeans.home" name="profile-test-single">
+        <nbprofiledirect>
+            <classpath>
+                <path path="${run.test.classpath}"/>
+            </classpath>
+        </nbprofiledirect>
+        <junit dir="${profiler.info.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" jvm="${profiler.info.jvm}" showoutput="true">
+            <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
+            <jvmarg value="${profiler.info.jvmargs.agent}"/>
+            <jvmarg line="${profiler.info.jvmargs}"/>
+            <test name="${profile.class}"/>
+            <classpath>
+                <path path="${run.test.classpath}"/>
+            </classpath>
+            <syspropertyset>
+                <propertyref prefix="test-sys-prop."/>
+                <mapper from="test-sys-prop.*" to="*" type="glob"/>
+            </syspropertyset>
+            <formatter type="brief" usefile="false"/>
+            <formatter type="xml"/>
+        </junit>
+    </target>
+    <!--
+                ===============
+                JAVADOC SECTION
+                ===============
+            -->
+    <target depends="init" if="have.sources" name="-javadoc-build">
+        <mkdir dir="${dist.javadoc.dir}"/>
+        <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}">
+            <and>
+                <isset property="endorsed.classpath.cmd.line.arg"/>
+                <not>
+                    <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/>
+                </not>
+            </and>
+        </condition>
+        <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
+            <classpath>
+                <path path="${javac.classpath}"/>
+            </classpath>
+            <fileset dir="${src.dir}" excludes="*.java,${excludes}" includes="${includes}">
+                <filename name="**/*.java"/>
+            </fileset>
+            <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+                <include name="**/*.java"/>
+                <exclude name="*.java"/>
+            </fileset>
+            <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/>
+        </javadoc>
+        <copy todir="${dist.javadoc.dir}">
+            <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
+                <filename name="**/doc-files/**"/>
+            </fileset>
+            <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+                <include name="**/doc-files/**"/>
+            </fileset>
+        </copy>
+    </target>
+    <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
+        <nbbrowse file="${dist.javadoc.dir}/index.html"/>
+    </target>
+    <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
+    <!--
+                =========================
+                JUNIT COMPILATION SECTION
+                =========================
+            -->
+    <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
+        <mkdir dir="${build.test.classes.dir}"/>
+    </target>
+    <target name="-pre-compile-test">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target if="do.depend.true" name="-compile-test-depend">
+        <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir=""/>
+    </target>
+    <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
+        <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir=""/>
+        <copy todir="${build.test.classes.dir}"/>
+    </target>
+    <target name="-post-compile-test">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
+    <target name="-pre-compile-test-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
+        <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
+        <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
+        <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="" srcdir=""/>
+        <copy todir="${build.test.classes.dir}"/>
+    </target>
+    <target name="-post-compile-test-single">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
+    <!--
+                =======================
+                JUNIT EXECUTION SECTION
+                =======================
+            -->
+    <target depends="init" if="have.tests" name="-pre-test-run">
+        <mkdir dir="${build.test.results.dir}"/>
+    </target>
+    <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
+        <j2seproject3:junit testincludes="**/*Test.java"/>
+    </target>
+    <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
+        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+    </target>
+    <target depends="init" if="have.tests" name="test-report"/>
+    <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
+    <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
+    <target depends="init" if="have.tests" name="-pre-test-run-single">
+        <mkdir dir="${build.test.results.dir}"/>
+    </target>
+    <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
+        <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
+        <j2seproject3:junit excludes="" includes="${test.includes}"/>
+    </target>
+    <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
+        <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+    </target>
+    <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
+    <!--
+                =======================
+                JUNIT DEBUGGING SECTION
+                =======================
+            -->
+    <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
+        <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
+        <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
+        <delete file="${test.report.file}"/>
+        <mkdir dir="${build.test.results.dir}"/>
+        <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
+            <customize>
+                <syspropertyset>
+                    <propertyref prefix="test-sys-prop."/>
+                    <mapper from="test-sys-prop.*" to="*" type="glob"/>
+                </syspropertyset>
+                <arg value="${test.class}"/>
+                <arg value="showoutput=true"/>
+                <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
+                <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
+            </customize>
+        </j2seproject3:debug>
+    </target>
+    <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
+        <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
+    </target>
+    <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
+    <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
+        <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
+    </target>
+    <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
+    <!--
+                =========================
+                APPLET EXECUTION SECTION
+                =========================
+            -->
+    <target depends="init,compile-single" name="run-applet">
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
+        <j2seproject1:java classname="sun.applet.AppletViewer">
+            <customize>
+                <arg value="${applet.url}"/>
+            </customize>
+        </j2seproject1:java>
+    </target>
+    <!--
+                =========================
+                APPLET DEBUGGING  SECTION
+                =========================
+            -->
+    <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
+        <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
+        <j2seproject3:debug classname="sun.applet.AppletViewer">
+            <customize>
+                <arg value="${applet.url}"/>
+            </customize>
+        </j2seproject3:debug>
+    </target>
+    <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
+    <!--
+                ===============
+                CLEANUP SECTION
+                ===============
+            -->
+    <target name="-deps-clean-init" unless="built-clean.properties">
+        <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
+        <delete file="${built-clean.properties}" quiet="true"/>
+    </target>
+    <target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
+        <echo level="warn" message="Cycle detected: WebTerminal was already built"/>
+    </target>
+    <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
+        <mkdir dir="${build.dir}"/>
+        <touch file="${built-clean.properties}" verbose="false"/>
+        <property file="${built-clean.properties}" prefix="already.built.clean."/>
+        <antcall target="-warn-already-built-clean"/>
+        <propertyfile file="${built-clean.properties}">
+            <entry key="${basedir}" value=""/>
+        </propertyfile>
+    </target>
+    <target depends="init" name="-do-clean">
+        <delete dir="${build.dir}"/>
+        <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/>
+    </target>
+    <target name="-post-clean">
+        <!-- Empty placeholder for easier customization. -->
+        <!-- You can override this target in the ../build.xml file. -->
+    </target>
+    <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
+    <target name="-check-call-dep">
+        <property file="${call.built.properties}" prefix="already.built."/>
+        <condition property="should.call.dep">
+            <not>
+                <isset property="already.built.${call.subproject}"/>
+            </not>
+        </condition>
+    </target>
+    <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
+        <ant antfile="${call.script}" inheritall="false" target="${call.target}">
+            <propertyset>
+                <propertyref prefix="transfer."/>
+                <mapper from="transfer.*" to="*" type="glob"/>
+            </propertyset>
+        </ant>
+    </target>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/nbproject/genfiles.properties	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=e5603d91
+build.xml.script.CRC32=3684b868
+build.xml.stylesheet.CRC32=28e38971@1.48.0.46
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=e5603d91
+nbproject/build-impl.xml.script.CRC32=00e97611
+nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.48.0.46
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/nbproject/project.properties	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,73 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processor.options=
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+    ${run.classpath}
+debug.test.classpath=\
+    ${run.test.classpath}
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/WebTerminal.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+excludes=
+file.reference.jfxrt.jar=../../../../artifacts/sdk/rt/lib/ext/jfxrt.jar
+file.reference.Library-src=src
+includes=**
+jar.compress=false
+javac.classpath=\
+    ${file.reference.jfxrt.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+    ${javac.classpath}
+javac.source=1.6
+javac.target=1.6
+javac.test.classpath=\
+    ${javac.classpath}:\
+    ${build.classes.dir}
+javac.test.processorpath=\
+    ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+main.class=webterminal.ShellConsole
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=false
+platform.active=default_platform
+run.classpath=\
+    ${javac.classpath}:\
+    ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
+# or test-sys-prop.name=value to set system properties for unit tests):
+run.jvmargs=
+run.test.classpath=\
+    ${javac.test.classpath}:\
+    ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=${file.reference.Library-src}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/nbproject/project.xml	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.java.j2seproject</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
+            <name>WebTerminal</name>
+            <source-roots>
+                <root id="src.dir"/>
+            </source-roots>
+            <test-roots/>
+        </data>
+    </configuration>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/NodeWriter.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+
+import org.w3c.dom.*;
+import java.io.*;
+
+/** Write out a Node in XML text format.
+ * Currently only used for debugging.
+ */
+
+public class NodeWriter {
+    Writer out;
+    public boolean asciiOnly = true;
+
+    public NodeWriter(Writer out) {
+        this.out = out;
+    }
+
+    public static void writeNode (Node node, Writer out) throws IOException {
+        new NodeWriter(out).writeNode(node);
+    }
+
+    public static String writeNodeToString(Node node) {
+        try {
+            StringWriter wr = new StringWriter();
+            new NodeWriter(wr).writeNode(node);
+            return wr.toString();
+        }
+        catch (Throwable ex) {
+            return "writeNodeToString threw "+ex;
+            }
+    }
+    
+    void writeNodeName(Node node) throws IOException {
+        out.write(node.getNodeName());
+    }
+
+    /** Control abbreviation of repeated characters in text.
+        If there are more than this many identical characters
+        in a row, abbreviate.  If 0, don't abbreviate.  */
+    int abbrevRepeatedMinimum = 3;
+
+    void writeData(String data, boolean attribute) throws IOException {
+        int start = 0;
+        int end = data.length();
+        for (int i = 0; i < end;  i++) {
+            char ch = data.charAt(i);
+            String ent = null;
+            int count = 1;
+            if (abbrevRepeatedMinimum > 0) {
+                while (i+count < end && data.charAt(i+count)==ch)
+                    count++;
+            }
+            if (ch == '&')
+                ent = "&amp;";
+            else if (attribute && ch == '\"')
+                ent = "&quot;";
+            else if (! attribute && ch == '<')
+                ent = "&lt;";
+            else if (! attribute && ch == '>')
+                ent = "&gt;";
+            else if (ch < ' ' || (asciiOnly && ch >= 127))
+                ent = "&#x"+Integer.toHexString(ch)+';';
+            if (ent != null) {
+                if (i > start)
+                    out.write(data, start, i-start);
+                start = i+1;
+                out.write(ent);
+            } else if (count >= abbrevRepeatedMinimum) {
+                out.write(data, start, i-start+1);
+                start = i+1;
+            }
+            if (count >= abbrevRepeatedMinimum) {
+                out.write("\\[*"+count+']');
+                i += count-1;
+                start = i+1;
+            }
+        }
+        if (end > start)
+            out.write(data, start, end-start);
+    }
+
+    public void writeNode (Node node) throws IOException {
+        switch (node.getNodeType()) {
+        case Node.DOCUMENT_NODE:
+        case Node.DOCUMENT_FRAGMENT_NODE:
+            writeNodeChildren(node);
+            break;
+
+        case Node.ELEMENT_NODE:
+            Element el = (Element) node;
+            out.write('<');
+            writeNodeName(node);
+            out.write("@"+Integer.toHexString(System.identityHashCode(el)));
+            NamedNodeMap attrs = el.getAttributes();
+            int nattrs = attrs.getLength();
+            for (int i = 0;  i < nattrs;  i++) {
+                writeNode(attrs.item(i));
+            }
+            if (node.getFirstChild() == null)
+                out.write("/>");
+            else {
+                out.write('>');
+                writeNodeChildren(node);
+                out.write("</");
+                writeNodeName(node);
+                out.write('>');
+            }
+            break;
+
+        case Node.ATTRIBUTE_NODE:
+            Attr at = (Attr) node;
+            out.write(' ');
+            writeNodeName(node);
+            out.write('=');
+            out.write('"');
+            writeData(at.getValue(), true);
+            out.write('"');
+            break;
+        
+        case Node.TEXT_NODE:
+            writeData(((Text) node).getData(), false);
+            break;
+
+        case Node.CDATA_SECTION_NODE:
+            writeData(node.getNodeValue(), false);
+            break;
+       
+        case Node.DOCUMENT_TYPE_NODE:
+        default:
+            ;
+        }
+    }
+
+    public void writeNodeChildren (Node node) throws IOException {
+        for (Node ch = node.getFirstChild(); ch != null;
+             ch = ch.getNextSibling()) {
+            writeNode(ch);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/RunInConsole.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+import java.io.*;
+import java.lang.reflect.Method;
+import javafx.application.Application;
+import javafx.scene.layout.*;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import javafx.scene.input.KeyEvent;
+
+/** Run a console-based Java application in a WebTerminal.
+ * Usage: java webterminal.RunInConsole [options] class.name class-args...
+ * This re-binds System.in, System.out, and System.err to a WebTerminal
+ * instance, and then invokes the main method of class.name, passing
+ * it the class-args, roughly as if you'd called:
+ * java class.name class-args...
+ * (Right now no 'options' are supported, but some may be added.)
+ */
+
+public class RunInConsole extends Application {
+
+    WebTerminal console;
+    PipedOutputStream inputSink;
+    Writer inputWriter;
+
+    Scene createScene() {
+        console = new WebTerminal() {
+                protected void enter (KeyEvent ke) {
+                    String text = console.handleEnter(ke);
+                    if (inputWriter != null) {
+                        synchronized (inputWriter) {
+                            try {
+                                inputWriter.write(text);
+                                inputWriter.write("\r\n");
+                                inputWriter.flush();
+                                //pin.notifyAll();
+                            }
+                            catch (Throwable ex) {
+                                ex.printStackTrace();
+                                System.exit(-1);
+                            }
+                        }
+                    }
+                }
+            };
+        //VBox.setVgrow(console.webView, Priority.ALWAYS);
+
+        VBox pane = console;
+        Scene scene = new Scene(pane);
+        // Make a bottom gray bar to free the resize corner on Mac
+        //scene.setFill(Color.GRAY);
+        return scene;
+    }
+
+    String[] restArgs;
+    Method mainMethod;
+    String className;
+
+    void getMainMethod() throws Throwable {
+        java.util.List<String> args = getParameters().getRaw();
+        int nargs = args.size();
+        className = args.get(0);
+        restArgs = new String[nargs-1];
+        args.subList(1, nargs).toArray(restArgs);
+        Class clas = Class.forName(className, false, RunInConsole.class.getClassLoader());
+        mainMethod = clas.getDeclaredMethod("main", String[].class);
+    }
+
+    @Override public void start(Stage stage) {
+        final Scene scene = createScene();
+        inputSink = new PipedOutputStream();
+        try {
+            getMainMethod();
+            inputWriter = new OutputStreamWriter(inputSink);
+            System.setIn(new PipedInputStream(inputSink));
+        }
+        catch (java.lang.ClassNotFoundException ex) {
+            System.err.println("can't find class "+className);
+            System.exit(-1);
+        }
+        catch (Throwable ex) {
+            WTDebug.println("caught "+ex);
+            System.exit(-1);
+        }
+        //WebTerminal.origErr = System.err;
+
+        stage.setTitle("Jfx-Shell");
+
+        stage.setScene(scene);
+        //stage.sizeToScene();
+        stage.setWidth(900);
+        stage.setHeight(700);
+        stage.show();
+
+        OutputStream wout = new WebOutputStream(new WebWriter(console, 'O'));
+        OutputStream werr = new WebOutputStream(new WebWriter(console, 'E'));
+        System.setOut(new PrintStream(new BufferedOutputStream(wout, 128), true));
+        System.setErr(new PrintStream(new BufferedOutputStream(werr, 128), true));
+        (new Thread() {
+                public void run() {
+                    try {
+                        mainMethod.invoke(null, new Object[] { restArgs });
+                    } catch (Throwable ex) {
+                        WTDebug.println("caught while executing main "+ex);
+                    }
+                }}).start();
+    }
+
+    public static void main(String[] args) {
+        WTDebug.init();
+        Application.launch(args);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/ShellConsole.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+import javafx.scene.Node;
+import javafx.scene.Scene;
+import javafx.scene.layout.*;
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.scene.input.KeyEvent;
+import javafx.scene.web.*;
+import javafx.stage.Stage;
+import java.io.*;
+import java.util.List;
+
+/** Application to run a Process in a WebTerminal window.
+ * The Process is run with standard input, output, and error streams
+ * bound to an interactive WebTerminal window.
+ * The WebTerminal window is bare, with no menubar or other "chrome".
+ * (That should probably change, at least when running as an Application.)
+ *
+ * Usage:
+ * <pre>
+ * java webterminal.ShellConsole [options] [command]
+ * </pre>
+ * So far no {@code [options]} are supported.
+ * The {@code [command]} is the arguments to the Process.
+ * The default for [command] is "bash" "--noediting" "-i".
+ */
+
+public class ShellConsole extends Application
+{
+    WebTerminal replNode;
+
+    Process process;
+
+    Scene createScene() {
+        replNode = new WebTerminal() {
+                protected void enter (KeyEvent ke) {
+                    String text = replNode.handleEnter(ke);
+                    if (pin != null) {
+                        synchronized (pin) {
+                            try {
+                                pin.write(text);
+                                pin.write("\n");
+                                pin.flush();
+                                //pin.notifyAll();
+                            }
+                            catch (Throwable ex) {
+                                ex.printStackTrace();
+                                System.exit(-1);
+                            }
+                        }
+                    }
+                }
+            };
+        VBox.setVgrow(replNode.webView, Priority.ALWAYS);
+
+        VBox pane = replNode;
+        Scene scene = new Scene(pane);
+        // Make a bottom gray bar to free the resize corner on Mac
+        //scene.setFill(Color.GRAY);
+        return scene;
+    }
+
+    Writer pin;
+    Reader pout;
+    Reader perr;
+
+    public static String[] defaultCommandWithArgs
+        = {"bash", "--noediting", "-i" };
+
+    @Override public void start(Stage stage) {
+        try {
+            List<String> args = getParameters().getRaw();
+            int argsSize = args.size();
+            String[] commandWithArgs = argsSize == 0 ? defaultCommandWithArgs
+                : args.toArray(new String[argsSize]);
+            ProcessBuilder pbuilder = new ProcessBuilder(commandWithArgs);
+            pbuilder.redirectErrorStream(true);
+            process = pbuilder.start();
+            pin = new OutputStreamWriter(process.getOutputStream());
+            pout = new InputStreamReader(process.getInputStream());
+            perr = new InputStreamReader(process.getErrorStream());
+        } catch (Throwable ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        }
+        final Scene scene = createScene();
+        stage.setTitle("Jfx-Shell");
+
+        stage.setScene(scene);
+        stage.setWidth(900);
+        stage.setHeight(700);
+        stage.show();
+
+        initialize0(); // ???
+    }
+
+    public static void main(String[] args) {
+        Application.launch(args);
+    }
+
+    private void copyThread(final Reader fromInferior, final WebWriter toPane) {
+        Thread th = new Thread() {
+                char[] buffer = new char[1024];
+                public void run () {
+                    for (;;) {
+                        try {
+                            int count = fromInferior.read(buffer);
+                            if (count < 0)
+                                break;
+                            toPane.write(buffer, 0, count);
+                        } catch (Throwable ex) {
+                            ex.printStackTrace();
+                            System.exit(-1);
+                        }
+                    }
+                }
+            }; 
+        th.start();
+    }
+
+    WebWriter out_stream;
+    WebWriter err_stream;
+    public void initialize0 () {
+        out_stream = new WebWriter(this.replNode, 'O');
+        err_stream = new WebWriter(this.replNode, 'E');
+        copyThread(pout, out_stream);
+        copyThread(perr, err_stream);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/WTDebug.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+import java.io.*;
+import org.w3c.dom.*;
+
+/** Some debugging utilities. */
+
+public class WTDebug {
+static 
+    PrintStream origErr;
+    public static void init() {
+        if (origErr == null)
+            origErr = System.err;
+    }
+
+    static {
+        init();
+    }
+
+    public static void print(Object obj) {
+        origErr.print(""+obj);
+    }
+
+    public static void println(Object obj) {
+        origErr.println(""+obj);
+    }
+
+    public static String pnode(org.w3c.dom.Node n) {
+
+        if (n == null) return "(null)";
+        if (n instanceof CharacterData)
+            return n.toString()+'\"'+toQuoted(((CharacterData)n).getData())+'\"'+"@"+Integer.toHexString(System.identityHashCode(n));
+        return n+"/"+n.getNodeName()+"@"+Integer.toHexString(System.identityHashCode(n));
+    }
+
+    public static String toQuoted(String str) {
+        int len = str.length();
+        StringBuilder buf = new StringBuilder();
+        for (int i = 0;  i < len;  i++) {
+            char ch = str.charAt(i);
+            if (ch == '\n')
+                buf.append("\\n");
+            else if (ch == '\r')
+                buf.append("\\r");
+            else if (ch == '\t')
+                buf.append("\\t");
+            else if (ch == '\033')
+                buf.append("\\E");
+            else if (ch < ' ' || ch >= 127)
+                buf.append("\\"+(char)(((ch>>6)&7)+'0')+(char)(((ch>>3)&7)+'0')+(char)((ch&7)+'0'));
+            else {
+                if (ch == '\"' || ch == '\'')
+                    buf.append('\\');
+                buf.append(ch);
+            }
+        }
+        return buf.toString();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/WebOutputStream.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+import java.io.*;
+
+/** A Simple OutputStream that decodes UTF-8 to a WebWriter.
+ */
+
+public class WebOutputStream extends OutputStream {
+    WebWriter out;
+    int partialChar;
+    int bytesNeeded = 0;
+
+    public WebOutputStream(WebWriter out) { this.out = out;}
+
+    public void write(int b) {
+        if (b >= 0) {
+            partialChar = b;
+            bytesNeeded = 0;
+        }
+        else if ((b & 0xC0) == 0x40) { // continuation byte
+            partialChar = (partialChar << 6) | (b & 0x3F);
+            bytesNeeded--;
+        }
+        else if ((b & 0xE0) == 0xC0) { // 1st of 2
+            partialChar = b & 0x1F;
+            bytesNeeded = 1;
+        }
+        else if ((b & 0xF0) == 0xE0) { // 1st of 3
+            partialChar = b & 0xF;
+            bytesNeeded = 2;
+        }
+        else if ((b & 0xF8) == 0xF0) { // 1st of 4
+            partialChar = b & 0x7;
+            bytesNeeded = 3;
+        }
+        else if ((b & 0xFC0) == 0xF8) { // 1st of 5
+            partialChar = b & 0x3;
+            bytesNeeded = 4;
+        }
+        if (bytesNeeded == 0) {
+            int ch = partialChar;
+            if (ch > 0x10000) {
+                out.write((char) (((ch - 0x10000) >> 10) + 0xD800));
+                ch = ((ch & 0x3FF) + 0xDC00);
+            }
+            out.write((char) ch);
+        }
+    }
+    public void flush() { out.flush(); }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/WebTerminal.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,1787 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+
+import javafx.scene.web.*;
+import org.w3c.dom.*;
+import org.w3c.dom.Node;
+import javafx.scene.input.KeyEvent;
+import javafx.scene.layout.*;
+import org.w3c.dom.events.EventTarget;
+import netscape.javascript.JSObject;
+import javafx.application.Platform;
+import javafx.scene.input.KeyCode;
+import javafx.scene.control.Control;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
+import javafx.concurrent.Worker.State;
+import java.util.List;
+import java.util.ArrayList;
+
+/** Implements a "rich-term" console/terminal based on a WebView.
+ *
+ * A "line" is a sequence of text or inline elements - usually span elements.
+ * A div or paragraph of N lines has (N-1) br elements between lines.
+ * (br elements are only allowed in div or p elements.)
+ */
+public abstract class WebTerminal extends VBox // FIXME should extend Control
+      implements javafx.event.EventHandler, org.w3c.dom.events.EventListener
+                      /*implements KeyListener, ChangeListener*/ 
+{
+    WebView webView;
+    protected WebView getWebView() { return webView; } 
+
+    protected WebEngine webEngine;
+
+    String defaultBackgroundColor = "white";
+    String defaultForegroundColor = "black";
+
+    public boolean isLineEditing() { return lineEditing; }
+    public void setLineEditing(boolean lineEditing) {
+        this.lineEditing = lineEditing;
+    }
+    private boolean lineEditing = true;
+
+    public boolean outputLFasCRLF() { return isLineEditing(); }
+
+    /** The current input line.
+     * Note there is always a current (active) input line, even if the
+     * inferior isn't ready for it, and hasn't emitted a prompt.
+     * This is to support type-ahead, as well as application code
+     * reading from standard input.  (FUTURE - untested.)
+     */
+    public Element getInputLine() { return inputLine; }
+    public void setInputLine(Element inputLine) { this.inputLine = inputLine; }
+    Element inputLine;
+
+    Document documentNode;
+    Element bodyNode;
+
+    public Document getDocumentNode() { return documentNode; }
+
+    /** The element (normally a div or pre) which cursor navigation is relative to.
+     * Cursor motion is relative to the start of this element.
+     * "Erase screen" only erases in this element.
+     */
+    public Element getCursorHome() { return cursorHome; }
+    public void setCursorHome(Element cursorHome) { this.cursorHome = cursorHome; }
+    /** The element (normally div) which cursor navigation is relative to. */
+    private Element cursorHome;
+
+    /** Current line number, 0-origin, relative to start of cursorHome.
+     * -1 if unknown. */
+    int currentCursorLine = -1;
+    /** Current column number, 0-origin, relative to start of cursorHome.
+     * -1 if unknown. */
+    int currentCursorColumn = -1;
+
+    /** This is the column width at which the next line implicitly starts.
+     * Compare with wrapWidth - if both are less than Integer.MAX_VALUE
+     * then they should normally be equal. */
+    int columnWidth = Integer.MAX_VALUE;
+
+    /** If inserting a character at this column width, insert a wrap-break. */
+    int wrapWidth = 80;
+    boolean wrapOnLongLines = true;
+
+    public void resetCursorCache() {
+        currentCursorColumn = -1;
+        currentCursorLine = -1;
+    }
+
+    void updateCursorCache() {
+        long lcol = delta2D(cursorHome, outputBefore);
+        currentCursorLine = (int) (lcol >> 32);
+        currentCursorColumn = (int) (lcol >> 1) & 0x7fffffff;
+    }
+
+    /** Get line of current cursor position, starting with 0 at the top. */
+    public int getCursorLine() {
+        if (currentCursorLine < 0)
+            updateCursorCache();
+        return currentCursorLine;
+    }
+
+    /** Get column of current cursor position, starting with 0 at the left. */
+    public int getCursorColumn() {
+        if (currentCursorColumn < 0)
+            updateCursorCache();
+        return currentCursorColumn;
+    }
+
+    /** First (top) line of scroll region, 0-origin. */
+    int scrollRegionTop = 0;
+    /** Last (bottom) line of scroll region, 1-origin.
+     * Equivalently, first line following scroll region, 0-origin.
+     * The value -1 is equivalent to numRows. */
+    int scrollRegionBottom = -1;
+
+    public int getScrollTop() {
+        return scrollRegionTop;
+    }
+    public int getScrollBottom() {
+        return scrollRegionBottom < 0 ? getNumRows() : scrollRegionBottom;
+    }
+
+    // 0-origin
+    int savedCursorLine, savedCursorColumn;
+
+    public void saveCursor() {
+        savedCursorLine = getCursorLine();
+        savedCursorColumn = getCursorColumn();
+    }
+ 
+    public void restoreCursor() {
+        moveTo(savedCursorLine, savedCursorColumn);
+    }
+ 
+    /** The output position (cursor).
+     * Insert output before this node.
+     * (For now always (???) equal to inputLine except for temporary updates,
+     * but in the future they may be separated.)
+     * (For now, never null, but in the future, if it is null, it means
+     * append output to the end of the output container's children.)
+     */
+    public Node getOutputPosition() { return outputBefore; }
+    org.w3c.dom.Node outputBefore;
+    public void setOutputPosition(Node node) {
+        outputBefore = node; }
+
+    /** The parent node of the output position. */
+    public Node getOutputContainer() { return outputContainer; }
+    Node outputContainer;
+
+    /* * Index of outputContainer in which to insert output.
+     * Normally this is the same as outputNode's text length,
+     * but in the future we may support cursor movement commands.
+     */
+    //int outputPosition = -1;
+
+    int inputLineNumber = 0;
+
+    protected void loadSucceeded() {
+        addInputLine();
+        outputBefore = inputLine;
+    }
+
+    public WebTerminal() {
+        webView = new WebView();
+        webEngine = webView.getEngine();
+        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
+                public void changed(ObservableValue<? extends State> ov, State t, State newValue) {
+                    if (newValue == State.SUCCEEDED) {
+                        initialize();
+                        loadSucceeded();
+                    }
+                }});
+
+        loadPage(webEngine);
+        this.getChildren().add(webView);
+
+        // We run the key-event handlers during the filter (capture) phase,
+        // rather than the normal (bubbling) phase.  This allows us to
+        // consume the event, so it never gets to the bubbling phase - and
+        // thus never gets passed to the native component.  (In JavaScript
+        // one can call preventDefault or have the handler return false,
+        // but we don't have the functionality with JavaFX events.)
+        webView.addEventFilter(KeyEvent.KEY_PRESSED, this);
+        webView.addEventFilter(KeyEvent.KEY_TYPED, this);
+
+        VBox.setVgrow(webView, Priority.ALWAYS);
+    }
+
+    public static final boolean USE_XHTML = true;
+    public static final String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
+    public static final String htmlNamespace = USE_XHTML ? XHTML_NAMESPACE : "";
+
+    /** URL for the initial page to be loaded. */
+    protected String pageUrl() {
+        String rname = USE_XHTML ? "repl.xml" : "repl.html";
+        java.net.URL rurl = WebTerminal.class.getResource(rname);
+        if (rurl == null)
+            throw new RuntimeException("no initial web page "+rname);
+        return rurl.toString();
+    }
+
+    /** Load the start page.  Do not call directly.
+     * Can be overridden to load a start page from a String:
+     * webEngibe.loadContent("initialContent", "MIME/type");
+     */
+    protected void loadPage(WebEngine webEngine) {
+        webEngine.load(pageUrl());
+    }
+
+    protected void initialize() {
+        documentNode = webEngine.getDocument();
+        bodyNode = documentNode.getElementById("body");
+
+        //((EventTarget) bodyNode).addEventListener("click", this, false);
+
+        //if (isLineEditing())             ((JSObject) bodyNode).call("focus");
+        // Element initial = documentNode.getElementById("initial"); FIXME LEAKS
+        Element initial = (Element) bodyNode.getFirstChild();
+        cursorHome = initial;
+        outputContainer = initial;
+    }
+
+    /** For debugging.*/
+    public String getHTMLText() {
+        if (true) {
+            return NodeWriter.writeNodeToString(bodyNode);
+        } /*else if (true) {
+        java.io.StringWriter sw = new java.io.StringWriter();
+        gnu.xml.XMLPrinter xp = new gnu.xml.XMLPrinter(sw, false);
+        ConsumeDOM.consumeNode(bodyNode, xp, true);
+        xp.flush();
+        return sw.toString();
+        } */ else if (false) {
+            return ((JSObject) (Object) bodyNode).getMember("innerHTML").toString();
+        } else {
+        com.sun.webkit.WebPage webPage = com.sun.javafx.webkit.Accessor.getPageFor(webEngine);
+        return "HTML="+webPage+"["+webPage.getHtml(webPage.getMainFrame())+"]";
+        //return  webEngine.getPage().toString(); //executeScript("document.innerHTML").toString();
+        }
+    }
+
+    /*
+    public void setHtmlText(String htmlText) {
+        ((HTMLEditorSkin)getSkin()).setHTMLText(htmlText);
+    }
+    */
+
+    protected void setEditable(Element element, boolean editable) {
+        ((JSObject) element).setMember("contentEditable", editable);
+    }
+    
+    protected void setEditable(boolean editable) {
+        setEditable(getInputLine(), editable);
+    }
+    
+    /** Add an input span as the last child of outputContainer.
+     */
+    public void addInputLine () {
+        Element inputNode = createSpanNode();
+        String id = "input"+(++inputLineNumber);
+
+        inputNode.setAttribute("id", id);
+        inputNode.setAttribute("std", "input");
+        setEditable(inputNode, true);
+        outputContainer.appendChild(inputNode);
+
+        // KLUDGE: The insertion caret isn't visible until something has inserted
+        // into the input line.  So we insert U-200B "zero width space".
+        // This gets removed in enter.
+        // (Note if a space is inserted and removed from the UI then the
+        // caret remains visible.  Thus a cleaner work-around would be if
+        // we could simulate this.  I haven't gotten that to work so far.)
+        Text dummyText = documentNode.createTextNode("\u200B");
+        //Text dummyText = documentNode.createTextNode("\n");
+        inputNode.appendChild(dummyText);
+        inputLine = inputNode;
+        setFocus();
+    }
+
+    public String inputAsString() { return toString(inputLine.getChildNodes());}
+
+    // DEBUGGING:
+    protected abstract void enter(KeyEvent ke);
+
+    public String grabInput(Element input) {
+        //WTDebug.println("grabInput input:"+WTDebug.pnode(input)+" firstCh:"+WTDebug.pnode(input.getFirstChild())+" inputL:"+WTDebug.pnode(inputLine));
+        String text = ((Text)input.getChildNodes().item(0)).getData();
+        //if (text == null) text = "";
+
+        // Replace Non-breaking space (inserted by webkit) with regular space.
+        text = text.replace((char) 160, ' ');
+        int tlen = text.length();
+        // See comment in addInputLine.
+        if (tlen > 0 && text.charAt(tlen-1) == (char) 0x200B) // OLD? 
+            text = text.substring(0, --tlen);
+        if (tlen > 0 && text.charAt(0) == (char) 0x200B) // NEW?
+        { tlen--; text = text.substring(1);}
+        return text;
+    }
+
+    protected String handleEnter (KeyEvent ke) {
+        /*
+        javafx.scene.input.Clipboard cc = javafx.scene.input.Clipboard.getSystemClipboard();
+        System.err.println("SCLIP has-h:"+cc.hasHtml()+" has-s:"+cc.hasString()+" str:"+cc.getString());
+        */
+        String text = grabInput(inputLine);
+        nextInputLine();
+        //super.processKeyEvent(ke);
+        return text;
+    }
+
+    protected void nextInputLine() {
+        outputBefore = inputLine.getNextSibling();
+        setEditable(false);
+        insertBreak();
+        addInputLine();
+        outputBefore = inputLine;
+    }
+
+    public void insertOutput (final String str, final char kind) {
+        Platform.runLater(new Runnable() {
+                public void run() {
+                    insertString(str, kind);
+                }
+            });
+    }
+
+    // States of escape sequences handler state machine.
+    static final int INITIAL_STATE = 0;
+    static final int SEEN_ESC_STATE = 1;
+    /** We have seen ESC '['. */
+    static final int SEEN_ESC_LBRACKET_STATE = 2;
+    /** We have seen ESC '[' '?'. */
+    static final int SEEN_ESC_LBRACKET_QUESTION_STATE = 3;
+    /** We have seen ESC ']'. */
+    static final int SEEN_ESC_RBRACKET_STATE = 4;
+    /** We have seen ESC ']' numeric-parameter ';'. */
+    static final int SEEN_ESC_BRACKET_TEXT_STATE = 5;
+    int controlSequenceState = INITIAL_STATE;
+
+    int prevParametersCount = 0; // number of semicolon argument separators seen.
+    // The actual number of arguments seen is:
+    // prevParametersCount+(curNumParameter>=0?1:0)
+    // Of these prevParametersCount are in the first prevParametersCount
+    // elements of prevNumParameters.
+    int curNumParameter = -1;
+    int[] prevNumParameters = null;
+    StringBuilder curTextParameter;
+
+    boolean insertMode;
+    public boolean inInsertMode() { return insertMode; }
+    public void setInsertMode(boolean enable) { insertMode = enable; }
+
+    int numRows = 24, numCols = 80;
+    public int getNumColumns() { return numCols; }
+    public int getNumRows() { return numRows; }
+    public void setRowsColumns(int rows, int columns) {
+        numCols = columns;
+        numRows = rows;
+        wrapWidth = columns;
+    }
+
+    public void handleBell() {
+        // Nothing.
+    }
+
+    public void handleOperatingSystemControl(int code, String text) {
+        if (code == 72) {
+            ((com.sun.webkit.dom.HTMLElementImpl) inputLine).insertAdjacentHTML("beforeBegin", text);
+        }
+        else {
+            // WTDebug.println("Saw Operating System Control #"+code+" \""+WTDebug.toQuoted(text)+"\"");
+        }
+    }
+
+    boolean usingAlternateScreenBuffer;
+    private Element savedCursorHome;
+    public void setAlternateScreenBuffer(boolean val) {
+        if (usingAlternateScreenBuffer != val) {
+            if (val) {
+                // FIXME should scroll top of new buffer to top of window.
+                Element buffer = createElement("pre");
+                savedCursorHome = cursorHome;
+                bodyNode.appendChild(buffer);
+                cursorHome = buffer;
+                outputContainer.removeChild(inputLine);
+                buffer.appendChild(inputLine);
+                outputContainer = buffer;
+                outputBefore = inputLine;
+                currentCursorColumn = 0;
+                currentCursorLine = 0;
+                setFocus();
+            } else { 
+                outputContainer.removeChild(inputLine);
+                cursorHome.getParentNode().removeChild(cursorHome);
+                cursorHome = savedCursorHome;
+                cursorHome.appendChild(inputLine);
+                outputContainer = cursorHome;
+                outputBefore = inputLine;
+                savedCursorHome = null;
+                outputContainer = cursorHome;
+                resetCursorCache();
+                setFocus();
+            }
+            usingAlternateScreenBuffer = val;
+            scrollRegionTop = 0;
+            scrollRegionBottom = -1;
+        }
+    }
+
+    public void handleControlSequence(char last) {
+        switch (last) {
+        case '@':
+            boolean saveInsertMode = inInsertMode();
+            setInsertMode(true);
+            if (curNumParameter<0) curNumParameter = 1;
+            insertSimpleOutput(makeSpaces(curNumParameter), 0, curNumParameter,
+                               'O', getCursorColumn()+curNumParameter);
+            cursorLeft(curNumParameter);
+            setInsertMode(saveInsertMode);
+            break;
+        case 'd': // Line Position Absolute
+            if (curNumParameter<0) curNumParameter = 1;
+            moveTo(curNumParameter-1, getCursorColumn());
+            break;
+        case 'h':
+            if (controlSequenceState == SEEN_ESC_LBRACKET_QUESTION_STATE) {
+                // DEC Private Mode Set (DECSET)
+                switch (curNumParameter) {
+                case 47:
+                case 1047:
+                    setAlternateScreenBuffer(true); break;
+                case 1048: saveCursor(); break;
+                case 1049: saveCursor(); setAlternateScreenBuffer(true); break;
+                }
+            }
+            else {
+                switch (curNumParameter) {
+                case 4: setInsertMode(true); break;
+                }
+            }
+            break;
+        case 'l':
+            if (controlSequenceState == SEEN_ESC_LBRACKET_QUESTION_STATE) {
+                // DEC Private Mode Reset (DECRST)
+                switch (curNumParameter) {
+                case 47:
+                case 1047:
+                    // should clear first?
+                    setAlternateScreenBuffer(false); break;
+                case 1048: restoreCursor(); break;
+                case 1049: setAlternateScreenBuffer(false); restoreCursor(); break;
+              }
+            }
+            else {
+                switch (curNumParameter) {
+                case 4: setInsertMode(false); break;
+                }
+            }
+            break;
+        case 'm':
+            for (int i = 0;  i <= prevParametersCount;  i++) {
+                int val = i < prevParametersCount ? prevNumParameters[i] : curNumParameter;
+                if (val <= 0) {
+                    currentStyles.clear();
+                }
+                else {
+                    int nstyles = currentStyles.size();
+                    switch (val) {
+                    case 1:
+                        pushSimpleStyle("font-weight:", "bold");
+                        break;
+                    case 22:
+                        pushSimpleStyle("font-weight:", null/*"normal"*/);
+                        break;
+                    case 4:
+                        pushSimpleStyle("text-decoration:", "underline");
+                        break;
+                    case 24:
+                        pushSimpleStyle("text-decoration:", null/*"none"*/);
+                        break;
+                    case 7:
+                        pushSimpleStyle("color:", defaultBackgroundColor);
+                        pushSimpleStyle("background-color:", defaultForegroundColor);
+                        break;
+                    case 27:
+                        pushSimpleStyle("color:", null/*defaultForegroundColor*/);
+                        pushSimpleStyle("background-color:", null/*defaultBackgroundColor*/);
+                        break;
+                    case 30: pushSimpleStyle("color:", "black"); break;
+                    case 31: pushSimpleStyle("color:", "red"); break;
+                    case 32: pushSimpleStyle("color:", "green"); break;
+                    case 33: pushSimpleStyle("color:", "yellow"); break;
+                    case 34: pushSimpleStyle("color:", "blue"); break;
+                    case 35: pushSimpleStyle("color:", "magenta"); break;
+                    case 36: pushSimpleStyle("color:", "cyan"); break;
+                    case 37: pushSimpleStyle("color:", "white"); break;
+                    case 39: pushSimpleStyle("color:", null/*defaultForegroundColor*/); break;
+                    case 40: pushSimpleStyle("background-color:", "black"); break;
+                    case 41: pushSimpleStyle("background-color:", "red"); break;
+                    case 42: pushSimpleStyle("background-color:", "green"); break;
+                    case 43: pushSimpleStyle("background-color:", "yellow"); break;
+                    case 44: pushSimpleStyle("background-color:", "blue"); break;
+                    case 45: pushSimpleStyle("background-color:", "magenta"); break;
+                    case 46: pushSimpleStyle("background-color:", "cyan"); break;
+                    case 47: pushSimpleStyle("background-color:", "white"); break;
+                    case 49: pushSimpleStyle("background-color:", null/*defaultBackgroundColor*/); break;
+                    }
+                }
+            }
+            adjustStyleNeeded = true;
+            break;
+        case 'r':
+            int top = prevParametersCount >= 1 ? prevNumParameters[0] : curNumParameter>=0 ? curNumParameter : 1;
+            int bottom = prevParametersCount >= 2 ? prevNumParameters[1]
+                : prevParametersCount==1 && curNumParameter>=0 ? curNumParameter : -1;
+            scrollRegionTop = top - 1;
+            scrollRegionBottom = bottom;
+            break;
+        case 'A': // cursor up
+            if (curNumParameter<0) curNumParameter = 1;
+            cursorDown(- curNumParameter);
+            break;
+        case 'B': // cursor down
+            if (curNumParameter<0) curNumParameter = 1;
+            cursorDown(curNumParameter);
+            break;
+        case 'C':
+            if (curNumParameter<0) curNumParameter = 1;
+            cursorRight(curNumParameter);
+            break;
+        case 'D':
+            if (curNumParameter<0) curNumParameter = 1;
+            cursorLeft(curNumParameter);
+            break;
+        case 'H':
+            int row = prevParametersCount >= 1 ? prevNumParameters[0] : curNumParameter>=0 ? curNumParameter : 1;
+            int col = prevParametersCount >= 2 ? prevNumParameters[1]
+                : prevParametersCount==1 && curNumParameter>=0 ? curNumParameter : 1;
+            moveTo(row-1, col-1);
+            break;
+        case 'J':
+            if (curNumParameter<0) curNumParameter = 0;
+            if (curNumParameter == 0) // Erase below.
+                eraseUntil(cursorHome);
+            else {
+                int saveLine = getCursorLine();
+                int saveCol = getCursorColumn();
+                if (curNumParameter == 1) { // Erase above
+                    for (int line = 0;  line < saveLine;  line++) {
+                        moveTo(line, 0);
+                        eraseLineRight();
+                    }
+                    if (saveCol != 0) {
+                        moveTo(saveLine, 0);
+                        eraseCharactersRight(saveCol, false);
+                    }
+                } else { // Erase all
+                    moveTo(0, 0);
+                    eraseUntil(cursorHome);
+                }
+                moveTo(saveLine, saveCol);
+            }
+            break;
+        case 'K':
+            if (curNumParameter!=1)
+                eraseLineRight();
+            if (curNumParameter>=1)
+                eraseLineLeft();
+            break;
+        case 'L': // Insert lines
+            if (curNumParameter<0) curNumParameter = 1;
+            insertLines(curNumParameter);
+            break;
+        case 'M': // Delete lines
+            if (curNumParameter<0) curNumParameter = 1;
+            deleteLines(curNumParameter);
+            break;
+        case 'P': // Delete characters
+            if (curNumParameter<0) curNumParameter = 1;
+            eraseCharactersRight(curNumParameter, true);
+            break;
+        case 'S':
+            if (curNumParameter<0) curNumParameter = 1;
+            scrollForward(curNumParameter);
+            break;
+        case 'T':
+            if (curNumParameter<0) curNumParameter = 1;
+            else if (curNumParameter >= 5)
+                ; // FIXME Initiate mouse tracking.
+            scrollReverse(curNumParameter);
+            break;
+        }
+    }
+
+    /** A stack of currently active "style" strings. */
+    public List<String> currentStyles = new ArrayList<String>();
+
+    /** True if currentStyles may not match the current style context.
+     * Thus the context needs to be adjusted before text is inserted. */
+    boolean adjustStyleNeeded;
+
+    /** Add a style property specifier to the currentStyles list.
+     * However, if the new specifier "cancels" an existing specifier,
+     * just remove the old one.
+     * @param styleNameWithColon style property name including colon,
+     *     (for example "text-decoration:").
+     * @param styleValue style property value string (for example "underline"),
+     *     or null to indicate the default value.
+     */
+    protected void pushSimpleStyle(String styleNameWithColon, String styleValue) {
+        int nstyles = currentStyles.size();
+        for (int i = 0;  i < nstyles;  ) {
+            String style = currentStyles.get(i);
+            if (style.startsWith(styleNameWithColon)) {
+                currentStyles.remove(i);
+                nstyles--;
+            } else
+                i++;
+        }
+        if (styleValue != null)
+            currentStyles.add(styleNameWithColon+' '+styleValue);
+    }
+
+    /** Adjust style at current position to match desired style.
+     * The desired style is a specified by the currentStyles list.
+     * This usually means adding {@code <span style=...>} nodes around the
+     * current position.  If the current position is already inside
+     * a {@code <span style=...>} node that doesn't match the desired style,
+     * then we have to split the {@code span} node so the current
+     * position is not inside the span node, but text before and after is.
+     */
+    protected void adjustStyle() {
+        adjustStyleNeeded = false;
+
+        List<String> parentStyles = new ArrayList<String>();
+        for (Node n = outputContainer;  n != bodyNode && n != null;
+             n = n.getParentNode()) {
+            String style;
+            if (n instanceof Element) {
+                style = ((Element) n).getAttribute("style");
+                if (style != null && style.length() > 0)
+                    parentStyles.add(style);
+            }
+        }
+
+        // Compare the parentStyles and currentStyles lists,
+        // so we can "keep" the styles where the match, and pop or add
+        // the styles where they don't match.
+        int keptStyles = 0;
+        int currentStylesLength = currentStyles.size();
+        int j;
+        for (j = parentStyles.size(); --j >= 0; ) {
+            String parentStyle = parentStyles.get(j);
+            if (parentStyle != null) {
+                if (keptStyles == currentStylesLength) {
+                    break;
+                }
+
+                // Matching is made more complicate because parentStyles
+                // may specify multiple properties in a single style attribute.
+                // For example "color: red; background-color: blue".
+                int k = 0;
+                while (k >= 0 && (parentStyle = parentStyle.trim()).length() > 0) {
+                    // Assume property values cannot contain semi-colons.
+                    // This may fail if there are string-valued properties,
+                    // since we don't check for quoted semi-colons.
+                    int semi = parentStyle.indexOf(';');
+                    String s;
+                    if (semi >= 0) {
+                        s = parentStyle.substring(0, semi).trim();
+                        parentStyle = parentStyle.substring(semi+1);
+                        if (s.length() == 0)
+                            continue;
+                    }
+                    else {
+                        s = parentStyle;
+                        parentStyle = "";
+                    }
+                    if (keptStyles+k < currentStylesLength
+                        && s.equals(currentStyles.get(keptStyles+k)))
+                        k++;
+                    else
+                        k = -1;
+                }
+                if (k >= 0)
+                    keptStyles += k;
+                else
+                    break;                   
+            }
+        }
+        int popCount = j+1;
+        while (--popCount >= 0) {
+            popStyle();
+        }
+        if (keptStyles < currentStylesLength) {
+            outputBefore = inputLine.getNextSibling();
+            outputContainer.removeChild(inputLine);
+            String styleValue = null;
+            do {
+                String s = currentStyles.get(keptStyles);
+                styleValue = styleValue == null ? s : styleValue + ';' + s;
+            } while (++keptStyles < currentStylesLength);
+            Element spanNode = createSpanNode();
+            spanNode.setAttribute("style", styleValue);
+            outputContainer.insertBefore(spanNode, outputBefore);
+            outputContainer = spanNode;
+            outputBefore = null;
+            spanNode.appendChild(inputLine);
+            outputBefore = inputLine;
+            setFocus();
+        }
+    }
+
+    public void setFocus() {
+        ((JSObject) inputLine).call("focus");
+    }
+
+    /** Move inputLine outside current (style) span. */
+    protected void popStyle() {
+        Node following = inputLine.getNextSibling();
+        Element span1 = (Element) inputLine.getParentNode();
+        Node parent = span1.getParentNode();
+        span1.removeChild(inputLine);
+        outputContainer = parent;
+        parent.insertBefore(inputLine, span1.getNextSibling());
+        outputBefore = inputLine;
+        if (following != null) {
+            Element span2 = createSpanNode();
+            String classAttr = span1.getAttribute("class");
+            String styleAttr = span1.getAttribute("style");
+            if (classAttr != null && classAttr.length() > 0)
+                span2.setAttribute("class", classAttr);
+            if (styleAttr != null && styleAttr.length() > 0)
+                span2.setAttribute("style", styleAttr);
+            parent.insertBefore(span2, inputLine.getNextSibling());
+            do {
+                Node ch = following;
+                following = ch.getNextSibling();
+                span1.removeChild(ch);
+                span2.appendChild(ch);
+            } while (following != null);
+        }
+        setFocus();
+    }
+
+    public void insertLinesIgnoreScroll(int count) {
+        StringBuilder builder = new StringBuilder(count);
+        while (--count >= 0)
+            builder.append('\n');
+        Text text = documentNode.createTextNode(builder.toString());
+        if (outputBefore == inputLine && inputLine != null)
+            outputContainer.insertBefore(text, outputBefore.getNextSibling());
+        else {
+            insertNode(text);
+            outputBefore = text;
+        }
+    }
+
+    public void deleteLinesIgnoreScroll(int count) {
+        for (int i = count; --i >= 0; ) {
+            eraseCharactersRight(-1, true);
+            Node current = outputBefore;
+            if (current==inputLine)
+                current=current.getNextSibling();
+            if (current instanceof Text) {
+                Text tnode = (Text) current;
+                String text = tnode.getTextContent();
+                int length = text.length();
+                if (length == 0 || text.charAt(0) != '\n') // Invalid usage
+                    break;
+                tnode.deleteData(0, 1);
+            }
+            else if (isBreakNode(current)) {
+                current.getParentNode().removeChild(current);
+                current=current.getNextSibling();
+            }
+            else {
+                // Invalid usage.
+                break;
+            }
+        }
+    }
+
+    public void insertLines(int count) {
+        int line = getCursorLine();
+        moveTo(getScrollBottom()-count, 0);
+        deleteLinesIgnoreScroll(count);
+        moveTo(line, 0);
+        insertLinesIgnoreScroll(count);
+    }
+
+    public void deleteLines(int count) {
+        deleteLinesIgnoreScroll(count);
+        int line = getCursorLine();
+        cursorLineStart(getScrollBottom() - line - count);
+        insertLinesIgnoreScroll(count);
+        moveTo(line, 0);
+    }
+
+    public void scrollForward(int count) {
+        int line = getCursorLine();
+        moveTo(getScrollTop(), 0);
+        deleteLinesIgnoreScroll(count);
+        int scrollRegionSize = getScrollBottom() - getScrollTop();
+        cursorLineStart(scrollRegionSize-count);
+        insertLinesIgnoreScroll(count);
+        moveTo(line, 0);
+    }
+
+    public void scrollReverse(int count) {
+        int line = getCursorLine();
+        moveTo(getScrollBottom()-count, 0);
+        deleteLinesIgnoreScroll(count);
+        moveTo(getScrollTop(), 0);
+        insertLinesIgnoreScroll(count);
+        moveTo(line, 0);
+    }
+
+    public void eraseLineLeft() {
+        int column = getCursorColumn();
+        cursorLineStart(0);
+        eraseCharactersRight(column, false);
+        cursorRight(column);
+    }
+
+    /** Erase from the current position until stopNode.
+     * If currently inside stopNode, erase to end of stopNode;
+     * otherwise erase until start of stopNode.
+     */
+    void eraseUntil(Node stopNode) {
+        Node current = outputBefore;
+        Node parent = outputContainer;
+        if (current==inputLine && current != null)
+            current=current.getNextSibling();
+        for (;;) {
+            if (current == stopNode)
+                return;
+            if (current == null) {
+                current = parent;
+                parent = current.getParentNode();
+            } else {
+                Node next = current.getNextSibling();
+                parent.removeChild(current);
+                current = next;
+            }
+        }
+    }
+
+    /** Erase or delete characters in current line.
+     * @param count number of characters to erase or -1 to end of line
+     * @param doDelete true if delete, false if erase
+     */
+    public void eraseCharactersRight(int count, boolean doDelete) {
+        if (count < 0)
+            count = Integer.MAX_VALUE;
+        // Note that the traversal logic is similar to move.
+        Node current = outputBefore;
+        Node parent = outputContainer;
+        if (current==inputLine && current != null)
+            current=current.getNextSibling();
+        int curColumn = -1;
+        int seen = 0; // Number of columns scanned so far.
+        for (;;) {
+            if (isBreakNode(current) || seen >= count) {
+                break;
+            }
+            else if (current instanceof Text) {
+                Text tnode = (Text) current;
+                String text = tnode.getTextContent();
+                int length = text.length();
+
+                int i = 0;
+                for (; i < length; i++) {
+                    if (seen >= count)
+                        break;
+                    char ch = text.charAt(i);
+                    // Optimization - don't need to calculate getCurrentColumn.
+                    if (ch >= ' ' && ch < 127) {
+                        seen++;
+                    }
+                    else if (ch == '\r' || ch == '\n' || ch == '\f') {
+                        count = seen;
+                        break;
+                    }
+                    else {
+                        if (curColumn < 0)
+                            curColumn = getCursorColumn();
+                        int col = updateColumn(ch, curColumn+seen);
+                        seen = col - curColumn;
+                        // general case using updateColumn FIXME
+                    }
+                }
+
+                if (i >= length && doDelete) {
+                    Node next = current.getNextSibling();
+                    parent.removeChild(current);
+                    current = next;
+                    //break;
+                }
+                else {
+                    if (doDelete)
+                        tnode.deleteData(0, i);
+                    else {
+                        tnode.replaceData(0, i, makeSpaces(i));
+                    }
+                }
+                continue;
+            } else if (current instanceof Element) {
+                if (isObjectElement((Element) current)) {
+                    Node next = current.getNextSibling();
+                    parent.removeChild(current);
+                    current = next;
+                    count--;
+                    continue;
+                }
+            }
+
+            Node ch;
+            if (current != null) {
+                // If there is a child, go to the first child next.
+                ch = current.getFirstChild();
+                if (ch != null) {
+                    parent = current;
+                    current = ch;
+                    continue;
+                }
+                // Otherwise, go to the next sibling.
+                ch = current.getNextSibling();
+                if (ch != null) {
+                    current = ch;
+                    continue;
+                }
+
+                // Otherwise go to the parent's sibling - but this gets complicated.
+                if (isBlockNode(current))
+                    break;
+            }
+
+            //ch = current;
+            for (;;) {
+                if (parent == bodyNode) {
+                    return;
+                }
+                Node sib = parent.getNextSibling();
+                Node pparent = parent.getParentNode();
+                if (isSpanNode(parent) && parent.getFirstChild() == null)
+                    pparent.removeChild(parent);
+                parent = pparent;
+                if (sib != null) {
+                    current = sib;
+                    break;
+                }
+            }
+        }
+    }
+
+    public void eraseLineRight() {
+        eraseCharactersRight(-1, true);
+    }
+
+    /** Move cursor to beginning of line, relative.
+     * @param deltaLines line number to move to, relative to current line.
+     */
+    public void cursorLineStart(int deltaLines) {
+        if (deltaLines > 0) // Optimization
+            moveTo(outputBefore, deltaLines, 0, true);
+        else
+            moveTo(getCursorLine()+deltaLines, 0);
+    }
+
+    public void cursorDown(int deltaLines) {
+        moveTo(getCursorLine()+deltaLines, getCursorColumn());
+    }
+
+    public void cursorRight(int count) {
+        if (false) {
+            moveTo(inputLine, 0, count, true);
+        } else {
+            // FIXME optimize same way cursorLeft is.
+            //long lcol = delta2D(cursorHome, outputBefore);
+            //inline = (int) (lcol >> 32);
+            //int col = (int) (lcol >> 1) & 0x7fffffff;
+            moveTo(getCursorLine(), getCursorColumn()+count);
+        }
+    }
+
+    public void cursorLeft(int count) {
+        if (count == 0)
+            return;
+        org.w3c.dom.Node prev = outputBefore.getPreviousSibling();
+        // Optimize common case
+        if (prev instanceof org.w3c.dom.Text) {
+            org.w3c.dom.Text ptext = (org.w3c.dom.Text) prev;
+            int len = ptext.getLength();
+            String tstr = ptext.getTextContent();
+            int tcols = 0;
+            int tcount = 0;
+            for (;;) {
+                if (tcols == count)
+                    break;
+                if (tcount == len) {
+                    tcount = -1;
+                    break;
+                }
+                tcount++;
+                char ch = tstr.charAt(len-tcount);
+                int chcols = charColumns(ch);
+                if (ch == '\n' || ch == '\r' || ch == '\f' || ch == 't'
+                    || chcols < 0 || tcols+chcols > count) {
+                    tcount = -1;
+                    break;
+                }
+                tcols += chcols;
+            }
+            if (tcount > 0) {
+                String after = tstr.substring(len-tcount);
+                ptext.deleteData(len-tcount, tcount);
+                count -= tcols;
+                org.w3c.dom.Node following = outputBefore.getNextSibling();
+                if (following instanceof org.w3c.dom.Text) {
+                    org.w3c.dom.Text rtext = (org.w3c.dom.Text) following;
+                    rtext.replaceData(0, 0, after);
+                } else {
+                    org.w3c.dom.Text nafter = documentNode.createTextNode(after);
+                    outputContainer.insertBefore(nafter, following);
+                }
+                if (currentCursorColumn > 0)
+                    currentCursorColumn -= tcols;
+            }
+        }
+        if (count > 0) {
+            moveTo(getCursorLine(), getCursorColumn()-count);
+        }
+    }
+
+    /** Return column number following a tab at initial {@code col}.
+     * Both {@code col} and result are 0-origin.
+     * Default implementation assumes tabs every 8 columns.
+     */
+    protected int nextTabCol(int col) {
+        return (col & ~7) + 8;
+    }
+
+    public Text createText(String data) {
+        return documentNode.createTextNode(data);
+    }
+    
+    public Element createElement(String tag) {
+        return USE_XHTML ? documentNode.createElementNS(htmlNamespace, tag)
+            : documentNode.createElement(tag);
+    }
+
+    protected Element createSpanNode() {
+        return createElement("span");
+    }
+
+    protected void insertString(String str, char kind) {
+        //WTDebug.println("insertString \""+WTDebug.toQuoted(str)+"\" len:"+str.length()+" in-is-out:"+(inputLine==outputBefore)+" DOM["+getHTMLText()+"]");
+        int prevEnd = 0;
+        int curColumn = getCursorColumn();
+        int slen = str.length();
+        int i = 0;
+        for (; i < slen;  i++) {
+            char ch = str.charAt(i);
+            switch (controlSequenceState) {
+            case SEEN_ESC_STATE:
+                switch (ch) {
+                case '[':
+                    controlSequenceState = SEEN_ESC_LBRACKET_STATE;
+                    curNumParameter = -1;
+                    prevParametersCount = 0;
+                    continue;
+                case ']':
+                    controlSequenceState = SEEN_ESC_RBRACKET_STATE;
+                    curNumParameter = -1;
+                    prevParametersCount = 0;
+                    continue;
+                case '7': // DECSC
+                    saveCursor();
+                    break;
+                case '8': // DECRC
+                    restoreCursor();
+                    break;
+                case 'M': // Reverse index
+                    insertLines(1);
+                    break;
+                }
+                controlSequenceState = INITIAL_STATE;
+                prevEnd = i + 1;
+                curColumn = getCursorColumn();
+                break;
+            case SEEN_ESC_LBRACKET_STATE:
+            case SEEN_ESC_LBRACKET_QUESTION_STATE:
+                if (ch >= '0' && ch <= '9') {
+                    curNumParameter = curNumParameter >= 0 ? 10 * curNumParameter : 0;
+                    curNumParameter += (ch - '0');
+                }
+                else if (ch == ';') {
+                    if (prevNumParameters == null)
+                        prevNumParameters = new int[4];
+                    else if (prevNumParameters.length <= prevParametersCount) {
+                        prevNumParameters = java.util.Arrays.copyOf(prevNumParameters, 2*prevParametersCount);
+                    }
+                    prevNumParameters[prevParametersCount] = curNumParameter;
+                    curNumParameter = -1;
+                    prevParametersCount++;
+                }
+                else if (ch == '?')
+                    controlSequenceState = SEEN_ESC_LBRACKET_QUESTION_STATE;
+                else {
+                    handleControlSequence(ch);
+                    prevNumParameters = null;
+                    prevEnd = i + 1;
+                    curColumn = getCursorColumn();
+                    controlSequenceState = INITIAL_STATE;
+                }
+                continue;
+
+            case SEEN_ESC_RBRACKET_STATE:
+                if (ch >= '0' && ch <= '9') {
+                    curNumParameter = curNumParameter >= 0 ? 10 * curNumParameter : 0;
+                    curNumParameter += (ch - '0');
+                }
+                else if (ch == ';') {
+                    controlSequenceState = SEEN_ESC_BRACKET_TEXT_STATE;
+                    curTextParameter = new StringBuilder();
+                }
+                else {
+                    prevNumParameters = null;
+                    prevEnd = i + 1;
+                    curColumn = getCursorColumn();
+                    controlSequenceState = INITIAL_STATE;
+                }
+                continue;
+
+            case SEEN_ESC_BRACKET_TEXT_STATE:
+                if (ch == '\007' || ch == '\000') {
+                    handleOperatingSystemControl(curNumParameter, curTextParameter.toString());
+                    curTextParameter = null;
+                    curColumn = getCursorColumn();
+                    controlSequenceState = INITIAL_STATE;
+                    prevNumParameters = null;
+                    prevEnd = i + 1;
+                } else {
+                    curTextParameter.append(ch);
+                }
+                continue;
+            case INITIAL_STATE:
+                switch (ch) {
+                case '\r':
+                    insertSimpleOutput(str, prevEnd, i, kind, curColumn);
+                    //currentCursorColumn = column;
+                    if (i+1 < slen && str.charAt(i+1) == '\n'
+                        && getCursorLine() != scrollRegionBottom-1) {
+                        cursorLineStart(1);
+                        i++;
+                    } else {
+                        cursorLineStart(0);
+                    }
+                    prevEnd = i + 1;
+                    curColumn = 0;
+                    break;
+                case '\n':
+                    insertSimpleOutput(str, prevEnd, i, kind, curColumn);
+                    if (outputLFasCRLF())
+                        cursorLineStart(1);
+                    // Only scroll if scrollRegionBottom explicitly set to a value >= 0.
+                    else if (getCursorLine() == scrollRegionBottom-1)
+                        scrollForward(1);
+                    else
+                        cursorDown(1);
+                    prevEnd = i + 1;
+                    curColumn = currentCursorColumn;
+                    break;
+                case '\b':
+                    insertSimpleOutput(str, prevEnd, i, kind, curColumn); 
+                    cursorLeft(1);
+                    //WTDebug.println("BACKSPACE after DOM["+getHTMLText()+"]");
+                    prevEnd = i + 1; 
+                    curColumn = currentCursorColumn;
+                    break;
+                case '\007': // Bell
+                    insertSimpleOutput(str, prevEnd, i, kind, curColumn); 
+                    //currentCursorColumn = column;
+                    handleBell();
+                    prevEnd = i + 1;
+                    break;
+                case '\033':
+                    insertSimpleOutput(str, prevEnd, i, kind, curColumn);
+                    //currentCursorColumn = column;
+                    prevEnd = i + 1;
+                    controlSequenceState = SEEN_ESC_STATE;
+                    continue;
+                case '\t':
+                    insertSimpleOutput(str, prevEnd, i, kind, curColumn);
+                    int nextStop = nextTabCol(getCursorColumn());
+                    //WTDebug.println("TAB cur:"+currentCursorColumn+" tab-to:"+nextStop+" move:"+(nextStop-currentCursorColumn));
+                    cursorRight(nextStop-currentCursorColumn);
+                    curColumn = currentCursorColumn;
+                    prevEnd = i + 1;
+                    break;
+                default:
+                    int nextColumn = updateColumn(ch, curColumn);
+                    if (nextColumn > wrapWidth) {
+                        if (wrapOnLongLines) {
+                            insertSimpleOutput(str, prevEnd, i, kind, curColumn);
+                            //currentCursorColumn = column;
+                            //insertWrapBreak();
+                            cursorLineStart(1);
+                            prevEnd = i;
+                        }
+                        //line++;
+                        nextColumn = updateColumn(ch, 0);
+                    }
+                    curColumn = nextColumn;
+                }
+            }
+        }
+        if (controlSequenceState == INITIAL_STATE) {
+            insertSimpleOutput(str, prevEnd, i, kind, curColumn);
+            //currentCursorColumn = column;
+        }
+        //long lcol = delta2D(cursorHome, outputBefore);
+    }
+
+    protected void insertSimpleOutput (String str, int beginIndex, int endIndex, char kind, int endColumn) {
+        int sslen = endIndex - beginIndex;
+        if (sslen == 0)
+            return;
+
+        if (adjustStyleNeeded)
+            adjustStyle();
+        int slen = str.length();
+        if (beginIndex > 0 || endIndex != slen)
+            str = str.substring(beginIndex, endIndex);
+        //WTDebug.println("[insertSimple \""+WTDebug.toQuoted(str)+"\" kind:"+kind+" DOM["+getHTMLText()+"] outBef:"+WTDebug.pnode(outputBefore)+" endCol:"+endColumn+" cur:"+getCursorColumn()+" ins:"+inInsertMode());
+        int column = getCursorColumn();
+        int widthInColums = endColumn-column;
+        if (! inInsertMode()) {
+            eraseCharactersRight(widthInColums, true);
+        } else if (wrapOnLongLines) {
+            moveTo(cursorHome, getCursorLine(), wrapWidth-widthInColums, false);
+            eraseCharactersRight(-1, true);
+            moveTo(getCursorLine(), column);
+        }
+        if (kind == 'E') {
+            Element errElement = createSpanNode();
+            errElement.setAttribute("std", "error");
+            //errElement.setAttribute("style", "font-weight: bold; color: green; background: blue");
+            //resetCursorCache(); // FIXME - should avoid
+            insertNode(errElement);
+            errElement.appendChild(documentNode.createTextNode(str));
+            outputBefore = errElement.getNextSibling();
+        }
+        else {
+            org.w3c.dom.Node previous = outputBefore != null ? outputBefore.getPreviousSibling()
+                : outputContainer.getLastChild();
+            if (previous instanceof Text)
+                ((Text) previous).appendData(str);
+            else {
+                Text text = documentNode.createTextNode(str);
+                insertNode(text);
+            }
+        }
+        currentCursorColumn = endColumn;
+    }
+
+    /** Insert a node at (before) current position.
+     * Caller needs to update cursor cache or call resetCursorCache. */
+    public void insertNode (org.w3c.dom.Node node) {
+        outputContainer.insertBefore(node, outputBefore);
+    }
+
+    /** Insert element at current position, and move to start of element. */
+    public void pushIntoElement(Element element) {
+        resetCursorCache(); // FIXME - not needed if element is span, say.
+        insertNode(element);
+        outputContainer = element;
+        outputBefore = null;
+    }
+
+    /** Move position to follow current container. */
+    public void popFromElement() {
+        Node element = outputContainer;
+        outputContainer = element.getParentNode();
+        outputBefore = element.getNextSibling();
+    }
+
+    public void insertPrompt (final String str) {
+        Platform.runLater(new Runnable() {
+                public void run() {
+                    // <span std="prompt">
+                    Element promptElement = createSpanNode();
+                    promptElement.setAttribute("std", "prompt");
+                    resetCursorCache(); // FIXME - should avoid
+                    insertNode(promptElement);
+                    boolean moveInputLine = false; //inputLine == outputBefore;
+                    org.w3c.dom.Node savedParent = outputContainer;
+                    Node savedBefore = outputBefore;
+                    if (moveInputLine) { // FIXME - useless code?
+                        outputContainer.removeChild(inputLine);
+                        outputContainer = promptElement;
+                        promptElement.appendChild(inputLine);
+                        outputBefore = inputLine;
+                    } else {
+                        outputContainer = promptElement;
+                        outputBefore = null;
+                    }
+                    insertString(str, '\0');
+                    // </span>
+                    if (moveInputLine) { // FIXME - useless code?
+                        outputContainer.removeChild(inputLine);
+                        savedParent.insertBefore(inputLine, promptElement.getNextSibling());
+                        setFocus();
+                    }
+                    else
+                        outputBefore = savedBefore;
+                    outputContainer = savedParent;
+                }
+            });
+    }
+
+    private void appendText(Node parent, String data) {
+        if (data.length() == 0)
+            return;
+        Node last = parent.getLastChild();
+        if (last instanceof Text)
+            ((Text) last).appendData(data);
+        else
+            parent.appendChild(documentNode.createTextNode(data));
+    }
+
+    /** Insert a {@code <br>} node. */
+    protected void insertBreak () {
+        org.w3c.dom.Node breakNode = createElement("br");
+        insertNode(breakNode);
+        currentCursorColumn = 0;
+        if (currentCursorLine >= 0)
+            currentCursorLine++;
+    }
+
+    /** Insert a line break because of wrapping an over-long line. */
+    protected void insertWrapBreak() {
+        insertBreak();
+    }
+
+    public void handleEvent(org.w3c.dom.events.Event event) {
+        //WTDebug.println("handle1Event "+event+" type:"+event.getType()+" INPUT:"+inputAsString());
+    }
+
+    public void handle(javafx.event.Event ke) {
+        if (ke instanceof javafx.event.ActionEvent)
+            handle((javafx.event.ActionEvent) ke);
+        if (ke instanceof javafx.scene.input.KeyEvent)
+            handle((javafx.scene.input.KeyEvent) ke);
+    }
+
+    public void handle(javafx.event.ActionEvent ke) {
+        //WTDebug.println("handle2 action "+ke+" INPUT:"+inputAsString());
+    }
+    
+    public boolean isApplicationMode() { return true; }
+
+    private void processArrowKey(char ch) {
+        processInputCharacters((isApplicationMode() ? "\033O" : "\033[")+ch);
+    }
+
+    public void handle(javafx.scene.input.KeyEvent ke) {
+        KeyCode code = ke.getCode();
+        if (!isLineEditing()) {
+            switch (code) {
+                //redundant case ENTER: processInputCharacters("\r");  break;
+            case UP: processArrowKey('A');  break;
+            case DOWN: processArrowKey('B');  break;
+            case RIGHT: processArrowKey('C');  break;
+            case LEFT: processArrowKey('D');  break;
+            case HOME: processInputCharacters("\033[1~"); break;
+            case END: processInputCharacters("\033[4~"); break;
+                //case DELETE: processInputCharacters("\033[3~"); break;
+            case INSERT: processInputCharacters("\033[2~"); break;
+            case PAGE_UP: processInputCharacters("\033[5~"); break;
+            case PAGE_DOWN: processInputCharacters("\033[6~"); break;
+            default:
+                String chars = ke.getCharacter();
+                if (chars != KeyEvent.CHAR_UNDEFINED && chars.length() > 0)
+                    processInputCharacters(chars);
+            }
+            ke.consume();
+        } else if (ke.getEventType() == KeyEvent.KEY_TYPED
+                   && "\r".equals(ke.getCharacter())) {
+            enter(ke);
+            ke.consume();
+        }
+    }
+
+    public void processInputCharacters(String text) {
+    }
+
+    /*
+    public boolean isDivNode(Node node) {
+        if (! (node instanceof Element)) return false;
+        String tag = ((Element) node).getTagName();
+        return "div".equals(tag);
+    }
+    */
+
+    /** True if an img/object/a element.
+     * These are treated as black boxes similar to a single
+     * 1-column character. */
+    public boolean isObjectElement(Element node) {
+        String tag = node.getTagName();
+        return "a".equals(tag) || "object".equals(tag) || "img".equals(tag);
+    }
+
+    public boolean isBlockNode(Node node) {
+        if (! (node instanceof Element)) return false;
+        String tag = ((Element) node).getTagName();
+        return "p".equals(tag) || "div".equals(tag) || "pre".equals(tag);
+    }
+
+    public boolean isBreakNode(Node node) {
+        if (! (node instanceof Element)) return false;
+        String tag = ((Element) node).getTagName();
+        return "br".equals(tag);
+    }
+
+    public boolean isSpanNode(Node node) {
+        if (! (node instanceof Element)) return false;
+        String tag = ((Element) node).getTagName();
+        return "span".equals(tag);
+    }
+
+    /** Move forwards relative to cursorHome. */
+    public void moveTo(int goalLine, int goalColumn) {
+        moveTo(cursorHome, goalLine, goalColumn, true);
+    }
+
+    /** Move forwards relative to startNode.
+     * Currently, assumes startNode==cursorHome; that may change.
+     */
+    public void moveTo(Node startNode, int goalLine, int goalColumn, boolean addSpaceAsNeeded) {
+        //WTDebug.println("move start:"+WTDebug.pnode(startNode)+" gl:"+goalLine+" gc:"+goalColumn+" inputL:"+inputLine);
+        //WTDebug.println("move DOM["+getHTMLText()+"]");
+        adjustStyleNeeded = true;
+        int line = 0, column = 0;
+        Node current;
+        Node parent;
+
+        if (startNode == cursorHome) {
+            if (currentCursorLine >= 0 && currentCursorColumn >= 0
+                && goalLine >= currentCursorLine
+                && (goalLine > currentCursorLine
+                    || goalColumn >= currentCursorColumn)) {
+                current = outputBefore;
+                parent = outputContainer;
+                line = currentCursorLine;
+                column = currentCursorColumn;
+            }
+            else {
+                parent = cursorHome;
+                current = cursorHome.getFirstChild();
+            }
+        } else {
+            current = startNode;
+            parent = current == null ? outputContainer : current.getParentNode();
+        }
+        // Temporarily remove inputLine from tree.
+        if (inputLine != null) {
+            Node inputParent = inputLine.getParentNode();
+            if (inputParent != null) {
+                if (outputBefore==inputLine)
+                    outputBefore = outputBefore.getNextSibling();
+                if (current==inputLine)
+                    current = current.getNextSibling();
+               inputParent.removeChild(inputLine);
+               // Removing input line may leave 2 Text nodes adjacent.
+               // These are merged below.
+            }
+        }
+
+        //if (parent==null||(current!=null&&parent!=current.getParentNode()))
+        //throw new Error("BAD PARENT "+WTDebug.pnode(parent)+" OF "+WTDebug.pnode(current));
+        mainLoop:
+        while (line < goalLine || column < goalColumn) {
+            //WTDebug.println("-move cur:"+WTDebug.pnode(current)+(current==null?"":(" .par:"+WTDebug.pnode(current.getParentNode())))+" parent:"+WTDebug.pnode(parent)+" l:"+line+" col:"+column+" DOM["+getHTMLText()+"]");
+            if (parent==null||(current!=null&&parent!=current.getParentNode()))
+                throw new Error("BAD PARENT "+WTDebug.pnode(parent)+" OF "+WTDebug.pnode(current));
+            if (isBreakNode(current)) {
+                if (line == goalLine) {
+                    if (addSpaceAsNeeded) {
+                        Node previous = current.getPreviousSibling();
+                        String str = makeSpaces(goalColumn-column);
+                        if (previous instanceof Text)
+                            ((Text) previous).appendData(str);
+                        else
+                            parent.insertBefore(createText(str), current);
+                        column = goalColumn;
+                    }
+                    else
+                        goalColumn = column;
+                    break;
+                } else {
+                    line++;
+                    column = 0;
+                }
+            }
+            else if (current instanceof Text) {
+                Text tnode = (Text) current;
+                int tstart = 0;
+                Node before;
+                while ((before = tnode.getPreviousSibling()) instanceof Text) {
+                    // merge nodes
+                    // (adjacent text nodes may happen after removing inputLine)
+                    String beforeData = ((Text) before).getData();
+                    tstart += beforeData.length();
+                    tnode.insertData(0, beforeData);
+                    parent.removeChild(before);
+                }
+                String text = tnode.getTextContent();
+                int tlen = text.length();
+                for (int i = tstart; i < tlen;  i++) {
+                    if (line >= goalLine && column >= goalColumn) {
+                        tnode.splitText(i);
+                        break;
+                    }
+                    char ch = text.charAt(i);
+                    int nextColumn = updateColumn(ch, column);
+                    if (nextColumn > columnWidth) {
+                        line++;
+                        column = updateColumn(ch, 0);
+                    }
+                    else if (nextColumn == -1) {
+                        if (line == goalLine) {
+                            int nspaces = goalColumn-column;
+                            if (addSpaceAsNeeded) {
+                                String spaces = makeSpaces(nspaces);
+                                tnode.insertData(i, spaces);
+                                tlen += nspaces;
+                                i += nspaces;
+                            }
+                            column = goalColumn;
+                            i--;
+                        } else {
+                            line++;
+                            column = 0;
+                            if (ch == '\r' && i+1<tlen && text.charAt(i+1) == '\n')
+                                i++;
+                        }
+                    }
+                    else
+                        column = nextColumn;
+                }
+            }
+
+            if (parent==null||(current!=null&&parent!=current.getParentNode()))
+                throw new Error("BAD PARENT "+WTDebug.pnode(parent)+" OF "+WTDebug.pnode(current));
+            // If there is a child, go the the first child next.
+            Node ch;
+            if (current != null) {
+                if (current instanceof Element
+                    && isObjectElement((Element) current))
+                    column += 1;
+                else {
+                    ch = current.getFirstChild();
+                    if (ch != null) {
+                        parent = current;
+                        current = ch;
+                        continue;
+                    }
+                }
+                // Otherwise, go to the next sibling.
+                ch = current.getNextSibling();
+                if (ch != null) {
+                    current = ch;
+                    if (parent==null||(current!=null&&parent!=current.getParentNode()))
+                        throw new Error("BAD PARENT "+WTDebug.pnode(parent)+" OF "+WTDebug.pnode(current));
+                    continue;
+                }
+
+                // Otherwise go to the parent's sibling - but this gets complicated.
+                if (isBlockNode(current))
+                    line++;
+            }
+
+            ch = current;
+            for (;;) {
+                if (parent == cursorHome || parent == bodyNode) {
+                    current = null;
+                    if (true) { 
+                        if (line < goalLine) {
+                            StringBuilder sb = new StringBuilder();
+                            while (line++ < goalLine)
+                                sb.append('\n');
+                            appendText(parent, sb.toString());
+                        }
+                    }
+                    else {
+                        while (line++ < goalLine) {
+                            parent.appendChild(createElement("br"));
+                        }
+                    }
+                    int fill = goalColumn - column;
+                    if (fill > 0) {
+                        appendText(parent, makeSpaces(fill));
+                    }
+                    line = goalLine;
+                    column = goalColumn;
+                    break mainLoop;
+                }
+                Node sib = parent.getNextSibling();
+                ch = parent; // ??
+                parent = parent.getParentNode();
+                //WTDebug.println("-at end sib:"+WTDebug.pnode(sib)+" pp:"+WTDebug.pnode(parent));
+                if (sib != null) {
+                    current = sib;
+                    //parent = ch;
+                    break;
+                }
+            }
+            continue;
+        }
+        if (parent==null||(current!=null&&parent!=current.getParentNode()))
+            throw new Error("BAD PARENT "+WTDebug.pnode(parent)+" OF "+WTDebug.pnode(current));
+        if (parent == bodyNode && isBlockNode(current)) {
+            parent = current;
+            current = parent.getFirstChild();
+        }
+        if (inputLine != null) {
+            parent.insertBefore(inputLine, current);
+            setFocus();
+        }
+        outputContainer = parent;
+        outputBefore = inputLine;
+        if (startNode == cursorHome) {
+            currentCursorLine = line;
+            currentCursorColumn = column;
+        }
+        else
+            resetCursorCache(); // ??? can we do better?
+    }
+
+    /** Returns number of columns needed for argument.
+     * Currently always returns 1.
+     * However, in the future we should handle zero-width characters
+     * as well as double-width characters, and composing charcters.
+     */
+    int charColumns(int ch) {
+        if (ch == 0x200B)
+            return 0;
+        return 1;
+    }
+
+    /** Calculate a "column state" after appending a given char.
+     * A non-negative column state is a number of columns.
+     * The value -1 as a return value indicates a newline character.
+     *
+     * In the future, a value less than -1 can be used to encode an
+     * initial part of a compound character, including a start surrogate.
+     * Compound character support is not implemented yet,
+     * nor is support for zero-width or double-width characters.
+     */
+    protected int updateColumn(char ch, int startState) {
+        if (ch == '\n' || ch == '\r' || ch == '\f')
+            return -1;
+        if (startState < 0) {
+            // TODO handle surrogates, compound characters, etc.
+        }
+        if (ch == '\t')
+            return nextTabCol(startState);
+        return startState+charColumns(ch);
+    }
+
+    /** Calculate (lines, columns) from startNode inclusive to stopNode (exclusive).
+     * @param startNode origin - the zero/start location
+     * @param stopNode the goal/end location
+     * @return {@code lines<<32|columns<<1|(stopSeen?1:0)}
+     */
+    public long delta2D(Node startNode, Node stopNode) {
+        //WTDebug.println("delta2D start:"+WTDebug.pnode(startNode)+" stop:"+WTDebug.pnode(stopNode));
+        return delta2D(startNode, 0, stopNode);
+    }
+    protected long delta2D(Node startNode, long startDelta, Node stopNode) {
+        //WTDebug.println("delta2Dr start:"+WTDebug.pnode(startNode)+" stD:"+(startDelta>>32)+"/"+((startDelta>>1)&0x7fffffff)+"?"+(startDelta&1)+" stop:"+WTDebug.pnode(stopNode));
+        long delta = startDelta;
+        if (startNode == stopNode)
+            return delta|1;
+        if (startNode instanceof Text) {
+            Text tnode = (Text) startNode;
+            String text = tnode.getTextContent();
+            int tlen = text.length();
+            int line = (int) (delta >> 32);
+            int col = ((int) delta) >> 1;
+            for (int i = 0; i < tlen;  i++) {
+                char ch = text.charAt(i);
+
+                col = updateColumn(ch, col);
+                if (col > columnWidth) {
+                    line++;
+                    col = updateColumn(ch, 0);
+                }
+                else if (col == -1) {
+                    line++;
+                    col = 0;
+                    if (ch == '\r' && i+1<tlen && text.charAt(i+1) == '\n')
+                        i++;
+                }
+            }
+            return ((long)line << 32)|((long) col << 1);
+        }
+        if (isBreakNode(startNode)) {
+            return ((delta >> 32) + 1) << 32;
+        }
+        if (startNode instanceof Element) {
+            if (isObjectElement((Element) startNode)) {
+                // FIXME
+            }
+            for (Node n = startNode.getFirstChild(); n != null;
+                 n = n.getNextSibling()) {
+                delta = delta2D(n, delta, stopNode);
+                if ((delta & 1) != 0)
+                    return delta;
+            }
+            if (isBlockNode(startNode))
+                delta = ((delta >> 32) + 1) << 32;
+        }
+        return delta;
+    }
+
+    public static String makeSpaces(int count) {
+        StringBuilder builder = new StringBuilder(count);
+        for (; count >= 8; count -= 8)
+            builder.append("        ");
+        while (--count >= 0)
+            builder.append(' ');
+        return builder.toString();
+    }
+
+  public static String toString(org.w3c.dom.NodeList ich)
+  {
+    if (ich.getLength() == 1)
+      {
+        org.w3c.dom.Node n = (org.w3c.dom.Node) ich.item(0);
+        if (n instanceof Text)
+          return '\"' + WTDebug.toQuoted(((Text) n).getData()) + '\"';
+        else
+          return n.toString();
+      }
+    else
+      return ""+ich.getLength()+"items";
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/WebWriter.java	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates.
+ * All rights reserved. Use is subject to license terms.
+ *
+ * This file is available and licensed under the following license:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the distribution.
+ *  - Neither the name of Oracle Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package webterminal;
+
+/** A Writer that inserts the written text into a WebTerminal.
+ */
+
+public class WebWriter extends java.io.Writer
+{
+    WebTerminal terminal;
+
+    StringBuilder sbuf = new StringBuilder();
+    char kind;
+
+    /** Which port is this?
+     * @return 'O': if output; 'E': if error stream; 'P': if prompt text
+     */
+    public char getKind() { return kind; }
+
+    public WebWriter (WebTerminal terminal, char kind) {
+        this.terminal = terminal;
+        this.kind = kind;
+    }
+
+    public synchronized void write (int x) {
+        sbuf.append((char) x);
+        //WebTerminal.origErr.println("after write1 "+WebTerminal.toQuoted(sbuf.toString()));
+        if (x == '\n')
+            flush();
+    }
+
+    public void write (String str) {
+        sbuf.append(str);
+        //WebTerminal.origErr.println("after writeS "+WebTerminal.toQuoted(sbuf.toString()));
+        flush();
+    }
+
+    public synchronized void write (char[] data, int off, int len) {
+        sbuf.append(data, off, len);
+        //WebTerminal.origErr.println("after writeN "+WebTerminal.toQuoted(sbuf.toString()));
+        flush();
+    }
+
+    public synchronized void flush() {
+        StringBuilder s = sbuf;
+        //WebTerminal.origErr.println("WebWr.flush "+WebTerminal.toQuoted(sbuf.toString()));
+
+        if (s.length() > 0) {
+            // FIXME optimize by passing sbuf to insertOutput?
+            terminal.insertOutput(s.toString(), kind);
+            s.setLength(0);
+        }
+    }
+
+    public void close () {
+        flush();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/repl.html	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,22 @@
+<html>
+<head>
+<title>WebTerminal</title>
+<style type="text/css">
+ body { font-family: monospace }
+ span[std="output"] { }
+ span[std="error"] { color: red; }
+ span[std="prompt"] { color: green; margin: 0px; padding: 0px; border: 1px }
+ span[std="input"] { font-weight: bolder; color: blue }
+ input[std="input"] { font-weight: bolder; }
+ input[std="input"] {
+        border: 0px;
+	margin: 0px;
+	padding: 0px;
+  right: 0px;
+  width: auto;
+  left: auto;
+}
+</style>
+</head>
+<body id="body" ><pre id="initial"></pre></body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/src/webterminal/repl.xml	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>WebTerminal</title>
+<style type="text/css">
+ span[std="output"] { }
+ span[std="error"] { color: red; }
+ span[std="prompt"] { color: purple; margin: 0px; padding: 0px; border: 1px }
+ span[std="input"] { font-weight: bolder; color: blue }
+ input[std="input"] { font-weight: bolder; }
+ input[std="input"] {
+        border: 0px;
+	margin: 0px;
+	padding: 0px;
+  right: 0px;
+  width: auto;
+  left: auto;
+}
+</style>
+</head>
+<body id="body"><pre id="initial"></pre></body>
+</html>
Binary file apps/experiments/WebTerminal/terminfo/j/jfxterm has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/terminfo/j/jfxterm.ti	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,72 @@
+jfxterm|JavaFX WebNode terminal emulator,
+	colors#8,
+	cols#80,
+	lines#24,
+	pairs#64,
+	am,
+	mir,
+	msgr,
+	xenl,
+#	bel=^G,
+	bold=\E[1m,
+	clear=\E[H\E[J,
+	cr=\r,
+	csr=\E[%i%p1%d;%p2%dr,
+	cub1=\b,
+	cub=\E[%p1%dD,
+	cud1=\n,
+	cud=\E[%p1%dB,
+	cuf1=\E[C,
+	cuf=\E[%p1%dC,
+	cup=\E[%i%p1%d;%p2%dH,
+	cuu1=\E[A,
+	cuu=\E[%p1%dA,
+	dch1=\E[P,
+	dch=\E[%p1%dP,
+	dl1=\E[M,
+	dl=\E[%p1%dM,
+	ed=\E[J,
+	el1=\E[1K,
+	el=\E[K,
+	home=\E[H,
+	ht=\t,
+	ich1=\E[@,
+	ich=\E[%p1%d@,
+	il1=\E[L,
+	il=\E[%p1%dL,
+	ind=\n,
+        indn=\E[%p1%dS,
+#	invis=\E[8m,
+#	kbs=^?,
+	kcub1=\EOD,
+	kcud1=\EOB,
+	kcuf1=\EOC,
+	kcuu1=\EOA,
+	kdch1=\E[3~,
+	kend=\E[4~,
+	khome=\E[1~,
+	kich1=\E[2~,
+	knp=\E[6~,
+	kpp=\E[5~,
+	op=\E[39;49m,
+	rc=\E8,
+	rev=\E[7m,
+	ri=\EM,
+        rin=\E[%p1%dT,
+	rmir=\E[4l,
+	rmso=\E[27m,
+	rmul=\E[24m,
+#	rs1=\Ec,
+	sc=\E7,
+	setab=\E[%p1%{40}%+%dm,
+	setaf=\E[%p1%{30}%+%dm,
+	sgr0=\E[m,
+	smir=\E[4h,
+	smul=\E[4m,
+ 	smso=\E[7m,
+# 	u6=\E[%i%d;%dR,
+# 	u7=\E[6n,
+	smcup=\E[?47h,
+	rmcup=\E[?47l,
+        vpa=\E[%i%p1%dd,
+#       rs2 may need to be added
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/terminfo/j/xjfxterm.ti	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,11 @@
+jfxterm|JavaFX WebNode terminal enulator,
+	cols#80,
+        lines#24,
+	cr=\r,
+        cub1=\b,
+        cub=\E[%p1%dD,
+#	cuf1=\E[C,
+#	cuf=\E[%p1%dC,
+	home=\E[H,
+        cup=\E[%i%p1%d;%p2%dH,
+        home=\E[H,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/util/hcat	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,3 @@
+echo -n "]72;"
+cat
+echo -n ""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/experiments/WebTerminal/util/myemacs	Mon Mar 17 09:33:56 2014 -0700
@@ -0,0 +1,7 @@
+# Convenience command to run emacs with working TERM and TERMINFO
+case "$0" in 
+  /* ) cmd="$0";;
+  *)   cmd=`pwd`/"$0";;
+esac
+dir=`dirname $cmd`
+TERMINFO=$dir/../terminfo TERM=jfxterm /usr/bin/emacs -nw "$@"