Introducing xterm-headless

· 2 min read · 227 Words · -Views -Comments

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.

https://static.1991421.cn/2023/2023-12-25-225330.jpeg

Notes

  1. 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.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover