Scramjet for UNIX: Java acceleration for terminal apps
- UNIX command-line tools: Scramjet allows fast UNIX-style
command-line tools to be written in Java by avoiding the JVM startup
- UNIX terminal applications: Scramjet allows writing
efficient ncurses-style fullscreen Unicode ANSI text applications
(editors, mail agents, viewers) in Java, with 256-colour support.
- Eclipse hooks: Scramjet allows monolithic Java applications
such as Eclipse to be controlled from the UNIX command-line, running
commands on demand within the Eclipse JVM, with input/output via the
Download and License
Hosted on github at http://github.com/uazu/scramjet,
and released under the Apache License,
How it works
- On first invocation of Scramjet, a JVM is started for the user and
- Communication with the JVM is via private named pipes (FIFOs) in
the ~/.scramjet folder.
- The back-end is pure Java, and the front-end is pure C -- no JNI
- The front-end communicates over the FIFOs to start a given Tool
within the JVM and exchanges stdin/stdout/stderr/window-change data
over the FIFOs with the Java back end as the tool runs.
- One JVM can serve multiple simultaneous invocations of the same or
- The background JVM shuts itself down if it has been idle for 15
Advantages of Scramjet
Using Java and Scramjet for writing command-line tools and terminal
applications has some advantages and disadvantages compared to
starting a JVM each time or writing in C:
- Advantage: The cost of loading and JIT-compiling the classes is
paid only once -- after that the tool is 'hot' and starts
- Advantage: Java and its libraries become convenient for writing
small tools, longer than a script but too complex to write quickly in
- Advantage: Data may be kept in the JVM and shared between
different instances of a tool, e.g. caches, or shared editor
- Limitation: Java applications use UTF-16 natively rather than
UTF-8 or ISO-8859-x, putting them at a disadvantage for bulk text
processing compared to C applications written to work with these
- Limitation: Existing Java tools that make use of static variables
for per-invocation state may be more difficult to convert to Scramjet.
If all else fails, global locks may be a work-around, serialising
execution of the tool within the JVM.
- Limitation: Runaway threads in a JVM cannot be killed off. If a
Java tool has bugs, the only way to resolve the problem may be to
restart the JVM. (You can use the 'sj-threads -l' command to
view the live stacktraces of all the running threads.)
- Good Unicode handling. Standard input/output/error is converted
according to the UNIX locale (e.g. LANG environment
variable) as detected by Java on JVM startup.
- For full-screen applications, Unicode output is optimised for
UTF-8 and Latin1, otherwise it goes via Java's character encoders.
There is no handling of double-width characters yet, and it assumes a
1:1 mapping between Unicode code-points and displayed monospace
- 256-colour output is supported if that is detected from the
TERM environment variable and associated terminfo
- Raw byte output to standard output/error is possible via direct
Comparison with 'nailgun'
This tool was inspired by nailgun, and has some advantages
and disadvantages compared to that tool:
- Advantage: Scramjet is secure because the JVM runs as the user,
and all communication passes over local named pipes protected by 0600
- Advantage: Scramjet allows curses-style terminal apps to be
written because it has a module to pass through window-size
information and to enable raw input.
- Advantage: Scramjet has rich convenience classes to make it easy
to get started writing various types of apps or tools.
- Same: Scramjet borrows the code from nailgun which diverts
System.in/out/err and System.exit(rc) so that they
operate as expected within the Tool context.
- Limitation: Scramjet only supports UNIX, because it uses named
- Limitation: On a multi-user system, each user will have their own
Scramjet JVM running. This isn't shared, unlike the JVM in nailgun.
In addition, a nailgun server could be run on some other machine on
the network, even on another OS.
Using as an Eclipse plugin
Scramjet can be built as an Eclipse plugin. When installed in the
Eclipse drop-in folder, Eclipse will load it up and then Eclipse
effectively becomes a Scramjet server. Normal Scramjet command-line
tools run within the Eclipse JVM, with access to the Eclipse classes.
This opens up the possibility of writing command-line tools that query
or modify the Eclipse data structures, or that automate Eclipse
processes. It is even possible to write a curses-style front end to
navigate the Eclipse environment.
Writing full-screen terminal apps
Scramjet provides a curses-like library (although obviously with a
Java-oriented API) which supports ANSI terminals such as the Linux
console, screen and the various terminals for X, including
256-colour support. The bulk of the code is in Java. The only part
in C is the code that sets raw input mode, and that detects the
terminal size and catches window-resize signals. The interface can be
used directly for simple one-page applications, or via the TiledApp
interface for multi-paged tiled applications (like editors).
These pages and files, including applets and artwork,
are Copyright (c) 1997-2019 Jim Peters
unless otherwise stated. Please contact
me if you'd like to use anything not explicitly released, or if
you have something interesting to discuss.