Take a look at DomTerm, a terminal emulator and multiplexer with HTML graphics and other rare features.

DomTerm is a modern terminal emulator that uses a browser engine as a “GUI toolkit.” This enables related features such as embeddable images and links, HTML rich text, and collapsible (show/hide) commands. Other than that, it looks and feels like a full-featured, stand-alone terminal emulator with excellent Xterm compatibility (including mouse handling and 24-bit colors) and proper “decorations” (menus). There is also built-in support for session management and side Windows (as in TMUx and GNU Screen), basic input editing (as in Readline), and paging (as in LESS).

Figure 1: DomTerminal terminal simulator.

We’ll take a look at these features in the following sections. We’ll assume you have DomTerm installed (skip to the end of this article if you need to get and build Dormterm). Before we begin, let’s take a look at the technology.

Front end vs. back end

DomTerm is mostly written in JavaScript and runs in a browser engine. It can be a desktop browser like Chrome or Firefox (see Figure 3), or it can be an embedded browser. Using a generic web browser is fine, but the user experience is not good enough (because the menus are built for generic web browsing, not for terminal emulators), and the security model hampers use. So it’s better to use an embedded browser.

Currently the following are supported:

  • Qdomterm, using the Qt toolkit and QtWebEngine
  • An embedded Electron (see Figure 1)
  • Atom-domterm runs Domterm as an Atom text editor (also based on Electron) package integrated with the Atom panel system (see Figure 2)
  • A WebEngine wrapper for JavaFX, which is useful for Java programming (see Figure 4)
  • Previously the front-end used Firefox-XUL as the preferred option, but Mozilla has discontinued XUL
DomTerm terminal panes in Atom editor

Figure 2: DomTerm terminal panel in Atom editor.

Right now, the Electron front-end is probably the best choice, followed by the Qt front-end. If you use Atom, atom-DomTerm also works pretty well.

The back-end server is written in C. It manages pseudo terminals (PTY) and sessions. It is also an HTTP server that provides Javascript and other files for the front end. The domterm command starts terminal tasks and performs other requests. If no server is running, DomTerm will service itself. Communication between the backend and the server is usually done using WebSockets (libwebSockets on the server). However, the embedding of JavaFX uses neither Websockets nor DomTerm servers. Instead, Java applications communicate directly over java-javascript Bridges.

A robust xTERm-compatible terminal emulator

DomTerm looks and feels like a modern terminal emulator. It handles mouse events, 24-bit colors, Unicode, double width characters (CJK), and input methods. DomTerm works very well on the VTTEST test suite.

Its unusual features include:

Show/Hide button (” fold “) : The little triangle (figure 2) is the button to hide/show the corresponding output. A button can be created by simply adding specific escape characters to the prompt.

Mouse-click support for Readline and similar input editors: If you click on the input field (yellow), DomTerm sends the correct arrow key sequence to the application. (You can enable this feature with escape characters in the prompt, or you can force it by Alt+ clicking.)

Styling the terminal with CSS: This is usually done in ~/.domterm/settings.ini, which is automatically reloaded when saved. For example, in Figure 2, a background color is set for terminals.

A better REPL console

A classic terminal emulator works based on rectangular character cells. This is fine on the REPL (command line), but not ideal. Here are some useful DomTerm features of the REPL that are not usually found in terminal emulators:

A command that “prints” a picture, graph, mathematical formula, or set of clickable links: an application can send escape characters containing almost any HTML. (HTML is stripped out to remove JavaScript and other dangerous features.)

Figure 3 shows a snippet from a gnuplot session. Gnuplot (2.1 and later) supports DormTerm as a terminal type. The graphic output is converted to an SVG image, which is then printed to the terminal. My blog post on Gnuplot display on DormTerm provides more information on this.

Figure 3: Gnuplot screenshot.

The Kawa language has a library for creating and converting geometric image values. If you print such image values to the DomTerm terminal, the image is converted to SVG and embedded in the output.

Figure 4: Computable geometry in Kawa.

Rich text output: HtML-styled help messages are easier to read and look better. The bottom panel of Figure 1 shows the output of dormTerm Help. (The output is plain text if it is not run under DomTerm.) Notice the PAUSED message in the built-in pager.

Includes error messages for clickable links: DomTerm recognizes the syntax filename:line:column and converts it into a link that opens the file and locates the row in a customizable text editor. (This applies to relative path filenames if you use PROMPT_COMMAND or similar to trace directories.)

The compiler can detect it running under DomTerm and issue file links directly with escape characters. This is much more robust than style matching that relies on DomTerm, because it can handle Spaces and other characters without relying on directory tracing. In Figure 4, you can see the error message from the Kawa Compiler. Hovering over the file location makes it underlined, and file: URL appears in the Atom-DomTerm message bar (bottom of the window). (When atom-Domterm is not used, such a message is displayed in a float box, as the PAUSED message you see in Figure 1.)

The action when a link is clicked is configurable. The default action for a file: link with the #position suffix is to open that file in a text editor.

** Structured internal representation: ** The following are represented as internal node structures: commands, prompts, input lines, normal and error outputs, tags, and if “save as HTML”, the structure is retained. HTML files are COMPATIBLE with XML, so you can use XML tools to search or transform the output. The domterm view-saved command opens the saved HTML file in a way that enables command folding (show/hide buttons are active) and window resizing.

Built-in Lisp graceful printing: You can include graceful printing commands (e.g., Grouping) in your output, so that line breaks are recalculated based on window sizing. Check out my article DomTerm in dynamic Graceful printing for a more in-depth discussion.

Basic inline editing, with a history (like GNU Readline) : this uses the browser’s own editor, so it has excellent mouse and selection handling. You can do this in normal character mode (most of the input characters are referred to the process); Or between line modes (where normal characters are inserted directly, whereas control characters cause editing, and the enter key sends the edited line to the process). The default is automatic mode, with DomTerm switching between character mode and line mode depending on whether the PTY is in raw mode or terminal mode.

Built-in pager (similar to a simplified version of less) : Keyboard shortcuts for scrolling. In “page mode,” output pauses after each new screen (or individual line, if you want to move forward row by row); Page mode is simple for user input, so (if you want) you can run an interactive program without blocking it.

Multiplexing and sessions

Labels and Tiling: You can not only create multiple terminal labels, but also tiling them. You can either use mouse or keyboard shortcuts to create or switch panels and tabs. They can be rearranged and resized with the mouse. This is done through the GoldenLayout JavaScript library. Figure 1 shows a window with two panels. There are two tabs above, one running Midnight Commander; The bottom panel shows the Dormterm Help output in HTML. In Atom, by contrast, we use its own drag-and-drop panels and tabs. You can see this in Figure 2.

Detach or reconnect sessions: Like TMUx and GNU Screen, DomTerm supports session scheduling. You can even attach multiple Windows or panels to the same session. This supports multi-user session sharing and remote linking. For security, all sessions on the same server need to be able to read the Unix domain interface and a local file containing a random key. This restriction will be relaxed when we have good, secure remote links.)

The domterm command is similar to TMUx and GNU Screen in that it has several options for controlling or opening a single or multiple session server. The main difference is that if it is not running under DomTerm, the dormterm command creates a new top-level window instead of running on the existing terminal.

Like tMUx and Git, the dormterm command has many subcommands. Some subcommands create Windows or sessions. Others (such as “printing” a picture) work only under an existing DormTerm session.

The domterm Browse command opens a window or panel to browse a specified URL, such as while browsing a document.

Get and install DomTerm

DomTerm is available from its Github repository. There are no pre-built packages, but there are detailed instructions. All the prerequisites are available on Fedora 27, which makes it particularly easy to build.


Via: opensource.com/article/18/…

Translated by tomjlw and proofread by wxy

This article is originally compiled by LCTT and released in Linux China