terminal.ts 22.3 KB
Newer Older
D
Daniel Imms 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

M
Matt Bierner 已提交
6
import { Event } from 'vs/base/common/event';
D
Dirk Baeumer 已提交
7
import { IDisposable } from 'vs/base/common/lifecycle';
8
import * as platform from 'vs/base/common/platform';
D
Daniel Imms 已提交
9
import { RawContextKey, ContextKeyExpr, IContextKey } from 'vs/platform/contextkey/common/contextkey';
10
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
11
import { URI } from 'vs/base/common/uri';
12
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
D
Daniel Imms 已提交
13 14 15 16 17

export const TERMINAL_PANEL_ID = 'workbench.panel.terminal';

export const TERMINAL_SERVICE_ID = 'terminalService';

18 19 20
/** A context key that is set when there is at least one opened integrated terminal. */
export const KEYBINDING_CONTEXT_TERMINAL_IS_OPEN = new RawContextKey<boolean>('terminalIsOpen', false);
/** A context key that is set when the integrated terminal has focus. */
21
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new RawContextKey<boolean>('terminalFocus', false);
22
/** A context key that is set when the integrated terminal does not have focus. */
J
Johannes Rieken 已提交
23
export const KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_FOCUS.toNegated();
24

25
/** A keybinding context key that is set when the integrated terminal has text selected. */
26
export const KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED = new RawContextKey<boolean>('terminalTextSelected', false);
27 28 29
/** A keybinding context key that is set when the integrated terminal does not have text selected. */
export const KEYBINDING_CONTEXT_TERMINAL_TEXT_NOT_SELECTED: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED.toNegated();

R
rebornix 已提交
30
/**  A context key that is set when the find widget in integrated terminal is visible. */
31
export const KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('terminalFindWidgetVisible', false);
R
rebornix 已提交
32 33
/**  A context key that is set when the find widget in integrated terminal is not visible. */
export const KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_NOT_VISIBLE: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE.toNegated();
34 35
/**  A context key that is set when the find widget find input in integrated terminal is focused. */
export const KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED = new RawContextKey<boolean>('terminalFindWidgetInputFocused', false);
36 37
/**  A context key that is set when the find widget in integrated terminal is focused. */
export const KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_FOCUSED = new RawContextKey<boolean>('terminalFindWidgetFocused', false);
38 39
/**  A context key that is set when the find widget find input in integrated terminal is not focused. */
export const KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_NOT_FOCUSED: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED.toNegated();
R
rebornix 已提交
40

41
export const IS_WORKSPACE_SHELL_ALLOWED_STORAGE_KEY = 'terminal.integrated.isWorkspaceShellAllowed';
42
export const NEVER_SUGGEST_SELECT_WINDOWS_SHELL_STORAGE_KEY = 'terminal.integrated.neverSuggestSelectWindowsShell';
D
Daniel Imms 已提交
43
export const NEVER_MEASURE_RENDER_TIME_STORAGE_KEY = 'terminal.integrated.neverMeasureRenderTime';
44

45 46 47 48 49
// The creation of extension host terminals is delayed by this value (milliseconds). The purpose of
// this delay is to allow the terminal instance to initialize correctly and have its ID set before
// trying to create the corressponding object on the ext host.
export const EXT_HOST_CREATION_DELAY = 100;

B
Benjamin Pasero 已提交
50
export const ITerminalService = createDecorator<ITerminalService>(TERMINAL_SERVICE_ID);
D
Daniel Imms 已提交
51

52 53 54 55 56 57
export const TerminalCursorStyle = {
	BLOCK: 'block',
	LINE: 'line',
	UNDERLINE: 'underline'
};

58 59
export const TERMINAL_CONFIG_SECTION = 'terminal.integrated';

60 61 62 63
export const DEFAULT_LETTER_SPACING = 0;
export const MINIMUM_LETTER_SPACING = -5;
export const DEFAULT_LINE_HEIGHT = 1.0;

64 65
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';

