Introducing xterm-headless
In addition to browser components/addons, the official xterm.js repo also provides a headless component. So what is xterm‑headless?
While browsing inshellisense recently I noticed it uses xterm‑headless. After digging in, the role of the headless component became clear. Notes below.
headless nodejs support
From the official docs, headless is for Node.js usage. In other words, the server can instantiate a terminal client component and operate on it.
Notes
- There are no official Node‑side addons yet, but custom ones are possible — just don’t depend on DOM APIs.
Usage
Usage mirrors the browser side — instantiate xterm.Terminal
directly.
Use cases
Knowing the server can also host xterm.js, where does it shine?
For example: with an ssh2 connection on the server, data exchanged with the target host is a stream. Typically, we forward it to the client and write it into xterm.js, which structures it. With server‑side headless support, we can also feed the data into a server‑resident terminal. If the user closes the browser, the server session keeps running and can continue to write data to the “virtual” terminal — essentially a remote/sentinel mode.
inshellisense
Back to inshellisense (IS): it uses headless to write terminal data into a virtual terminal so it can compute cursor positions, extract terminal info, etc. See the source.
Final Thoughts
Headless is quite useful — the server can fully instantiate an xterm instance.