Introducing xterm-headless

What xterm-headless is and how to use it to implement terminal functionality on Node.js, with use cases and notes.

Dec 25, 2023 · 2 min read · 227 Words · -Views -Comments · Programming
WebShell 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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