66
export interface ITerminalConfiguration {
D
Daniel Imms 已提交
67 68 69 70
	shell: {
		linux: string;
		osx: string;
		windows: string;
71
	};
D
Daniel Imms 已提交
72 73 74 75 76
	shellArgs: {
		linux: string[];
		osx: string[];
		windows: string[];
	};
D
Daniel Imms 已提交
77
	macOptionIsMeta: boolean;
78
	macOptionClickForcesSelection: boolean;
D
Daniel Imms 已提交
79
	rendererType: 'auto' | 'canvas' | 'dom';
80
	rightClickBehavior: 'default' | 'copyPaste' | 'selectWord';
D
Daniel Imms 已提交
81 82
	cursorBlinking: boolean;
	cursorStyle: string;
83
	drawBoldTextInBrightColors: boolean;
D
Daniel Imms 已提交
84
	fontFamily: string;
85 86
	fontWeight: FontWeight;
	fontWeightBold: FontWeight;
87
	// fontLigatures: boolean;
D
Daniel Imms 已提交
88
	fontSize: number;
89
	letterSpacing: number;
D
Daniel Imms 已提交
90 91 92 93 94 95
	lineHeight: number;
	setLocaleVariables: boolean;
	scrollback: number;
	commandsToSkipShell: string[];
	cwd: string;
	confirmOnExit: boolean;
D
Daniel Imms 已提交
96
	enableBell: boolean;
97 98 99 100 101
	env: {
		linux: { [key: string]: string };
		osx: { [key: string]: string };
		windows: { [key: string]: string };
	};
B
bpceee 已提交
102
	showExitAlert: boolean;
103
	experimentalBufferImpl: 'JsArray' | 'TypedArray';
104
	splitCwd: 'workspaceRoot' | 'initial' | 'inherited';
105
	windowsEnableConpty: boolean;
106 107
}

108
export interface ITerminalConfigHelper {
109
	config: ITerminalConfiguration;
110
	getFont(): ITerminalFont;
111 112 113
	/**
	 * Merges the default shell path and args into the provided launch configuration
	 */
114
	mergeDefaultShellPathAndArgs(shell: IShellLaunchConfig, platformOverride?: platform.Platform): void;
115 116
	/** Sets whether a workspace shell configuration is allowed or not */
	setWorkspaceShellAllowed(isAllowed: boolean): void;
117 118 119 120
}

export interface ITerminalFont {
	fontFamily: string;
D
Daniel Imms 已提交
121
	fontSize: number;
122
	letterSpacing: number;
123
	lineHeight: number;
124 125
	charWidth?: number;
	charHeight?: number;
126 127
}

128 129 130 131
export interface ITerminalEnvironment {
	[key: string]: string | null;
}

132
export interface IShellLaunchConfig {
133 134 135
	/**
	 * The name of the terminal, if this is not set the name of the process will be used.
	 */
136
	name?: string;
137 138 139 140

	/**
	 * The shell executable (bash, cmd, etc.).
	 */
141
	executable?: string;
142

143 144
	/**
	 * The CLI arguments to use with executable, a string[] is in argv format and will be escaped,
D
Daniel Imms 已提交
145 146
	 * a string is in "CommandLine" pre-escaped format and will be used as is. The string option is
	 * only supported on Windows and will throw an exception if used on macOS or Linux.
147 148
	 */
	args?: string[] | string;
149

150 151 152 153
	/**
	 * The current working directory of the terminal, this overrides the `terminal.integrated.cwd`
	 * settings key.
	 */
K
kieferrm 已提交
154
	cwd?: string | URI;
155

156 157 158 159
	/**
	 * A custom environment for the terminal, if this is not set the environment will be inherited
	 * from the VS Code process.
	 */
160
	env?: ITerminalEnvironment;
161

162 163 164 165 166
	/**
	 * Whether to ignore a custom cwd from the `terminal.integrated.cwd` settings key (eg. if the
	 * shell is being launched by an extension).
	 */
	ignoreConfigurationCwd?: boolean;
167

168
	/** Whether to wait for a key press before closing the terminal. */
169 170
	waitOnExit?: boolean | string;

171 172 173 174 175 176 177
	/**
	 * A string including ANSI escape sequences that will be written to the terminal emulator
	 * _before_ the terminal process has launched, a trailing \n is added at the end of the string.
	 * This allows for example the terminal instance to display a styled message as the first line
	 * of the terminal. Use \x1b over \033 or \e for the escape control character.
	 */
	initialText?: string;
178 179 180 181 182 183

	/**
	 * When true the terminal will be created with no process. This is primarily used to give
	 * extensions full control over the terminal.
	 */
	isRendererOnly?: boolean;
184 185
}

D
Daniel Imms 已提交
186
export interface ITerminalService {
187
	_serviceBrand: any;
188

D
Daniel Imms 已提交
189
	activeTabIndex: number;
190
	configHelper: ITerminalConfigHelper;
D
Daniel Imms 已提交
191
	onActiveTabChanged: Event<void>;
192
	onTabDisposed: Event<ITerminalTab>;
193
	onInstanceCreated: Event<ITerminalInstance>;
194
	onInstanceDisposed: Event<ITerminalInstance>;
195
	onInstanceProcessIdReady: Event<ITerminalInstance>;
D
Daniel Imms 已提交
196
	onInstanceDimensionsChanged: Event<ITerminalInstance>;
197
	onInstanceRequestExtHostProcess: Event<ITerminalProcessExtHostRequest>;
198
	onInstancesChanged: Event<void>;
199
	onInstanceTitleChanged: Event<ITerminalInstance>;
200
	onActiveInstanceChanged: Event<ITerminalInstance>;
201
	terminalInstances: ITerminalInstance[];
D
Daniel Imms 已提交
202
	terminalTabs: ITerminalTab[];
203

204 205 206 207 208 209 210
	/**
	 * Creates a terminal.
	 * @param shell The shell launch configuration to use.
	 * @param wasNewTerminalAction Whether this was triggered by a new terminal action, if so a
	 * default shell selection dialog may display.
	 */
	createTerminal(shell?: IShellLaunchConfig, wasNewTerminalAction?: boolean): ITerminalInstance;
211 212 213 214 215 216

	/**
	 * Creates a terminal renderer.
	 * @param name The name of the terminal.
	 */
	createTerminalRenderer(name: string): ITerminalInstance;
217 218 219
	/**
	 * Creates a raw terminal instance, this should not be used outside of the terminal part.
	 */
M
Matt Bierner 已提交
220
	createInstance(terminalFocusContextKey: IContextKey<boolean>, configHelper: ITerminalConfigHelper, container: HTMLElement | undefined, shellLaunchConfig: IShellLaunchConfig, doCreateProcess: boolean): ITerminalInstance;
221
	getInstanceFromId(terminalId: number): ITerminalInstance;
T
t-amqi 已提交
222
	getInstanceFromIndex(terminalIndex: number): ITerminalInstance;
D
Daniel Imms 已提交
223
	getTabLabels(): string[];
M
Matt Bierner 已提交
224
	getActiveInstance(): ITerminalInstance | null;
225 226
	setActiveInstance(terminalInstance: ITerminalInstance): void;
	setActiveInstanceByIndex(terminalIndex: number): void;
227
	getActiveOrCreateInstance(wasNewTerminalAction?: boolean): ITerminalInstance;
228
	splitInstance(instance: ITerminalInstance, shell?: IShellLaunchConfig): void;
229

M
Matt Bierner 已提交
230
	getActiveTab(): ITerminalTab | null;
231 232 233 234
	setActiveTabToNext(): void;
	setActiveTabToPrevious(): void;
	setActiveTabByIndex(tabIndex: number): void;

235
	showPanel(focus?: boolean): Promise<void>;
D
Daniel Imms 已提交
236
	hidePanel(): void;
237
	focusFindWidget(): Promise<void>;
238
	hideFindWidget(): void;
239
	getFindState(): FindReplaceState;
240 241
	findNext(): void;
	findPrevious(): void;
242

243
	setContainers(panelContainer: HTMLElement, terminalContainer: HTMLElement): void;
244
	selectDefaultWindowsShell(): Promise<string>;
245
	setWorkspaceShellAllowed(isAllowed: boolean): void;
246

247
	requestExtHostProcess(proxy: ITerminalProcessExtHostProxy, shellLaunchConfig: IShellLaunchConfig, activeWorkspaceRootUri: URI, cols: number, rows: number): void;
D
Daniel Imms 已提交
248
}
D
Daniel Imms 已提交
249

