Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running DomTerm Terminal Emulator on Windows Using WSL

DZone's Guide to

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.

· Web Dev Zone ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

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.

screenshot-1

DomTerm Feature Summary

There are other good JavaScript-based terminal emulators - xterm.js appears to be popular. Compared to these, DomTerm has a number of advantages. Here is a brief summary; see this article for more information with screenshots.

  • 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 intmux or GNU screen. In screenshot-2 domterm list shows 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 help output 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 /usr, /home, and/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, theC: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 userWUSERto 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).

Installing DomTerm

There are detailed instructions for downloading and building DomTerm from source (git repository), including specific notes for WSL.

Simpler (but less up-to-date) is to download a binary release; see detailed instructions.

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, invokedomterm --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).

Screenshot-2 below shows Firefox running a REPL for the Kawa language demonstrating "printing" of picture result values.

snapshot-2

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.bashrc:

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.

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:
web dev ,backend ,terminal emulator

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}