Running DomTerm Terminal Emulator on Windows Using WSL
Running DomTerm Terminal Emulator on Windows Using WSL
Based on web technologies, DomTerm gives developers a lot of great features not found in other emulators. Read on to find out the benefits.
Join the DZone community and get the full member experience.Join For Free
Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.
DomTerm is a terminal emulator (command console) that is based on web technologies. This enables a bunch of useful features not available on other terminal emulators. DomTerm has mostly been developed and used on Unix-like operating systems (I myself mostly use Fedora Linux), but, in this article, we will focus on Microsoft Windows.
DomTerm Feature Summary
- The standout feature is that you can embed images and general HTML. For example, interactive programs can "print" their results as images or graphics, as shown in screenshot-2. Help text can be rich HTML text, as shown in screenshot-1.
- This is combined with leading-class xterm compatibility, and modern features like wide character (CJK) support, 24-bit colors, and mouse event reporting.
- Styling with CSS. See the manual for examples, including a Solarized theme.
- Draggable tabs and panes (sub-windows). The top screenshot show two panes. You can mix terminal panes with ones for browsing web pages (useful for reading documentation).
- Client-server architecture. The UI client can be any modern browser (screenshot-2 uses Firefox), or a dedicated terminal application (screenshot-1 shows an Electron front-end). The server manages sessions (processes), communications, and preferences. You can detach and re-attach sessions, as in
screen. In screenshot-2
domterm listshows 3 active sessions.
- URLs in output become links. In a compiler error message File:line: becomes a link that opens an editor. Screenshot-2 shows a hover over the error message.
- Alt-click to move the cursor. (Alt is not needed if you put a certain escape sequence in your prompt.)
- Optional built-in line-editing with history.
- Built-in pager (like a simplified
less), as shown by the
domterm helpoutput in screenshot-1.
- Detailed documentation.
Windows Subsystem for Linux
In 2016 Microsoft released Windows Subsystem for Linux (WSL). This is an emulation layer that runs Linux executables, including the
bashshell and many non-GUI applications. Microsoft also makes available in their Store a subset of the Ubuntu Linux distribution, including the Ubuntu package manager apt-get. Later Microsoft added support for other Linux distributions, but this article will assume Ubuntu.
A Detour: Windows and Linux Files and Programs
From our point of view, there are two kinds of executables: Windows programs (which normally have the extension
.exe) and Linux programs. It is easy to call a Window program from a Linux program (and vice versa), and you can even pipe data between them.
A Windows program sees the regular Windows file system. A Linux program "sees" a traditional Unix-like file system, with
/tmp. Obviously, this Linux file system is implemented using Windows files, but Windows programs should never try to access files in the "Linux file system" (reading is ok but discouraged; if a Windows program tries to write a Unix file it can trash your Linux filesystem). On the other hand, Windows partitions (drives) are "mounted" in the Unix file system. For example, the
C:drive is mounted as
/mnt/c. It follows that any file that needs to be accessible to both Windows and Linux should be on a Windows partition. For example, DomTerm expects user preferences for user
WUSERto be in
/mnt/c/Users/WUSER/AppData/Roaming/DomTerm/settings.ini, which a Windows program can access as
c:\Users\WUSER\AppData\Roaming\DomTerm\settings.ini (note that your Unix user
$USER does not need to be the same as your Windows username
WUSER, though it can be).
There are detailed instructions for downloading and building DomTerm from source (git repository), including specific notes for WSL.
Running in the Browser
Let's first try running DomTerm in a web browser. Current versions of Firefox and Google Chrome are both supported (Microsoft Edge does not work for unknown reasons. Internet Explorer will probably never work).
To run DomTerm in the Firefox browser, invoke
domterm --firefox option; to use the Google Chrome browser use the
--chrome option. By default, DomTerm will look for these browsers in the default (Windows) location, but you can override the browser location. You can also use the
--browser option to select your default browser (as long as that is Firefox or Chrome).
Using the Electron Front-End
While running a shell in a browser is fine, it's not quite as nice as a dedicated terminal emulator application: there is browser-related clutter, minor annoyances because of the browser security model, and the menus aren't very appropriate. The Electron-based front-end is easy to install and recommended; see installation instructions.
To run DomTerm with the Electron front-end you can use the
--electronoption (Electron is the default if it is available).
Shell Prompts and Other Tricks
It is recommended that you put some DomTerm-specific escape sequences in your prompt template. For example, something like the following in your
if [ "$PS1" != "" ] then PS1="[\W]\!\\$ " if [ -n "$DOMTERM" ] then PS1='\[\e[19u\e[16u\]▼\[\e[17u\e[14u\]'$PS1'\[\e[15u\]' fi fi
This has the following nice benefits:
- Clicking the mouse moves the cursor (even if you don't press Alt).
- Delimit each command with its associated output as a group, and display a "button" (the triangle, which is the Unicode character 25bc "black down-pointing triangle"). Clicking on the triangle folds (hides) the command's output. The triangle is changed to right-pointing; clicking on it restores (unhides) the output.
- Create DOM elements with special attributes to mark prompt and input areas. This is used for styling, and to add structure (useful for analyzing saved HTML).
See here for more details and tricks. For example, directory tracking can turn compiler messages into links that when clicked opens a text editor at the specified file and position.
Opinions expressed by DZone contributors are their own.