D
Daniel Imms 已提交
250 251 252 253 254 255 256
export const enum Direction {
	Left = 0,
	Right = 1,
	Up = 2,
	Down = 3
}

257
export interface ITerminalTab {
M
Matt Bierner 已提交
258
	activeInstance: ITerminalInstance | null;
259
	terminalInstances: ITerminalInstance[];
D
Daniel Imms 已提交
260
	title: string;
D
Daniel Imms 已提交
261
	onDisposed: Event<ITerminalTab>;
262
	onInstancesChanged: Event<void>;
263

264 265
	focusPreviousPane(): void;
	focusNextPane(): void;
D
Daniel Imms 已提交
266
	resizePane(direction: Direction): void;
267
	setActiveInstanceByIndex(index: number): void;
D
Daniel Imms 已提交
268
	attachToElement(element: HTMLElement): void;
D
Daniel Imms 已提交
269 270
	setVisible(visible: boolean): void;
	layout(width: number, height: number): void;
271
	addDisposable(disposable: IDisposable): void;
M
Matt Bierner 已提交
272
	split(terminalFocusContextKey: IContextKey<boolean>, configHelper: ITerminalConfigHelper, shellLaunchConfig: IShellLaunchConfig): ITerminalInstance | undefined;
273 274
}

D
Daniel Imms 已提交
275 276 277 278 279 280 281 282 283 284 285 286
export interface ITerminalDimensions {
	/**
	 * The columns of the terminal.
	 */
	readonly cols: number;

	/**
	 * The rows of the terminal.
	 */
	readonly rows: number;
}

287 288 289 290 291 292 293 294 295 296 297 298 299
interface ISearchOptions {
	/**
	 * Whether the find should be done as a regex.
	 */
	regex?: boolean;
	/**
	 * Whether only whole words should match.
	 */
	wholeWord?: boolean;
	/**
	 * Whether find should pay attention to case.
	 */
	caseSensitive?: boolean;
D
Daniel Imms 已提交
300 301 302 303
	/**
	 * Whether the search should start at the current search position (not the next row)
	 */
	incremental?: boolean;
304 305
}

306
export interface ITerminalInstance {
D
jsdoc  
Daniel Imms 已提交
307 308 309 310
	/**
	 * The ID of the terminal instance, this is an arbitrary number only used to identify the
	 * terminal instance.
	 */
D
Daniel Imms 已提交
311 312 313 314
	readonly id: number;

	readonly cols: number;
	readonly rows: number;
D
jsdoc  
Daniel Imms 已提交
315

316
	/**
317 318
	 * The process ID of the shell process, this is undefined when there is no process associated
	 * with this terminal.
319
	 */
320
	processId: number | undefined;
321

D
jsdoc  
Daniel Imms 已提交
322 323 324
	/**
	 * An event that fires when the terminal instance's title changes.
	 */
325
	onTitleChanged: Event<ITerminalInstance>;
D
jsdoc  
Daniel Imms 已提交
326

327 328 329 330 331
	/**
	 * An event that fires when the terminal instance is disposed.
	 */
	onDisposed: Event<ITerminalInstance>;

332 333
	onFocused: Event<ITerminalInstance>;

334 335
	onProcessIdReady: Event<ITerminalInstance>;

336 337
	onRequestExtHostProcess: Event<ITerminalInstance>;

D
Daniel Imms 已提交
338 339
	onDimensionsChanged: Event<void>;

340 341
	onFocus: Event<ITerminalInstance>;

D
Daniel Imms 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
	/**
	 * Attach a listener to the raw data stream coming from the pty, including ANSI escape
	 * sequences.
	 */
	onData: Event<string>;

	/**
	 * Attach a listener to the "renderer" input event, this event fires for terminal renderers on
	 * keystrokes and when the Terminal.sendText extension API is used.
	 * @param listener The listener function.
	 */
	onRendererInput: Event<string>;

	/**
	 * 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 that the line data will
	 * not fire for the last line, until either the line is ended with a LF character of the process
	 * is exited. The lineData string will contain the fully wrapped line, not containing any LF/CR
	 * characters.
	 */
	onLineData: Event<string>;

