mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-04 19:35:46 +01:00
Merge pull request #36999 from Microsoft/tyriar/29840-onLineData-api
Provide an ITerminalInstance.onLineData internal API
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user