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

7
import Event from 'vs/base/common/event';
8
import platform = require('vs/base/common/platform');
9 10 11
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
D
Daniel Imms 已提交
12 13 14 15 16

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

export const TERMINAL_SERVICE_ID = 'terminalService';

17 18
export const TERMINAL_DEFAULT_SHELL_LINUX = !platform.isWindows ? (process.env.SHELL || 'sh') : 'sh';
export const TERMINAL_DEFAULT_SHELL_OSX = !platform.isWindows ? (process.env.SHELL || 'sh') : 'sh';
19

H
hun1ahpu 已提交
20 21
export const TERMINAL_DEFAULT_RIGHT_CLICK_COPY_PASTE = platform.isWindows;

22
/**  A context key that is set when the integrated terminal has focus. */
A
Alex Dima 已提交
23
export const KEYBINDING_CONTEXT_TERMINAL_FOCUS = new RawContextKey<boolean>('terminalFocus', undefined);
24
/**  A context key that is set when the integrated terminal does not have focus. */
J
Johannes Rieken 已提交
25
export const KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED: ContextKeyExpr = KEYBINDING_CONTEXT_TERMINAL_FOCUS.toNegated();
26

27 28 29 30 31
/** A keybinding context key that is set when the integrated terminal has text selected. */
export const KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED = new RawContextKey<boolean>('terminalTextSelected', undefined);
/** 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();

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

34
export interface ITerminalConfiguration {
35 36 37 38 39 40 41
	terminal: {
		integrated: {
			shell: {
				linux: string,
				osx: string,
				windows: string
			},
D
Daniel Imms 已提交
42 43
			shellArgs: {
				linux: string[],
44 45
				osx: string[],
				windows: string[]
D
Daniel Imms 已提交
46
			},
H
hun1ahpu 已提交
47
			rightClickCopyPaste: boolean,
48
			cursorBlinking: boolean,
49
			fontFamily: string,
50
			fontLigatures: boolean,
51
			fontSize: number,
52
			lineHeight: number,
53
			setLocaleVariables: boolean,
D
Daniel Imms 已提交
54
			scrollback: number,
55
			commandsToSkipShell: string[],
D
Daniel Imms 已提交
56
			cwd: string
57
		}
58 59 60
	};
}

61 62 63 64 65
export interface ITerminalConfigHelper {
	getTheme(baseThemeId: string): string[];
	getFont(): ITerminalFont;
	getFontLigaturesEnabled(): boolean;
	getCursorBlink(): boolean;
H
hun1ahpu 已提交
66
	getRightClickCopyPaste(): boolean;
67
	getCommandsToSkipShell(): string[];
D
Daniel Imms 已提交
68
	getScrollback(): number;
D
Daniel Imms 已提交
69
	getCwd(): string;
70 71 72 73 74 75 76 77 78 79
}

export interface ITerminalFont {
	fontFamily: string;
	fontSize: string;
	lineHeight: number;
	charWidth: number;
	charHeight: number;
}

80
export interface IShellLaunchConfig {
81 82 83 84 85 86 87 88 89 90 91
	/** The name of the terminal, this this is not set the name of the process will be used. */
	name?: string;
	/** The shell executable (bash, cmd, etc.). */
	executable?: string;
	/** The CLI arguments to use with executable. */
	args?: string[];
	/**
	 * The current working directory of the terminal, this overrides the `terminal.integrated.cwd`
	 * settings key.
	 */
	cwd?: string;
92 93 94 95 96
	/**
	 * A custom environment for the terminal, if this is not set the environment will be inherited
	 * from the VS Code process.
	 */
	env?: { [key: string]: string };
97 98 99 100 101 102
	/**
	 * 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;
	/** Whether to wait for a key press before closing the terminal. */
103
	waitOnExit?: boolean;
104 105
}

D
Daniel Imms 已提交
106
export interface ITerminalService {
107
	_serviceBrand: any;
108

D
Daniel Imms 已提交
109
	activeTerminalInstanceIndex: number;
110
	configHelper: ITerminalConfigHelper;
111
	onActiveInstanceChanged: Event<string>;
112
	onInstanceDisposed: Event<ITerminalInstance>;
113
	onInstanceProcessIdReady: Event<ITerminalInstance>;
114 115
	onInstancesChanged: Event<string>;
	onInstanceTitleChanged: Event<string>;
116 117
	terminalInstances: ITerminalInstance[];

118
	createInstance(shell?: IShellLaunchConfig): ITerminalInstance;
119
	getInstanceFromId(terminalId: number): ITerminalInstance;
D
Daniel Imms 已提交
120
	getInstanceLabels(): string[];
121 122 123 124 125 126 127
	getActiveInstance(): ITerminalInstance;
	setActiveInstance(terminalInstance: ITerminalInstance): void;
	setActiveInstanceByIndex(terminalIndex: number): void;
	setActiveInstanceToNext(): void;
	setActiveInstanceToPrevious(): void;