	/**
	 * Attach a listener that fires when the terminal's pty process exits. The number in the event
	 * is the processes' exit code, an exit code of null means the process was killed as a result of
	 * the ITerminalInstance being disposed.
	 */
	onExit: Event<number>;

374
	processReady: Promise<void>;
D
Daniel Imms 已提交
375

D
jsdoc  
Daniel Imms 已提交
376 377 378 379 380 381
	/**
	 * The title of the terminal. This is either title or the process currently running or an
	 * explicit name given to the terminal instance through the extension API.
	 *
	 * @readonly
	 */
382 383
	title: string;

K
Kai Wood 已提交
384 385 386 387 388 389 390
	/**
	 * The focus state of the terminal before exiting.
	 *
	 * @readonly
	 */
	hadFocusOnExit: boolean;

A
Amy Qiu 已提交
391 392 393 394 395 396
	/**
	 * False when the title is set by an API or the user. We check this to make sure we
	 * do not override the title when the process title changes in the terminal.
	 */
	isTitleSetByProcess: boolean;

397 398 399
	/**
	 * The shell launch config used to launch the shell.
	 */
D
Daniel Imms 已提交
400
	readonly shellLaunchConfig: IShellLaunchConfig;
401

402 403 404 405 406 407 408
	/**
	 * Whether to disable layout for the terminal. This is useful when the size of the terminal is
	 * being manipulating (eg. adding a split pane) and we want the terminal to ignore particular
	 * resize events.
	 */
	disableLayout: boolean;

D
Daniel Imms 已提交
409 410 411 412 413 414
	/**
	 * An object that tracks when commands are run and enables navigating and selecting between
	 * them.
	 */
	readonly commandTracker: ITerminalCommandTracker;

415 416 417 418 419
	/**
	 * The cwd that the terminal instance was initialized with.
	 */
	readonly initialCwd: string;

D
jsdoc  
Daniel Imms 已提交
420 421
	/**
	 * Dispose the terminal instance, removing it from the panel/service and freeing up resources.
422
	 *
423 424 425 426
	 * @param immediate Whether the kill should be immediate or not. Immediate should only be used
	 * when VS Code is shutting down or in cases where the terminal dispose was user initiated.
	 * The immediate===false exists to cover an edge case where the final output of the terminal can
	 * get cut off. If immediate kill any terminal processes immediately.
D
jsdoc  
Daniel Imms 已提交
427
	 */
428
	dispose(immediate?: boolean): void;
D
jsdoc  
Daniel Imms 已提交
429

430 431 432 433 434 435 436
	/**
	 * Registers a link matcher, allowing custom link patterns to be matched and handled.
	 * @param regex The regular expression the search for, specifically this searches the
	 * textContent of the rows. You will want to use \s to match a space ' ' character for example.
	 * @param handler The callback when the link is called.
	 * @param matchIndex The index of the link from the regex.match(html) call. This defaults to 0
	 * (for regular expressions without capture groups).
437 438
	 * @param validationCallback A callback which can be used to validate the link after it has been
	 * added to the DOM.
439 440
	 * @return The ID of the new matcher, this can be used to deregister.
	 */
D
Daniel Imms 已提交
441
	registerLinkMatcher(regex: RegExp, handler: (url: string) => void, matchIndex?: number, validationCallback?: (uri: string, callback: (isValid: boolean) => void) => void): number;
442 443 444 445 446 447 448 449

	/**
	 * Deregisters a link matcher if it has been registered.
	 * @param matcherId The link matcher's ID (returned after register)
	 * @return Whether a link matcher was found and deregistered.
	 */
	deregisterLinkMatcher(matcherId: number): void;

450 451 452 453 454
	/**
	 * Check if anything is selected in terminal.
	 */
	hasSelection(): boolean;

D
jsdoc  
Daniel Imms 已提交
455 456 457
	/**
	 * Copies the terminal selection to the clipboard.
	 */
458
	copySelection(): void;
D
jsdoc  
Daniel Imms 已提交
459

460 461 462 463 464
	/**
	 * Current selection in the terminal.
	 */
	readonly selection: string | undefined;

465 466 467 468 469
	/**
	 * Clear current selection.
	 */
	clearSelection(): void;

470 471 472 473 474
	/**
	 * Select all text in the terminal.
	 */
	selectAll(): void;

R
rebornix 已提交
475 476 477
	/**
	 * Find the next instance of the term
	*/
478
	findNext(term: string, searchOptions: ISearchOptions): boolean;
R
rebornix 已提交
479 480 481 482

