Terminal Search in WebShell

How to implement terminal search in WebShell using the xterm search addon, plus notes about normal vs alternate screen buffers and event hooks.

Aug 21, 2023 · 1 min read · 71 Words · -Views -Comments · Programming
🇨🇳 阅读中文版
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.

install

npm i xterm-addon-search

const searchAddon = new SearchAddon();

term.loadAddon(searchAddon);

Notes

On the alternate screen (e.g., within vi), search results may be inaccurate, since the content loaded by vi isn’t necessarily the full file. For commands like cat, terminal-level search works fine. On the alternate screen, prefer the editor’s built-in search.

Determine whether the terminal is in normal or alternate screen with:

term.buffer.active.type === 'normal'

To listen for changes, use term.onBufferChange.

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