Skip to content

Commit

Permalink
Use pty naming instead of virtual process
Browse files Browse the repository at this point in the history
Part of #77160
  • Loading branch information
Tyriar committed Jul 25, 2019
1 parent a32dfe1 commit 3866deb
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { window, Terminal, TerminalVirtualProcess, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget } from 'vscode';
import { window, Terminal, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget } from 'vscode';
import { doesNotThrow, equal, ok } from 'assert';

suite('window namespace tests', () => {
Expand Down Expand Up @@ -264,12 +264,12 @@ suite('window namespace tests', () => {
});
term.dispose();
});
const virtualProcess: TerminalVirtualProcess = {
const pty: Pseudoterminal = {
onDidWrite: new EventEmitter<string>().event,
start: () => {},
shutdown: () => {}
};
window.createTerminal({ name: 'c', virtualProcess });
window.createTerminal({ name: 'c', pty });
});

test('should fire Terminal.onData on write', (done) => {
Expand All @@ -291,20 +291,20 @@ suite('window namespace tests', () => {
let startResolve: () => void;
const startPromise: Promise<void> = new Promise<void>(r => startResolve = r);
const writeEmitter = new EventEmitter<string>();
const virtualProcess: TerminalVirtualProcess = {
const pty: Pseudoterminal = {
onDidWrite: writeEmitter.event,
start: () => startResolve(),
shutdown: () => {}
};
const terminal = window.createTerminal({ name: 'foo', virtualProcess });
const terminal = window.createTerminal({ name: 'foo', pty });
});

test('should fire provide dimensions on start as the terminal has been shown', (done) => {
const reg1 = window.onDidOpenTerminal(term => {
equal(terminal, term);
reg1.dispose();
});
const virtualProcess: TerminalVirtualProcess = {
const pty: Pseudoterminal = {
onDidWrite: new EventEmitter<string>().event,
start: (dimensions) => {
ok(dimensions!.columns > 0);
Expand All @@ -317,7 +317,7 @@ suite('window namespace tests', () => {
},
shutdown: () => {}
};
const terminal = window.createTerminal({ name: 'foo', virtualProcess });
const terminal = window.createTerminal({ name: 'foo', pty });
});

test('should respect dimension overrides', (done) => {
Expand All @@ -340,13 +340,13 @@ suite('window namespace tests', () => {
});
const writeEmitter = new EventEmitter<string>();
const overrideDimensionsEmitter = new EventEmitter<TerminalDimensions>();
const virtualProcess: TerminalVirtualProcess = {
const pty: Pseudoterminal = {
onDidWrite: writeEmitter.event,
onDidOverrideDimensions: overrideDimensionsEmitter.event,
start: () => {},
shutdown: () => {}
};
const terminal = window.createTerminal({ name: 'foo', virtualProcess });
const terminal = window.createTerminal({ name: 'foo', pty });
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ suite.only('workspace-namespace', () => {
customProp1: 'testing task one'
};
const writeEmitter = new vscode.EventEmitter<string>();
const execution = new vscode.CustomExecution2((): Thenable<vscode.TerminalVirtualProcess> => {
return Promise.resolve(<vscode.TerminalVirtualProcess>{
const execution = new vscode.CustomExecution2((): Thenable<vscode.Pseudoterminal> => {
return Promise.resolve(<vscode.Pseudoterminal>{
onDidWrite: writeEmitter.event,
start: () => {
writeEmitter.fire('testing\r\n');
Expand Down
118 changes: 65 additions & 53 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ declare module 'vscode' {
* [Terminal.sendText](#Terminal.sendText) is triggered that will fire the
* [TerminalRenderer.onDidAcceptInput](#TerminalRenderer.onDidAcceptInput) event.
*
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*
* **Example:** Create a terminal renderer, show it and write hello world in red
* ```typescript
Expand All @@ -828,7 +828,7 @@ declare module 'vscode' {
export interface TerminalRenderer {
/**
* The name of the terminal, this will appear in the terminal selector.
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*/
name: string;

Expand All @@ -837,7 +837,7 @@ declare module 'vscode' {
* a value smaller than the maximum value, if this is undefined the terminal will auto fit
* to the maximum value [maximumDimensions](TerminalRenderer.maximumDimensions).
*
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*
* **Example:** Override the dimensions of a TerminalRenderer to 20 columns and 10 rows
* ```typescript
Expand All @@ -855,14 +855,14 @@ declare module 'vscode' {
* Listen to [onDidChangeMaximumDimensions](TerminalRenderer.onDidChangeMaximumDimensions)
* to get notified when this value changes.
*
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*/
readonly maximumDimensions: TerminalDimensions | undefined;

/**
* The corresponding [Terminal](#Terminal) for this TerminalRenderer.
*
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*/
readonly terminal: Terminal;

Expand All @@ -871,7 +871,7 @@ declare module 'vscode' {
* text to the underlying _process_, this will write the text to the terminal itself.
*
* @param text The text to write.
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*
* **Example:** Write red text to the terminal
* ```typescript
Expand All @@ -890,7 +890,7 @@ declare module 'vscode' {
* [Terminal.sendText](#Terminal.sendText). Keystrokes are converted into their
* corresponding VT sequence representation.
*
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*
* **Example:** Simulate interaction with the terminal from an outside extension or a
* workbench command such as `workbench.action.terminal.runSelectedText`
Expand All @@ -908,7 +908,7 @@ declare module 'vscode' {
* An event which fires when the [maximum dimensions](#TerminalRenderer.maximumDimensions) of
* the terminal renderer change.
*
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*/
readonly onDidChangeMaximumDimensions: Event<TerminalDimensions>;
}
Expand All @@ -918,60 +918,60 @@ declare module 'vscode' {
* Create a [TerminalRenderer](#TerminalRenderer).
*
* @param name The name of the terminal renderer, this shows up in the terminal selector.
* @deprecated Use [virtual processes](#TerminalVirtualProcess) instead.
* @deprecated Use [ExtensionTerminalOptions](#ExtensionTerminalOptions) instead.
*/
export function createTerminalRenderer(name: string): TerminalRenderer;
}

//#endregion

//#region Terminal extension pty
//#region Extension terminals

export namespace window {
/**
* Creates a [Terminal](#Terminal) where an extension acts as the process.
* Creates a [Terminal](#Terminal) where an extension controls the teerminal.
*
* @param options A [TerminalVirtualProcessOptions](#TerminalVirtualProcessOptions) object describing the
* characteristics of the new terminal.
* @param options An [ExtensionTerminalOptions](#ExtensionTerminalOptions) object describing
* the characteristics of the new terminal.
* @return A new Terminal.
*/
export function createTerminal(options: TerminalVirtualProcessOptions): Terminal;
export function createTerminal(options: ExtensionTerminalOptions): Terminal;
}

/**
* Value-object describing what options a virtual process terminal should use.
*/
export interface TerminalVirtualProcessOptions {
export interface ExtensionTerminalOptions {
/**
* A human-readable string which will be used to represent the terminal in the UI.
*/
name: string;

/**
* An implementation of [TerminalVirtualProcess](#TerminalVirtualProcess) that allows an
* extension to act as a terminal's backing process.
* An implementation of [Pseudoterminal](#Pseudoterminal) that allows an extension to
* control a terminal.
*/
virtualProcess: TerminalVirtualProcess;
pty: Pseudoterminal;
}

/**
* Defines the interface of a terminal virtual process, enabling extensions to act as a process
* in the terminal.
* Defines the interface of a terminal pty, enabling extensions to control a terminal.
*/
interface TerminalVirtualProcess {
interface Pseudoterminal {
/**
* An event that when fired will write data to the terminal. Unlike
* [Terminal.sendText](#Terminal.sendText) which sends text to the underlying _process_,
* this will write the text to the terminal itself.
* [Terminal.sendText](#Terminal.sendText) which sends text to the underlying _process_
* (the pty "slave"), this will write the text to the terminal itself (the pty "master").
*
* **Example:** Write red text to the terminal
* ```typescript
* const writeEmitter = new vscode.EventEmitter<string>();
* const virtualProcess: TerminalVirtualProcess = {
* onDidWrite: writeEmitter.event
* const pty: vscode.Pseudoterminal = {
* onDidWrite: writeEmitter.event,
* start: () => writeEmitter.fire('\x1b[31mHello world\x1b[0m'),
* shutdown: () => {}
* };
* vscode.window.createTerminal({ name: 'My terminal', virtualProcess });
* writeEmitter.fire('\x1b[31mHello world\x1b[0m');
* vscode.window.createTerminal({ name: 'My terminal', pty });
* ```
*
* **Example:** Move the cursor to the 10th row and 20th column and write an asterisk
Expand All @@ -985,44 +985,50 @@ declare module 'vscode' {
* An event that when fired allows overriding the [dimensions](#Terminal.dimensions) of the
* terminal. Note that when set the overridden dimensions will only take effect when they
* are lower than the actual dimensions of the terminal (ie. there will never be a scroll
* bar). Set to `undefined` for the terminal to go back to the regular dimensions.
* bar). Set to `undefined` for the terminal to go back to the regular dimensions (fit to
* the size of the panel).
*
* **Example:** Override the dimensions of a terminal to 20 columns and 10 rows
* ```typescript
* const dimensionsEmitter = new vscode.EventEmitter<string>();
* const virtualProcess: TerminalVirtualProcess = {
* const pty: vscode.Pseudoterminal = {
* onDidWrite: writeEmitter.event,
* onDidOverrideDimensions: dimensionsEmitter.event
* onDidOverrideDimensions: dimensionsEmitter.event,
* start: () => {
* dimensionsEmitter.fire({
* columns: 20,
* rows: 10
* });
* },
* shutdown: () => {}
* };
* vscode.window.createTerminal({ name: 'My terminal', virtualProcess });
* dimensionsEmitter.fire({
* columns: 20,
* rows: 10
* });
* vscode.window.createTerminal({ name: 'My terminal', pty });
* ```
*/
onDidOverrideDimensions?: Event<TerminalDimensions | undefined>;

/**
* An event that when fired will exit the process with an exit code, this will behave the
* same for a virtual process as when a regular process exits with an exit code. Note that
* exit codes must be positive numbers, when negative the exit code will be forced to `1`.
* same for an extension treminal as when a regular process exits with an exit code. Note
* that exit codes must be positive numbers, when negative the exit code will be forced to
* `1`.
*
* **Example:** Exit with an exit code of `0` if the y key is pressed, otherwise `1`.
* ```typescript
* const writeEmitter = new vscode.EventEmitter<string>();
* const exitEmitter = new vscode.EventEmitter<number>();
* const virtualProcess: TerminalVirtualProcess = {
* const pty: vscode.Pseudoterminal = {
* onDidWrite: writeEmitter.event,
* input: data => exitEmitter.fire(data === 'y' ? 0 : 1)
* start: () => writeEmitter.fire('Press y to exit successfully'),
* shutdown: () => {}
* handleInput: data => exitEmitter.fire(data === 'y' ? 0 : 1)
* };
* vscode.window.createTerminal({ name: 'Exit example', virtualProcess });
* writeEmitter.fire('Press y to exit successfully');
* vscode.window.createTerminal({ name: 'Exit example', pty });
*/
onDidExit?: Event<number>;

/**
* Implement to handle when the terminal is ready to start firing events.
* Implement to handle when the pty is ready to start firing events.
*
* @param initialDimensions The dimensions of the terminal, this will be undefined if the
* terminal panel has not been opened before this is called.
Expand All @@ -1035,21 +1041,23 @@ declare module 'vscode' {
shutdown(): void;

/**
* Implement to handle keystrokes in the terminal or when an extension calls
* [Terminal.sendText](#Terminal.sendText). Keystrokes are converted into their
* corresponding VT sequence representation.
* Implement to handle incoming keystrokes in the terminal or when an extension calls
* [Terminal.sendText](#Terminal.sendText). `data` contains the keystrokes/text serialized into
* their corresponding VT sequence representation.
*
* @param data The sent data.
* @param data The incoming data.
*
* **Example:** Echo input in the terminal. The sequence for enter (`\r`) is translated to
* CRLF to go to a new line and move the cursor to the start of the line.
* ```typescript
* const writeEmitter = new vscode.EventEmitter<string>();
* const virtualProcess: TerminalVirtualProcess = {
* const pty: vscode.Pseudoterminal = {
* onDidWrite: writeEmitter.event,
* start: () => {},
* shutdown: () => {},
* handleInput: data => writeEmitter.fire(data === '\r' ? '\r\n' : data)
* };
* vscode.window.createTerminal({ name: 'Local echo', virtualProcess });
* vscode.window.createTerminal({ name: 'Local echo', pty });
* ```
*/
handleInput?(data: string): void;
Expand Down Expand Up @@ -1145,6 +1153,7 @@ declare module 'vscode' {
}
//#endregion

//#region CustomExecution
/**
* Class used to execute an extension callback as a task.
*/
Expand All @@ -1168,16 +1177,18 @@ declare module 'vscode' {
*/
export class CustomExecution2 {
/**
* @param process The [TerminalVirtualProcess](#TerminalVirtualProcess) to be used by the task to display output.
* @param process The [Pseudotrminal](#Pseudoterminal) to be used by the task to display output.
* @param callback The callback that will be called when the task is started by a user.
*/
constructor(callback: (thisArg?: any) => Thenable<TerminalVirtualProcess>);
constructor(callback: (thisArg?: any) => Thenable<Pseudoterminal>);

/**
* The callback used to execute the task. Cancellation should be handled using the shutdown method of [TerminalVirtualProcess](#TerminalVirtualProcess).
* When the task is complete, onDidExit should be fired on the TerminalVirtualProcess with the exit code with '0' for success and a non-zero value for failure.
* The callback used to execute the task. Cancellation should be handled using
* [Pseudoterminal.shutdown](#Pseudoterminal.shutdown). When the task is complete,
* [Pseudoterminal.onDidExit](#Pseudoterminal.onDidExit) should be fired with the exit code
* with '0' for success and a non-zero value for failure.
*/
callback: (thisArg?: any) => Thenable<TerminalVirtualProcess>;
callback: (thisArg?: any) => Thenable<Pseudoterminal>;
}

/**
Expand All @@ -1203,6 +1214,7 @@ declare module 'vscode' {
*/
execution2?: ProcessExecution | ShellExecution | CustomExecution | CustomExecution2;
}
//#endregion

//#region Tasks
export interface TaskPresentationOptions {
Expand Down
Loading

0 comments on commit 3866deb

Please sign in to comment.