	/**
	 * Find the previous instance of the term
	 */
483
	findPrevious(term: string, searchOptions: ISearchOptions): boolean;
R
rebornix 已提交
484

485 486 487 488 489
	/**
	 * Notifies the terminal that the find widget's focus state has been changed.
	 */
	notifyFindWidgetFocusChanged(isFocused: boolean): void;

D
jsdoc  
Daniel Imms 已提交
490
	/**
491
	 * Focuses the terminal instance if it's able to (xterm.js instance exists).
D
jsdoc  
Daniel Imms 已提交
492 493 494
	 *
	 * @param focus Force focus even if there is a selection.
	 */
D
Daniel Imms 已提交
495
	focus(force?: boolean): void;
D
jsdoc  
Daniel Imms 已提交
496

497 498 499 500 501 502 503 504
	/**
	 * Focuses the terminal instance when it's ready (the xterm.js instance is created). Use this
	 * when the terminal is being shown.
	 *
	 * @param focus Force focus even if there is a selection.
	 */
	focusWhenReady(force?: boolean): Promise<void>;

D
jsdoc  
Daniel Imms 已提交
505 506 507
	/**
	 * Focuses and pastes the contents of the clipboard into the terminal instance.
	 */
508
	paste(): void;
D
jsdoc  
Daniel Imms 已提交
509 510 511 512 513 514 515 516 517 518

	/**
	 * Send text to the terminal instance. The text is written to the stdin of the underlying pty
	 * process (shell) of the terminal instance.
	 *
	 * @param text The text to send.
	 * @param addNewLine Whether to add a new line to the text being sent, this is normally
	 * required to run a command in the terminal. The character(s) added are \n or \r\n
	 * depending on the platform. This defaults to `true`.
	 */
519
	sendText(text: string, addNewLine: boolean): void;
D
jsdoc  
Daniel Imms 已提交
520

521 522 523 524 525 526 527 528 529
	/**
	 * Takes a path and returns the properly escaped path to send to the terminal.
	 * On Windows, this included trying to prepare the path for WSL if needed.
	 *
	 * @param path The path to be escaped and formatted.
	 * @returns An escaped version of the path to be execuded in the terminal.
	 */
	preparePathForTerminalAsync(path: string): Promise<string>;

530 531 532 533 534 535
	/**
	 * Write text directly to the terminal, skipping the process if it exists.
	 * @param text The text to write.
	 */
	write(text: string): void;

536 537 538 539
	/** Scroll the terminal buffer down 1 line. */
	scrollDownLine(): void;
	/** Scroll the terminal buffer down 1 page. */
	scrollDownPage(): void;
540 541
	/** Scroll the terminal buffer to the bottom. */
	scrollToBottom(): void;
542 543 544 545
	/** Scroll the terminal buffer up 1 line. */
	scrollUpLine(): void;
	/** Scroll the terminal buffer up 1 page. */
	scrollUpPage(): void;
546 547
	/** Scroll the terminal buffer to the top. */
	scrollToTop(): void;
D
Daniel Imms 已提交
548

D
Daniel Imms 已提交
549 550 551 552 553
	/**
	 * Clears the terminal buffer, leaving only the prompt line.
	 */
	clear(): void;

D
jsdoc  
Daniel Imms 已提交
554 555 556 557 558 559
	/**
	 * Attaches the terminal instance to an element on the DOM, before this is called the terminal
	 * instance process may run in the background but cannot be displayed on the UI.
	 *
	 * @param container The element to attach the terminal instance to.
	 */
D
Daniel Imms 已提交
560
	attachToElement(container: HTMLElement): void;
D
jsdoc  
Daniel Imms 已提交
561 562

	/**
563
	 * Updates the configuration of the terminal instance.
D
jsdoc  
Daniel Imms 已提交
564
	 */
565
	updateConfig(): void;
D
Daniel Imms 已提交
566

567 568 569 570 571 572
	/**
	 * Updates the accessibility support state of the terminal instance.
	 * @param isEnabled Whether it's enabled.
	 */
	updateAccessibilitySupport(isEnabled: boolean): void;

D
jsdoc  
Daniel Imms 已提交
573 574 575 576 577
	/**
	 * Configure the dimensions of the terminal instance.
	 *
	 * @param dimension The dimensions of the container.
	 */
578
	layout(dimension: { width: number, height: number }): void;
D
jsdoc  
Daniel Imms 已提交
579 580 581 582 583 584

