提交 8bf87ab3 编写于 作者: D Daniel Imms

Provide an ITerminalInstance.onLineData internal API

Fixes #29840
上级 77ba628a
......@@ -354,9 +354,22 @@ export interface ITerminalInstance {
*
* @param listener The listener function which takes the processes' data stream (including
* ANSI escape sequences).
*
* @deprecated onLineData will replace this.
*/
onData(listener: (data: string) => void): IDisposable;
/**
* Attach a listener to listen for new lines added to this terminal instance.
*
* @param listener The listener function which takes new line strings added to the terminal,
* excluding ANSI escape sequences. The line event will fire when an LF character is added to
* the terminal (ie. the line is not wrapped), note that this means taht the line data will
* never fire for the last line, until the line is ended with a LF character. The lineData
* string will contain the fully wrapped line, not containing any LF/CR characters.
*/
onLineData(listener: (lineData: string) => void): IDisposable;
/**
* Attach a listener that fires when the terminal's pty process exits.
*
......
......@@ -827,6 +827,32 @@ export class TerminalInstance implements ITerminalInstance {
};
}
public onLineData(listener: (lineData: string) => void): lifecycle.IDisposable {
if (!this._xterm) {
throw new Error('xterm must be initialized');
}
const lineFeedListener = () => {
const buffer = (<any>this._xterm.buffer);
const newLine = buffer.lines.get(buffer.ybase + buffer.y);
if (!newLine.isWrapped) {
let i = buffer.ybase + buffer.y - 1;
let lineData = buffer.translateBufferLineToString(i, true);
while (i >= 0 && buffer.lines.get(i--).isWrapped) {
lineData = buffer.translateBufferLineToString(i, true) + lineData;
}
listener(lineData);
}
};
this._xterm.on('lineFeed', lineFeedListener);
return {
dispose: () => {
if (this._xterm) {
this._xterm.off('lineFeed', lineFeedListener);
}
}
};
}
public onExit(listener: (exitCode: number) => void): lifecycle.IDisposable {
if (this._process) {
this._process.on('exit', listener);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册