使用xterm.js,如何获取控制台中的文本term.write(...)使用term.write(...)或其他方法输入的文本)。
获取HTML的textContent不起作用,因为html处理空白的方式不同,因为xtermjs以不同的方式处理颜色。
Using xterm.js, how do you get the text in the console (the text entered with term.write(...) or other methods).
Getting the textContent of the HTML does not work, because html handles whitespace differently and because xtermjs handles colors differently.
最满意答案
你所指的是终端缓冲区的内容。
截至目前(xterm.js 3.2)没有公共API来检索缓冲区的内容,所以你将不得不解决这个问题。
尝试通过DOM检索内容不起作用。 Xterm.js从3.0版开始使用canvas元素,而不是DOM div元素和文本节点来提高性能。
使用公共API完成此操作的最佳方式是通过监听data事件并使用该事件 。 data事件在大块数据被分派到终端进行处理时发出。
What you are referring to is the contents of the terminal's buffer.
As of now (xterm.js 3.2) there is no public API to retrieve the contents of the buffer, so you will have to work your way around this.
Attempting to retrieve the contents via the DOM will not work. Xterm.js uses a canvas element since version 3.0, instead of DOM div elements and text nodes, for performance.
The best way to do this with a public API is by listening to the data event and work with that. The data event is emitted when a chunk of data is being dispatched to the terminal for handling.
更多推荐
发布评论