	/**
	 * Sets whether the terminal instance's element is visible in the DOM.
	 *
	 * @param visible Whether the element is visible.
	 */
D
Daniel Imms 已提交
585
	setVisible(visible: boolean): void;
586

587 588 589 590 591
	/**
	 * Immediately kills the terminal's current pty process and launches a new one to replace it.
	 *
	 * @param shell The new launch configuration.
	 */
D
Daniel Imms 已提交
592
	reuseTerminal(shell: IShellLaunchConfig): void;
D
Daniel Imms 已提交
593

B
Ben Stein 已提交
594 595 596
	/**
	 * Sets the title of the terminal instance.
	 */
A
Amy Qiu 已提交
597
	setTitle(title: string, eventFromProcess: boolean): void;
598

599 600
	waitForTitle(): Promise<string>;

D
Daniel Imms 已提交
601 602
	setDimensions(dimensions: ITerminalDimensions): void;

603
	addDisposable(disposable: IDisposable): void;
604 605

	toggleEscapeSequenceLogging(): void;
606 607

	getCwd(): Promise<string>;
D
Daniel Imms 已提交
608
}
D
Daniel Imms 已提交
609 610

export interface ITerminalCommandTracker {
611 612
	scrollToPreviousCommand(): void;
	scrollToNextCommand(): void;
D
Daniel Imms 已提交
613 614
	selectToPreviousCommand(): void;
	selectToNextCommand(): void;
615 616
	selectToPreviousLine(): void;
	selectToNextLine(): void;
617
}
D
Daniel Imms 已提交
618 619

export interface ITerminalProcessManager extends IDisposable {
620
	readonly processState: ProcessState;
621
	readonly ptyProcessReady: Promise<void>;
D
Daniel Imms 已提交
622 623 624 625 626 627 628
	readonly shellProcessId: number;
	readonly initialCwd: string;

	readonly onProcessReady: Event<void>;
	readonly onProcessData: Event<string>;
	readonly onProcessTitle: Event<string>;
	readonly onProcessExit: Event<number>;
D
Daniel Imms 已提交
629

D
Daniel Imms 已提交
630
	addDisposable(disposable: IDisposable);
631
	dispose(immediate?: boolean);
D
Daniel Imms 已提交
632
	createProcess(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number);
D
Daniel Imms 已提交
633
	write(data: string): void;
D
Daniel Imms 已提交
634
	setDimensions(cols: number, rows: number): void;
635 636
}

637
export const enum ProcessState {
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
	// The process has not been initialized yet.
	UNINITIALIZED,
	// The process is currently launching, the process is marked as launching
	// for a short duration after being created and is helpful to indicate
	// whether the process died as a result of bad shell and args.
	LAUNCHING,
	// The process is running normally.
	RUNNING,
	// The process was killed during launch, likely as a result of bad shell and
	// args.
	KILLED_DURING_LAUNCH,
	// The process was killed by the user (the event originated from VS Code).
	KILLED_BY_USER,
	// The process was killed by itself, for example the shell crashed or `exit`
	// was run.
	KILLED_BY_PROCESS
}
655 656


657
export interface ITerminalProcessExtHostProxy extends IDisposable {
658 659
	readonly terminalId: number;

660 661 662
	emitData(data: string): void;
	emitTitle(title: string): void;
	emitPid(pid: number): void;
D
Daniel Imms 已提交
663
	emitExit(exitCode: number): void;
664

D
Daniel Imms 已提交
665 666
	onInput: Event<string>;
	onResize: Event<{ cols: number, rows: number }>;
667
	onShutdown: Event<boolean>;
668
}
669 670 671 672

export interface ITerminalProcessExtHostRequest {
	proxy: ITerminalProcessExtHostProxy;
	shellLaunchConfig: IShellLaunchConfig;
673
	activeWorkspaceRootUri: URI;
674 675 676
	cols: number;
	rows: number;
}