Skip to content

Commit 211ea8a

Browse files
author
“Per
committed
Initial public check-in of JWebTerminal.
0 parents  commit 211ea8a

26 files changed

+5038
-0
lines changed

README

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# JWebTerminal - a web-based console
2+
3+
JWebTerminal implements a general-purpose interactive console:
4+
Users can type commands which get sent to a command handler,
5+
which evaluates the command, and displays the results, typically
6+
in some kind of type-script format.
7+
8+
There are two basic modes:
9+
- In line-editing mode each input line is an input field you
10+
edit locally (in the browser). The finished line is sent to the
11+
client when you type Enter.
12+
- In character mode each character is sent directly to the client,
13+
which is also responsible for input echoing.
14+
15+
Applications of JWebTerminal include:
16+
- A chat/talk window.
17+
- A read-eval-print-loop for an interactive scripting language.
18+
- A command console.
19+
- A terminal emulator.
20+
21+
WebTerminal recognizes a large subset of the standard ANSI/xterm
22+
terminal escape sequences for repositioning the cursor, erasing
23+
previous text, changing style, etc. Enough of a subset is recognized
24+
that you can run programs like the emacs text editor, with styling.
25+
This requires you specify the correct terminal type (TERM), which is
26+
done automatically by the PtyTerminal application. A matching
27+
terminfo entry is provided, but it also should work ok to specify TERM
28+
to a standard terminal name, like eterm-color, vte, gnome, konsole,
29+
and xterm (all with color), or vt100 or vt220 (both non-color).
30+
31+
The terminfo directory defines the escape sequences supported by the
32+
"jfxterm" terminal type, using a terminfo descriptor. The terminal emulation
33+
is a subset of the standard xterm/ansi/vt100 ones.
34+
35+
There is an escape sequence to send HTML to WebTerminal.
36+
This allows you to embed images, forms, and other HTML elements
37+
in the console output.
38+
39+
The primary class is webterminal.WebTerminal, which is
40+
an abstract (overridable) control you embed in your scenegraph.
41+
42+
## Sample Applications
43+
44+
#### RunInConsole
45+
46+
The utility class webterminal.RunInConsole make it easy to
47+
run an old-fashioned console-based Java application in a WebTerminal.
48+
It re-binds System.in, System.out, and System.err to the WebTerminal.
49+
50+
For example, the jrunscript tool is a wrapper around the class
51+
com.sun.tools.script.shell.Main in tools.jar. So to start up
52+
a JavaScript read-elal-print-tool, do:
53+
54+
$ ant run-main -Drunmain.classpath=$JAVA_HOME/lib/tools.jar \
55+
-Drunmain.class="com.sun.tools.script.shell.Main" \
56+
-Drunmain.args="-l javascript"
57+
58+
#### ShellConsole
59+
60+
The application webterminal.ShellConsole uses java.lang.Process
61+
to run a process inside a WebTerminal. Currently, it is hard-wired to
62+
run /bin/bash. (It does work under Cygwin if you edit the
63+
commandWithArgs field.)
64+
65+
#### PtyConsole
66+
67+
An application that implements a terminal emulator
68+
using WebTermnal and a PTY to fork off an operating system process.
69+
70+
The TERM and TERMINFO environment variables are set up automatically
71+
to use the "jfxterm" terminal type.
72+
73+
PtyConsole does depend on native code that assumes modern Unix-style
74+
pseudo-teletypes. At the time of writing it has only been tested on
75+
GNU/Linux Fedora 21; it may need some porting effort on older
76+
or non-Linux platforms, especially Windows.
77+