	showPanel(focus?: boolean): TPromise<void>;
D
Daniel Imms 已提交
128
	hidePanel(): void;
129
	setContainers(panelContainer: HTMLElement, terminalContainer: HTMLElement): void;
130
	updateConfig(): void;
D
Daniel Imms 已提交
131
}
D
Daniel Imms 已提交
132

133
export interface ITerminalInstance {
D
jsdoc  
Daniel Imms 已提交
134 135 136 137
	/**
	 * The ID of the terminal instance, this is an arbitrary number only used to identify the
	 * terminal instance.
	 */
138
	id: number;
D
jsdoc  
Daniel Imms 已提交
139

140 141 142 143 144
	/**
	 * The process ID of the shell process.
	 */
	processId: number;

D
jsdoc  
Daniel Imms 已提交
145 146 147
	/**
	 * An event that fires when the terminal instance's title changes.
	 */
D
Daniel Imms 已提交
148
	onTitleChanged: Event<string>;
D
jsdoc  
Daniel Imms 已提交
149 150 151 152 153 154 155

	/**
	 * 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
	 */
156 157
	title: string;

K
Kai Wood 已提交
158 159 160 161 162 163 164
	/**
	 * The focus state of the terminal before exiting.
	 *
	 * @readonly
	 */
	hadFocusOnExit: boolean;

D
jsdoc  
Daniel Imms 已提交
165 166 167
	/**
	 * Dispose the terminal instance, removing it from the panel/service and freeing up resources.
	 */
168
	dispose(): void;
D
jsdoc  
Daniel Imms 已提交
169

170 171 172 173 174
	/**
	 * Check if anything is selected in terminal.
	 */
	hasSelection(): boolean;

D
jsdoc  
Daniel Imms 已提交
175 176 177
	/**
	 * Copies the terminal selection to the clipboard.
	 */
178
	copySelection(): void;
D
jsdoc  
Daniel Imms 已提交
179

180 181 182 183 184
	/**
	 * Clear current selection.
	 */
	clearSelection(): void;

D
jsdoc  
Daniel Imms 已提交
185 186 187 188 189
	/**
	 * Focuses the terminal instance.
	 *
	 * @param focus Force focus even if there is a selection.
	 */
D
Daniel Imms 已提交
190
	focus(force?: boolean): void;
D
jsdoc  
Daniel Imms 已提交
191 192 193 194

	/**
	 * Focuses and pastes the contents of the clipboard into the terminal instance.
	 */
195
	paste(): void;
D
jsdoc  
Daniel Imms 已提交
196 197 198 199 200 201 202 203 204 205

	/**
	 * 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`.
	 */
206
	sendText(text: string, addNewLine: boolean): void;
D
jsdoc  
Daniel Imms 已提交
207

208 209 210 211
	/** Scroll the terminal buffer down 1 line. */
	scrollDownLine(): void;
	/** Scroll the terminal buffer down 1 page. */
	scrollDownPage(): void;
212 213
	/** Scroll the terminal buffer to the bottom. */
	scrollToBottom(): void;
214 215 216 217
	/** Scroll the terminal buffer up 1 line. */
	scrollUpLine(): void;
	/** Scroll the terminal buffer up 1 page. */
	scrollUpPage(): void;
218 219
	/** Scroll the terminal buffer to the top. */
	scrollToTop(): void;
D
Daniel Imms 已提交
220

D
Daniel Imms 已提交
221 222 223 224 225
	/**
	 * Clears the terminal buffer, leaving only the prompt line.
	 */
	clear(): void;

D
jsdoc  
Daniel Imms 已提交
226 227 228 229 230 231
	/**
	 * 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 已提交
232
	attachToElement(container: HTMLElement): void;
D
jsdoc  
Daniel Imms 已提交
233 234

	/**
235
	 * Updates the configuration of the terminal instance.
D
jsdoc  
Daniel Imms 已提交
236
	 */
237
	updateConfig(): void;
D
Daniel Imms 已提交
238

D
jsdoc  
Daniel Imms 已提交
239 240 241 242 243
	/**
	 * Configure the dimensions of the terminal instance.
	 *
	 * @param dimension The dimensions of the container.
	 */
244
	layout(dimension: { width: number, height: number }): void;
D
jsdoc  
Daniel Imms 已提交
245 246 247 248 249 250

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

	/**
	 * Attach a listener to the data stream from the terminal's pty process.
	 *
256 257
	 * @param listener The listener function which takes the processes' data stream (including
	 * ANSI escape sequences).
258 259
	 */
	onData(listener: (data: string) => void): void;
260 261 262 263 264 265 266 267

	/**
	 * Attach a listener that fires when the terminal's pty process exits.
	 *
	 * @param listener The listener function which takes the processes' exit code, an exit code of
	 * null means the process was killed as a result of the ITerminalInstance being disposed.
	 */
	onExit(listener: (exitCode: number) => void): void;
D
Daniel Imms 已提交
268
}