build.xml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- You may freely edit this file. See commented blocks below for -->
3+
<!-- some examples of how to customize the build. -->
4+
<!-- (If you delete it and reopen the project it will be recreated.) -->
5+
<!-- By default, only the Clean and Build commands use this build script. -->
6+
<!-- Commands such as Run, Debug, and Test only use this build script if -->
7+
<!-- the Compile on Save feature is turned off for the project. -->
8+
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
9+
<!-- in the project's Project Properties dialog box.-->
10+
<project name="WebTerminal" default="default" basedir=".">
11+
<description>Builds, tests, and runs the project WebTerminal.</description>
12+
<import file="nbproject/build-impl.xml"/>
13+
<property name="build.dir" value="build"/>
14+
<property name="dist.dir" value="dist"/>
15+
<property name="run.jvmargs" value="-Djava.library.path=${dist.dir}"/>
16+
17+
<!--
18+
19+
There exist several targets which are by default empty and which can be
20+
used for execution of your tasks. These targets are usually executed
21+
before and after some main targets. They are:
22+
23+
-pre-init: called before initialization of project properties
24+
-post-init: called after initialization of project properties
25+
-pre-compile: called before javac compilation
26+
-post-compile: called after javac compilation
27+
-pre-compile-single: called before javac compilation of single file
28+
-post-compile-single: called after javac compilation of single file
29+
-pre-compile-test: called before javac compilation of JUnit tests
30+
-post-compile-test: called after javac compilation of JUnit tests
31+
-pre-compile-test-single: called before javac compilation of single JUnit test
32+
-post-compile-test-single: called after javac compilation of single JUunit test
33+
-pre-jar: called before JAR building
34+
-post-jar: called after JAR building
35+
-post-clean: called after cleaning build products
36+
37+
(Targets beginning with '-' are not intended to be called on their own.)
38+
39+
Example of inserting an obfuscator after compilation could look like this:
40+
41+
<target name="-post-compile">
42+
<obfuscate>
43+
<fileset dir="${build.classes.dir}"/>
44+
</obfuscate>
45+
</target>
46+
47+
For list of available properties check the imported
48+
nbproject/build-impl.xml file.
49+
50+
51+
Another way to customize the build is by overriding existing main targets.
52+
The targets of interest are:
53+
54+
-init-macrodef-javac: defines macro for javac compilation
55+
-init-macrodef-junit: defines macro for junit execution
56+
-init-macrodef-debug: defines macro for class debugging
57+
-init-macrodef-java: defines macro for class execution
58+
-do-jar-with-manifest: JAR building (if you are using a manifest)
59+
-do-jar-without-manifest: JAR building (if you are not using a manifest)
60+
run: execution of project
61+
-javadoc-build: Javadoc generation
62+
test-report: JUnit report generation
63+
64+
An example of overriding the target for project execution could look like this:
65+
66+
<target name="run" depends="WebTerminal-impl.jar">
67+
<exec dir="bin" executable="launcher.exe">
68+
<arg file="${dist.jar}"/>
69+
</exec>
70+
</target>
71+
72+
Notice that the overridden target depends on the jar target and not only on
73+
the compile target as the regular run target does. Again, for a list of available
74+
properties which you can use, check the target you are overriding in the
75+
nbproject/build-impl.xml file.
76+
77+
-->
78+
79+
<target name="default" depends="test,jar,install-terminfo,javadoc"
80+
description="Build and test whole project."/>
81+
82+
<target name="all" depends="test,jar,native,install-terminfo,javadoc"
83+
description="Build and test whole project."/>
84+
85+
<property name="jheaders.dir" value="${build.dir}/include"/>
86+
87+
<target name="jheaders" depends="jar">
88+
<mkdir dir="${jheaders.dir}" />
89+
<javah destdir="${jheaders.dir}" classpath="build/classes" force="yes">
90+
<class name="ptyconsole.PTY"/>
91+
</javah>
92+
</target>
93+
94+
<target name="compile-native" unless="cross.platform" >
95+
<exec executable="make" failonerror="true" dir="native">
96+
<arg value="JDK_HOME=${JAVA_HOME}"/>
97+
<arg value="DIST_DIR=../${dist.dir}"/>
98+
<arg value="BUILD_DIR=../${build.dir}"/>
99+
<arg value="EXTRA_CFLAGS=${extra_cflags}"/>
100+
<arg value="EXTRA_LDFLAGS=${extra_ldflags}"/>
101+
<arg value="all"/>
102+
</exec>
103+
</target>
104+
105+
<target name="compile-native-cross" if="cross.platform" >
106+
<exec executable="make" failonerror="true" dir="native">
107+
<arg value="JDK_HOME=${platform.home}"/>
108+
<arg value="DIST_DIR=${native.cross.dist.dir}"/>
109+
<arg value="BUILD_DIR=${native.cross.build.dir}"/>
110+
<arg value="CC=${crosstools.gcc}"/>
111+
<arg value="EXTRA_CFLAGS=${crosstools.extra_cflags}"/>
112+
<arg value="EXTRA_LDFLAGS=${crosstools.extra_ldflags}"/>
113+
<arg value="LINK=${crosstools.gcc}"/>
114+
<arg value="all"/>
115+
</exec>
116+
</target>
117+
118+
<target name="native" depends="jheaders, compile-native, compile-native-cross"/>
119+
120+
<target name="install-terminfo">
121+
<copy file="terminfo/j/jfxterm" todir="${dist.dir}/j"/>
122+
</target>
123+
124+
<target depends="init,compile" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" description="Run a main class." name="run-main">
125+
<!-- Run an application (i.e. a class with a "main" method in a
126+
WebTerminal, redirecting System.in, System.out, and System.err.
127+
128+
Set -Drunmain.classpath=EXTRA_PATH to expand the classpath.
129+
-->
130+
<j2seproject1:java classname="webterminal.RunInConsole"
131+
classpath="${run.classpath}:${runmain.classpath}">
132+
<customize>
133+
<arg line="${runmain.class} ${runmain.args}"/>
134+
</customize>
135+
</j2seproject1:java>
136+
</target>
137+
138+
<target depends="init,compile" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" description="Run in a PTY." name="run-pty">
139+
<j2seproject1:java classname="ptyconsole.App"
140+
classpath="${run.classpath}:${runmain.classpath}">
141+
<customize>
142+
<arg line=""/>
143+
</customize>
144+
</j2seproject1:java>
145+
</target>
146+
147+
</project>

native/Makefile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
# Environment
3+
MKDIR=mkdir
4+
CP=cp
5+
CCADMIN=CCadmin
6+
SHELL=/bin/bash # NOTE: bash-ism present in this makefile
7+
8+
# NOTE: the following three variables are passed in from
9+
# the javafx-iio/build-*.xml files
10+
DIST_DIR = ../dist
11+
BUILD_DIR = ../build
12+
13+
BUILD_HEADERS = $(BUILD_DIR)/include
14+
15+
PTY_SRC = .
16+
17+
VPATH = $(PTY_SRC)
18+
19+
SYSTEM_UNAME := $(shell uname)
20+
IS_WINDOWS = false
21+
22+
23+
ifeq ($(SYSTEM_UNAME), Linux)
24+
fix_path = $2
25+
26+
OBJ_SUFFIX = o
27+
OUTPUT_FLAG = -o # trailing blank required
28+
PTY_LIB = $(DIST_DIR)/libpty.so
29+
30+
COMMON_PARAMS = -fno-strict-aliasing -fPIC -W -Wall -Wno-unused -Wno-parentheses -fno-omit-frame-pointer
31+
LINK = $(CC)
32+
LINK_PARAMS = $(COMMON_PARAMS) -shared -o $(PTY_LIB) $(EXTRA_LDFLAGS) -lX11
33+
CC_PARAMS = -O2 -ffast-math -Fd$(BUILD_DIR) $(COMMON_PARAMS) -I$(PTY_SRC) -I$(BUILD_HEADERS) -I$(JDK_HOME)/include -I$(JDK_HOME)/include/linux -c $(EXTRA_CFLAGS)
34+
endif
35+
36+
37+
INCLUDES = \
38+
-I$(JDK_HOME)/include \
39+
-I./build/jheaders \
40+
-I$(PTY_SRC)
41+
42+
43+
# The following should automatically include all .c files in the src/ folder.
44+
OBJS := $(patsubst $(PTY_SRC)/%.c,$(BUILD_DIR)/%.$(OBJ_SUFFIX),$(wildcard $(PTY_SRC)/*.c))
45+
# Can manually add more files here if needed.
46+
OBJS += \
47+
48+
all: .pre-build $(PTY_LIB)
49+
50+
$(PTY_LIB) : $(OBJS)
51+
$(LINK) $(LINK_PARAMS) $^ ;
52+
@if [ "$(MT)" != "" ]; then \
53+
$(MT) -nologo -manifest $@.manifest "-outputresource:$@;2" || \
54+
rm -f $(PTY_LIB); \
55+
fi;
56+
57+
$(BUILD_DIR)/%.$(OBJ_SUFFIX) : $(PTY_SRC)/%.c
58+
$(CC) $(CC_PARAMS) $(OUTPUT_FLAG)$@ $<
59+
60+
.pre-build:
61+
@mkdir -p $(BUILD_DIR) $(DIST_DIR)
62+
63+
# clean
64+
clean:
65+
rm -rf $(BUILD_DIR) $(DIST_DIR)
66+
67+
# clobber
68+
clobber:
69+
rm -rf $(BUILD_DIR) $(DIST_DIR)
70+

0 commit comments

Comments
 (0)